@@ -1422,28 +1422,28 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
1422
1422
int n_args, bool check_for_bounds, bool is_unbounded_pointer_to_data) {
1423
1423
std::string prod = " 1" ;
1424
1424
std::string idx = " 0" ;
1425
- std::reverse (m_args.begin (), m_args.end ());
1426
- std::reverse (diminfo.begin (), diminfo.end ());
1427
- if (!is_unbounded_pointer_to_data) {
1428
- for (int i = 0 ; i < (int )diminfo.size () - 1 ; i += 2 ) {
1429
- std::swap (diminfo[i], diminfo[i + 1 ]);
1425
+ if (is_unbounded_pointer_to_data) {
1426
+ for (int r = 0 ; r < n_args; r++) {
1427
+ std::string curr_llvm_idx = m_args[r];
1428
+ std::string lval = diminfo[r];
1429
+ curr_llvm_idx = " (" + curr_llvm_idx + " - " + lval + " )" ;
1430
+ if ( check_for_bounds ) {
1431
+ // check_single_element(curr_llvm_idx, arr); TODO: To be implemented
1432
+ }
1433
+ idx = " (" + idx + " + " + " (" + curr_llvm_idx + " )" + " )" ;
1430
1434
}
1435
+ return idx;
1431
1436
}
1432
- for ( int r = 0 , r1 = 0 ; r < n_args ; r++ ) {
1437
+ for ( int r = n_args - 1 , r1 = 2 * n_args - 1 ; r >= 0 ; r--, r1 -= 2 ) {
1433
1438
std::string curr_llvm_idx = m_args[r];
1434
- std::string lval = diminfo[r1];
1439
+ std::string lval = diminfo[r1 - 1 ];
1435
1440
curr_llvm_idx = " (" + curr_llvm_idx + " - " + lval + " )" ;
1436
1441
if ( check_for_bounds ) {
1437
1442
// check_single_element(curr_llvm_idx, arr); TODO: To be implemented
1438
1443
}
1439
1444
idx = " (" + idx + " + " + " (" + prod + " * " + curr_llvm_idx + " )" + " )" ;
1440
- if (is_unbounded_pointer_to_data) {
1441
- r1 += 1 ;
1442
- } else {
1443
- std::string dim_size = diminfo[r1 + 1 ];
1444
- r1 += 2 ;
1445
- prod = " (" + prod + " * " + dim_size + " )" ;
1446
- }
1445
+ std::string dim_size = diminfo[r1];
1446
+ prod = " (" + prod + " * " + dim_size + " )" ;
1447
1447
}
1448
1448
return idx;
1449
1449
}
@@ -1496,24 +1496,22 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
1496
1496
update_target_desc += indent + target_desc + " ->offset = 0;\n " ; // offset not available yet
1497
1497
1498
1498
std::string target_dim_des_array = target_desc + " ->dims" ;
1499
- int j = 0 ;
1500
- for ( int i = 0 ; i < value_rank; i++ ) {
1501
- std::string stride = " 1" ;
1502
- for (int r = (i * 2 ) + 1 ; r < (int )diminfo.size (); r += 2 ) {
1503
- stride = " (" + stride + " *" + diminfo[r] + " )" ;
1504
- }
1499
+ int j = target_rank - 1 ;
1500
+ int r = (int )diminfo.size () - 1 ;
1501
+ std::string stride = " 1" ;
1502
+ for ( int i = value_rank - 1 ; i >= 0 ; i-- ) {
1505
1503
if ( ds[i] != " " ) {
1506
1504
std::string dim_length = " (((" + ubs[i] + " - " + lbs[i] + " )" + " /" + ds[i] + " ) + 1)" ;
1507
1505
std::string target_dim_des = target_dim_des_array + " [" + std::to_string (j) + " ]" ;
1508
1506
update_target_desc += indent + target_dim_des + " .stride = " + stride + " ;\n " ;
1509
1507
update_target_desc += indent + target_dim_des + " .lower_bound = 1;\n " ;
1510
1508
update_target_desc += indent + target_dim_des + " .length = " + dim_length + " ;\n " ;
1511
- j++ ;
1509
+ j-- ;
1512
1510
}
1513
- // stride = "(" + stride + "*" + diminfo[r] + ")";
1514
- // r + = 2;
1511
+ stride = " (" + stride + " *" + diminfo[r] + " )" ;
1512
+ r - = 2 ;
1515
1513
}
1516
- LCOMPILERS_ASSERT (j == target_rank );
1514
+ LCOMPILERS_ASSERT (j == - 1 );
1517
1515
update_target_desc += indent + target_desc + " ->n_dims = " + std::to_string (target_rank) + " ;\n " ;
1518
1516
src = update_target_desc;
1519
1517
}
0 commit comments