998
1004
#############################################################################
999
1005
#############################################################################
1008
#############################################################################
1009
#############################################################################
1010
## Test sub views: construct a sub view and check its consistency
1013
coarse_shape = [3,5,5,5]
1014
full_shape = [ 2*s-1 for s in coarse_shape ]
1015
X_full = [ np.linspace(0,1,s) for s in full_shape ]
1016
X_coarse = [ np.linspace(0,1,s) for s in coarse_shape ]
1019
rnd_p = npr.random(size=d)
1021
tmp = [ x * p for x,p in zip(X_full, rnd_p) ]
1022
Atest_full = reduce( np.add, np.ix_(*tmp) )
1023
Atest_coarse = Atest_full[::2,::2,::2,::2]
1028
return np.dot(rnd_p,X)
1030
def test(testn, title, idx, view):
1036
TW.set_active_view(view)
1038
if view == 'full': A = Atest_full
1039
elif view == 'coarse': A = Atest_coarse
1040
if np.any(A[idx] != out) or np.any(A[idx].shape != out.shape):
1041
print_fail(testn,title,msg='Different output - idx: ' + str(idx))
1043
elif feval != np.prod(np.unique(A[idx]).shape):
1044
print_fail(testn,title,msg='Wrong number of function evaluations - idx: ' + str(idx))
1047
print_ok(testn,title)
1050
TW = TT.TensorWrapper(f, X_full, None, dtype=Atest_full.dtype, marshal_f=False)
1051
TW.set_view( 'coarse', X_coarse )
1053
######################################################
1057
test( testn, "View - Single index full", idx, 'full' )
1059
######################################################
1060
# Single index coarse
1063
test( testn, "View - Single index coarse", idx, 'coarse' )
1065
######################################################
1068
idx = (1,slice(None,None,None),3,3)
1069
test( testn, "View - Single slice full", idx, 'full' )
1071
######################################################
1072
# Single slice coarse
1074
idx = (1,3,slice(None,None,None),3)
1075
test( testn, "View - Single slice coarse", idx, 'coarse' )
1077
######################################################
1078
# Partial slice full
1080
idx = (1,slice(1,3,1),3,3)
1081
test( testn, "View - Partial slice full", idx, 'full' )
1083
######################################################
1084
# Partial index coarse
1086
idx = (1,3,slice(0,2,1),3)
1087
test( testn, "View - Partial slice coarse", idx, 'coarse' )
1089
######################################################
1090
# Multiple slice full
1092
idx = (1,slice(1,3,1),slice(None,None,None),3)
1093
test( testn, "View - Multiple slice full", idx, 'full' )
1095
######################################################
1096
# Multiple slice coarse
1098
idx = (1,slice(None,None,None),slice(0,2,1),3)
1099
test( testn, "View - Multiple slice coarse", idx, 'coarse' )
1101
######################################################
1104
idx = tuple([slice(None,None,None)] * d)
1105
test( testn, "View - Full slice full", idx, 'full' )
1107
######################################################
1110
idx = tuple([slice(None,None,None)] * d)
1111
test( testn, "View - Full slice coarse", idx, 'coarse' )
1113
######################################################
1117
idx = tuple( [ [random.randint(0,full_shape[i]-1) for j in range(nn)] for i in range(d) ] )
1118
test( testn, "View - List full", idx, 'full' )
1120
######################################################
1124
idx = tuple( [ [random.randint(0,coarse_shape[i]-1) for j in range(nn)] for i in range(d) ] )
1125
test( testn, "View - List coarse", idx, 'coarse' )
1127
######################################################
1128
# Single list slice full
1131
idx = (1, [random.randint(0,full_shape[1]-1) for j in range(nn)], slice(None,None,None), 2)
1132
test( testn, "View - Single list slice full", idx, 'full' )
1134
######################################################
1135
# Single list slice coarse
1138
idx = (1, [random.randint(0,coarse_shape[1]-1) for j in range(nn)], slice(None,None,None), 2)
1139
test( testn, "View - Single list slice coarse", idx, 'coarse' )
1141
######################################################
1142
# Single list slice full
1145
idx = (1, slice(None,None,None), [random.randint(0,full_shape[2]-1) for j in range(nn)], 2)
1146
test( testn, "View - Single list slice full", idx, 'full' )
1148
######################################################
1149
# Single list slice coarse
1152
idx = (1, slice(None,None,None), [random.randint(0,coarse_shape[2]-1) for j in range(nn)], 2)
1153
test( testn, "View - Single list slice coarse", idx, 'coarse' )
1155
######################################################
1156
# Single list slice full
1159
idx = (1, slice(None,None,None), 2, [random.randint(0,full_shape[3]-1) for j in range(nn)])
1160
test( testn, "View - Single list slice full", idx, 'full' )
1162
######################################################
1163
# Single list slice coarse
1166
idx = (1, slice(None,None,None), 2, [random.randint(0,coarse_shape[3]-1) for j in range(nn)])
1167
test( testn, "View - Single list slice coarse", idx, 'coarse' )
1169
######################################################
1171
######################################################
1173
ext_full_shape = [ Q**(int(math.log(s,Q))+1) for s in full_shape ]
1174
ext_coarse_shape = [ Q**(int(math.log(s,Q))+1) for s in coarse_shape ]
1175
# Create folded tensors
1176
X_ext_full = [ np.hstack( (X_full[i], np.ones(ext_full_shape[i]-full_shape[i])*X_full[i][-1]) ) for i in range(d) ]
1177
X_ext_coarse = [ np.hstack( (X_coarse[i], np.ones(ext_coarse_shape[i]-coarse_shape[i])*X_coarse[i][-1]) ) for i in range(d) ]
1178
tmp_ext_full = [ x * p for x,p in zip(X_ext_full, rnd_p) ]
1179
Atest_ext_full = reduce( np.add, np.ix_(*tmp_ext_full) )
1180
tmp_ext_coarse = [ x * p for x,p in zip(X_ext_coarse, rnd_p) ]
1181
Atest_ext_coarse = reduce( np.add, np.ix_(*tmp_ext_coarse) )
1186
return np.dot(rnd_p,X)
1188
def test(testn, title, idx, view):
1194
TW.set_active_view(view)
1196
if view == 'full': A = Atest_ext_full
1197
elif view == 'coarse': A = Atest_ext_coarse
1198
if np.any(A[idx] != out) or np.any(A[idx].shape != out.shape):
1199
print_fail(testn,title,msg='Different output - idx: ' + str(idx))
1201
elif feval != np.prod(np.unique(A[idx]).shape):
1202
print_fail(testn,title,msg='Wrong number of function evaluations - idx: ' + str(idx))
1205
print_ok(testn,title)
1208
TW.set_active_view('coarse')
1210
TW.set_active_view('full')
1215
TW.set_active_view('full')
1218
###################################################################
1219
# 01: Single address access
1225
if Atest_ext_full[idx] != out:
1226
print_fail(testn,"Sub view and PowQ - Single address access - full",msg='Different output')
1229
print_fail(testn,"Sub view and PowQ - Single address access - full",msg='Wrong number of function evaluations')
1232
print_ok(testn,"Sub view and PowQ - Single address access - full")
1235
###################################################################
1239
store_location = "tw"
1240
TW.store_location = store_location
1242
TW.store(force=True)
1243
print_ok(testn, "Sub view and PowQ - Storage - full")
1247
TW = TT.load(store_location)
1249
idx = tuple( [slice(None,None,None)]*d )
1250
test(testn,"Sub view and PowQ - Reload - full",idx, 'full')
1251
os.remove(store_location + ".pkl")
1252
os.remove(store_location + ".h5")
1253
if os.path.isfile(store_location + ".pkl.old"):
1254
os.remove(store_location + ".pkl.old")
1255
if os.path.isfile(store_location + ".h5.old"):
1256
os.remove(store_location + ".h5.old")
1258
###################################################################
1262
idx = (1,slice(None,None,None),3,4)
1263
test(testn,"Sub view and PowQ - Single slice - full",idx, 'full')
1265
###################################################################
1269
idx = (1,2,slice(1,3,1),4)
1270
test(testn,"Sub view and PowQ - Partial slice - full",idx, 'full')
1272
###################################################################
1273
# Partial stepping slice
1276
idx = (1,2,slice(0,4,2),4)
1277
test(testn,"Sub view and PowQ - Partial stepping slice - full",idx, 'full')
1279
###################################################################
1283
idx = (1,slice(None,None,None),3,slice(0,4,2))
1284
test(testn,"Sub view and PowQ - Multiple slice - full",idx, 'full')
1286
###################################################################
1290
idx = tuple([slice(None,None,None)] * len(shape))
1291
test(testn,"Sub view and PowQ - Full slice - full",idx, 'full')
1293
###################################################################
1297
idx = ([0,1],[1,2],[1,3],[0,4])
1298
test(testn,"Sub view and PowQ - Lists - full",idx, 'full')
1300
###################################################################
1305
test(testn,"Sub view and PowQ - Single list - full",idx, 'full')
1307
###################################################################
1311
idx = (0,[0,2],[1,3],3)
1312
test(testn,"Sub view and PowQ - Double list - full",idx, 'full')
1314
###################################################################
1318
idx = (0,[0,2],slice(None,None,None),3)
1319
test(testn,"Sub view and PowQ - Single list slice - full",idx, 'full')
1322
idx = (0,slice(None,None,None),[0,2],3)
1323
test(testn,"Sub view and PowQ - Single list slice - full",idx, 'full')
1326
idx = (slice(None,None,None),0,[0,2,3],3)
1327
test(testn,"Sub view and PowQ - Single list slice - full",idx, 'full')
1329
###################################################################
1333
idx = ([0,1],slice(None,None,None),[0,2],3)
1334
test(testn,"Sub view and PowQ - Double list slice - full",idx, 'full')
1337
idx = (slice(None,None,None),0,slice(None,None,None),[0,2,3])
1338
test(testn,"Sub view and PowQ - Double slice list - full",idx, 'full')
1340
###################################################################
1344
idx = ([0,1],[0,2],slice(None,None,None),[1,3])
1345
test(testn,"Sub view and PowQ - Lists slice - full",idx, 'full')
1347
###################################################################
1353
Atmp = Atest_ext_full.copy()
1354
Atest_ext_full = Atest_ext_full[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1355
TW.fix_indices(fix_idxs, fix_dims)
1356
idx = [ slice(None,None,None) ] * TW.ndim
1357
test(testn, "Sub view and PowQ - Fix indices - full", idx, 'full')
1359
###################################################################
1363
Atest_ext_full = Atmp.copy()
1364
TW.release_indices()
1365
idx = [ slice(None,None,None) ] * TW.ndim
1366
test(testn, "Sub view and PowQ - Release indices - full",idx, 'full')
1368
###################################################################
1374
Atmp = Atest_ext_full.copy()
1375
Atest_ext_full = Atest_ext_full[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1376
TW.fix_indices(fix_idxs, fix_dims)
1377
idx = [ slice(None,None,None) ] + [(0,1)] * (TW.ndim-1)
1378
test(testn, "Sub view and PowQ - Fix indices - second test - full",idx, 'full')
1380
###################################################################
1384
Atest_ext_full = Atmp.copy()
1385
TW.release_indices()
1386
idx = [ slice(None,None,None) ] * TW.ndim
1387
test(testn, "Sub view and PowQ - Release indices - full",idx, 'full')
1392
TW.set_active_view('coarse')
1395
###################################################################
1396
# 01: Single address access
1402
if Atest_ext_coarse[idx] != out:
1403
print_fail(testn,"Sub view and PowQ - Single address access - coarse",msg='Different output')
1406
print_fail(testn,"Sub view and PowQ - Single address access - coarse",msg='Wrong number of function evaluations')
1409
print_ok(testn,"Sub view and PowQ - Single address access - coarse")
1412
###################################################################
1416
store_location = "tw"
1417
TW.store_location = store_location
1419
TW.store(force=True)
1420
print_ok(testn, "Sub view and PowQ - Storage - coarse")
1424
TW = TT.load(store_location)
1426
idx = tuple( [slice(None,None,None)]*d )
1427
test(testn,"Sub view and PowQ - Reload - coarse",idx, 'coarse')
1428
os.remove(store_location + ".pkl")
1429
os.remove(store_location + ".h5")
1430
if os.path.isfile(store_location + ".pkl.old"):
1431
os.remove(store_location + ".pkl.old")
1432
if os.path.isfile(store_location + ".h5.old"):
1433
os.remove(store_location + ".h5.old")
1435
###################################################################
1439
idx = (1,slice(None,None,None),3,4)
1440
test(testn,"Sub view and PowQ - Single slice - coarse",idx, 'coarse')
1442
###################################################################
1446
idx = (1,2,slice(1,3,1),4)
1447
test(testn,"Sub view and PowQ - Partial slice - coarse",idx, 'coarse')
1449
###################################################################
1450
# Partial stepping slice
1453
idx = (1,2,slice(0,4,2),4)
1454
test(testn,"Sub view and PowQ - Partial stepping slice - coarse",idx, 'coarse')
1456
###################################################################
1460
idx = (1,slice(None,None,None),3,slice(0,4,2))
1461
test(testn,"Sub view and PowQ - Multiple slice - coarse",idx, 'coarse')
1463
###################################################################
1467
idx = tuple([slice(None,None,None)] * len(shape))
1468
test(testn,"Sub view and PowQ - Coarse slice - coarse",idx, 'coarse')
1470
###################################################################
1474
idx = ([0,1],[1,2],[1,3],[0,4])
1475
test(testn,"Sub view and PowQ - Lists - coarse",idx, 'coarse')
1477
###################################################################
1482
test(testn,"Sub view and PowQ - Single list - coarse",idx, 'coarse')
1484
###################################################################
1488
idx = (0,[0,2],[1,3],3)
1489
test(testn,"Sub view and PowQ - Double list - coarse",idx, 'coarse')
1491
###################################################################
1495
idx = (0,[0,2],slice(None,None,None),3)
1496
test(testn,"Sub view and PowQ - Single list slice - coarse",idx, 'coarse')
1499
idx = (0,slice(None,None,None),[0,2],3)
1500
test(testn,"Sub view and PowQ - Single list slice - coarse",idx, 'coarse')
1503
idx = (slice(None,None,None),0,[0,2,3],3)
1504
test(testn,"Sub view and PowQ - Single list slice - coarse",idx, 'coarse')
1506
###################################################################
1510
idx = ([0,1],slice(None,None,None),[0,2],3)
1511
test(testn,"Sub view and PowQ - Double list slice - coarse",idx, 'coarse')
1514
idx = (slice(None,None,None),0,slice(None,None,None),[0,2,3])
1515
test(testn,"Sub view and PowQ - Double slice list - coarse",idx, 'coarse')
1517
###################################################################
1521
idx = ([0,1],[0,2],slice(None,None,None),[1,3])
1522
test(testn,"Sub view and PowQ - Lists slice - coarse",idx, 'coarse')
1524
###################################################################
1530
Atmp = Atest_ext_coarse.copy()
1531
Atest_ext_coarse = Atest_ext_coarse[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1532
TW.fix_indices(fix_idxs, fix_dims)
1533
idx = [ slice(None,None,None) ] * TW.ndim
1534
test(testn, "Sub view and PowQ - Fix indices - coarse", idx, 'coarse')
1536
###################################################################
1540
Atest_ext_coarse = Atmp.copy()
1541
TW.release_indices()
1542
idx = [ slice(None,None,None) ] * TW.ndim
1543
test(testn, "Sub view and PowQ - Release indices - coarse",idx, 'coarse')
1545
###################################################################
1551
Atmp = Atest_ext_coarse.copy()
1552
Atest_ext_coarse = Atest_ext_coarse[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1553
TW.fix_indices(fix_idxs, fix_dims)
1554
idx = [ slice(None,None,None) ] + [(0,1)] * (TW.ndim-1)
1555
test(testn, "Sub view and PowQ - Fix indices - second test - coarse",idx, 'coarse')
1557
###################################################################
1561
Atest_ext_coarse = Atmp.copy()
1562
TW.release_indices()
1563
idx = [ slice(None,None,None) ] * TW.ndim
1564
test(testn, "Sub view and PowQ - Release indices - coarse",idx, 'coarse')
1566
######################################################
1567
# Sub view and Reshaped PowQ
1568
######################################################
1570
newshape_full = [Q]*int(math.log(np.prod(ext_full_shape),Q))
1571
newshape_coarse = [Q]*int(math.log(np.prod(ext_coarse_shape),Q))
1572
Atest_ext_full_shape = Atest_ext_full.copy()
1573
Atest_ext_full = np.reshape( Atest_ext_full, newshape_full )
1574
TW.set_active_view('full')
1575
TW.reshape( newshape_full )
1576
Atest_ext_coarse_shape = Atest_ext_coarse.copy()
1577
Atest_ext_coarse = np.reshape( Atest_ext_coarse, newshape_coarse )
1578
TW.set_active_view('coarse')
1579
TW.reshape( newshape_coarse )
1583
TW.set_active_view('full')
1586
###################################################################
1587
# Reshaped PowQ - Single slice
1590
idx = (0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-2) ])
1591
test(testn,"Reshaped PowQ - Single slice - full",idx,'full')
1593
###################################################################
1594
# Reshaped PowQ - Partial slice
1597
idx = (0,slice(0,1,1)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-2) ])
1598
test(testn,"Reshaped PowQ - Partial slice - full",idx,'full')
1600
###################################################################
1601
# Reshaped PowQ - Multiple slice
1604
idx = (slice(0,1,1),0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-3) ])
1605
test(testn,"Reshaped PowQ - Multiple slice - full",idx,'full')
1607
###################################################################
1608
# Reshaped PowQ - Full slice
1611
idx = tuple([slice(None,None,None)] * len(Atest_ext_full.shape))
1612
test(testn,"Reshaped PowQ - Full slice - full",idx,'full')
1614
###################################################################
1615
# Reshaped PowQ - List
1619
idx = tuple( [ [random.randint(0,Q-1) for j in range(nn)] for i in range(len(newshape_full)) ] )
1620
test(testn,"Reshaped PowQ - Lists - full",idx,'full')
1622
###################################################################
1623
# Reshaped PowQ - Single list
1627
idx = (1,[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-2) ])
1628
test(testn,"Reshaped PowQ - Single list - full",idx,'full')
1630
###################################################################
1631
# Reshaped PowQ - Double list
1635
idx = (1,[random.randint(0,Q-1) for j in range(nn)],[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-3) ])
1636
test(testn,"Reshaped PowQ - Double list - full",idx,'full')
1638
###################################################################
1639
# Reshaped PowQ - Single list slice
1643
idx = (1,slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-3) ])
1644
test(testn,"Reshaped PowQ - Single list slice - full",idx,'full')
1648
idx = (1,[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-3) ])
1649
test(testn,"Reshaped PowQ - Single list slice - full",idx,'full')
1653
idx = (1,[random.randint(0,Q-1) for j in range(nn)],0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-4) ])
1654
test(testn,"Reshaped PowQ - Single list slice - full",idx,'full')
1656
###################################################################
1657
# Reshaped PowQ - Double list slice
1661
idx = (1,[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-4) ])
1662
test(testn,"Reshaped PowQ - Double list slice - full",idx,'full')
1666
idx = (slice(None,None,None),0,slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_full)-4) ])
1667
test(testn,"Reshaped PowQ - Double slice list - full",idx,'full')
1669
###################################################################
1670
# Reshaped PowQ - Lists slice
1674
idx = ([random.randint(0,Q-1) for j in range(nn)],[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None)) + tuple( [ [random.randint(0,Q-1) for j in range(nn)] for i in range(len(newshape_full)-3) ] )
1675
test(testn,"Reshaped PowQ - Lists slice - full",idx,'full')
1677
###################################################################
1678
# Reshaped PowQ - Fix indices
1683
Atmp = Atest_ext_full.copy()
1684
Atest_ext_full = Atest_ext_full[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1685
TW.fix_indices(fix_idxs, fix_dims)
1686
idx = [ slice(None,None,None) ] * TW.ndim
1687
test(testn, "Reshaped PowQ - Fix indices - full",idx,'full')
1689
###################################################################
1690
# Reshaped PowQ - Release indices
1693
Atest_ext_full = Atmp.copy()
1694
TW.release_indices()
1695
idx = [ slice(None,None,None) ] * TW.ndim
1696
test(testn, "Reshaped PowQ - Release indices - full",idx,'full')
1698
###################################################################
1699
# Reshaped PowQ - Fix indices 2
1704
Atmp = Atest_ext_full.copy()
1705
Atest_ext_full = Atest_ext_full[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1706
TW.fix_indices(fix_idxs, fix_dims)
1707
idx = [ slice(None,None,None) ] + [(0,1)] * (TW.ndim-1)
1708
test(testn, "Reshaped PowQ - Fix indices - second test - full",idx,'full')
1710
###################################################################
1711
# Reshaped PowQ - Release indices
1714
Atest_ext_full = Atmp.copy()
1715
TW.release_indices()
1716
idx = [ slice(None,None,None) ] * TW.ndim
1717
test(testn, "Reshaped PowQ - Release indices - full",idx,'full')
1719
###################################################################
1720
# Reshaped PowQ - Restore original shape
1723
Atest_ext_full = Atest_ext_full_shape.copy()
1724
TW.reset_ghost_shape()
1725
idx = [ slice(None,None,None) ] * TW.ndim
1726
test(testn, "Reshaped PowQ - Restore original shape - full",idx,'full')
1730
TW.set_active_view('coarse')
1733
###################################################################
1734
# Reshaped PowQ - Single slice
1737
idx = (0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-2) ])
1738
test(testn,"Reshaped PowQ - Single slice - coarse",idx,'coarse')
1740
###################################################################
1741
# Reshaped PowQ - Partial slice
1744
idx = (0,slice(0,1,1)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-2) ])
1745
test(testn,"Reshaped PowQ - Partial slice - coarse",idx,'coarse')
1747
###################################################################
1748
# Reshaped PowQ - Multiple slice
1751
idx = (slice(0,1,1),0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-3) ])
1752
test(testn,"Reshaped PowQ - Multiple slice - coarse",idx,'coarse')
1754
###################################################################
1755
# Reshaped PowQ - Coarse slice
1758
idx = tuple([slice(None,None,None)] * len(Atest_ext_coarse.shape))
1759
test(testn,"Reshaped PowQ - Coarse slice - coarse",idx,'coarse')
1761
###################################################################
1762
# Reshaped PowQ - List
1766
idx = tuple( [ [random.randint(0,Q-1) for j in range(nn)] for i in range(len(newshape_coarse)) ] )
1767
test(testn,"Reshaped PowQ - Lists - coarse",idx,'coarse')
1769
###################################################################
1770
# Reshaped PowQ - Single list
1774
idx = (1,[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-2) ])
1775
test(testn,"Reshaped PowQ - Single list - coarse",idx,'coarse')
1777
###################################################################
1778
# Reshaped PowQ - Double list
1782
idx = (1,[random.randint(0,Q-1) for j in range(nn)],[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-3) ])
1783
test(testn,"Reshaped PowQ - Double list - coarse",idx,'coarse')
1785
###################################################################
1786
# Reshaped PowQ - Single list slice
1790
idx = (1,slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-3) ])
1791
test(testn,"Reshaped PowQ - Single list slice - coarse",idx,'coarse')
1795
idx = (1,[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-3) ])
1796
test(testn,"Reshaped PowQ - Single list slice - coarse",idx,'coarse')
1800
idx = (1,[random.randint(0,Q-1) for j in range(nn)],0,slice(None,None,None)) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-4) ])
1801
test(testn,"Reshaped PowQ - Single list slice - coarse",idx,'coarse')
1803
###################################################################
1804
# Reshaped PowQ - Double list slice
1808
idx = (1,[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-4) ])
1809
test(testn,"Reshaped PowQ - Double list slice - coarse",idx,'coarse')
1813
idx = (slice(None,None,None),0,slice(None,None,None),[random.randint(0,Q-1) for j in range(nn)]) + tuple([ random.randint(0,Q-1) for i in range(len(newshape_coarse)-4) ])
1814
test(testn,"Reshaped PowQ - Double slice list - coarse",idx,'coarse')
1816
###################################################################
1817
# Reshaped PowQ - Lists slice
1821
idx = ([random.randint(0,Q-1) for j in range(nn)],[random.randint(0,Q-1) for j in range(nn)],slice(None,None,None)) + tuple( [ [random.randint(0,Q-1) for j in range(nn)] for i in range(len(newshape_coarse)-3) ] )
1822
test(testn,"Reshaped PowQ - Lists slice - coarse",idx,'coarse')
1824
###################################################################
1825
# Reshaped PowQ - Fix indices
1830
Atmp = Atest_ext_coarse.copy()
1831
Atest_ext_coarse = Atest_ext_coarse[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1832
TW.fix_indices(fix_idxs, fix_dims)
1833
idx = [ slice(None,None,None) ] * TW.ndim
1834
test(testn, "Reshaped PowQ - Fix indices - coarse",idx,'coarse')
1836
###################################################################
1837
# Reshaped PowQ - Release indices
1840
Atest_ext_coarse = Atmp.copy()
1841
TW.release_indices()
1842
idx = [ slice(None,None,None) ] * TW.ndim
1843
test(testn, "Reshaped PowQ - Release indices - coarse",idx,'coarse')
1845
###################################################################
1846
# Reshaped PowQ - Fix indices 2
1851
Atmp = Atest_ext_coarse.copy()
1852
Atest_ext_coarse = Atest_ext_coarse[ tuple([ fix_idxs[fix_dims.index(i)] if (i in fix_dims) else slice(None,None,None) for i in range(d) ]) ]
1853
TW.fix_indices(fix_idxs, fix_dims)
1854
idx = [ slice(None,None,None) ] + [(0,1)] * (TW.ndim-1)
1855
test(testn, "Reshaped PowQ - Fix indices - second test - coarse",idx,'coarse')
1857
###################################################################
1858
# Reshaped PowQ - Release indices
1861
Atest_ext_coarse = Atmp.copy()
1862
TW.release_indices()
1863
idx = [ slice(None,None,None) ] * TW.ndim
1864
test(testn, "Reshaped PowQ - Release indices - coarse",idx,'coarse')
1866
###################################################################
1867
# Reshaped PowQ - Restore original shape
1870
Atest_ext_coarse = Atest_ext_coarse_shape.copy()
1871
TW.reset_ghost_shape()
1872
idx = [ slice(None,None,None) ] * TW.ndim
1873
test(testn, "Reshaped PowQ - Restore original shape - coarse",idx,'coarse')
1876
#############################################################################
1877
#############################################################################
1001
1879
print_summary("TensorWrapper", nsucc, nfail)
1003
1881
return (nsucc,nfail)