MCPcopy Create free account
hub / github.com/apache/singa / einsum

Function einsum

python/singa/tensor.py:1335–1469  ·  view source on GitHub ↗

function TODO list to finish the function in cpp(just like numpy function): 1.sum(A,axis = None) 2.repeat(A,repeats) 3.transpose(A,axes = None) Do the matrix to matrix einsum calculation according to the operands Warning : this function could only support two matrix' einsum calc

(ops, *args)

Source from the content-addressed store, hash-verified

1333
1334
1335def einsum(ops, *args):
1336 ''' function TODO list to finish the function in cpp(just like numpy function):
1337 1.sum(A,axis = None)
1338 2.repeat(A,repeats)
1339 3.transpose(A,axes = None)
1340 Do the matrix to matrix einsum calculation according to the operands
1341 Warning : this function could only support two matrix' einsum calcultion
1342
1343 Args:
1344 ops(string): the string specifies the subscripts for summation such as
1345 'ki,kj->kij' Here all the 26 lowercase letter can be used here.
1346 args(list of array_like): These are the tensors for the operation,
1347 but here only support two tensors.
1348
1349 Returns:
1350 Singa.Tensor the output matirx of the einsum calculation
1351
1352 The best way to understand this function is to try the examples below:
1353 A_ = [0,1,2,3,4,5,6,7,8,9,10,11]
1354 A = A_.reshape(4,3)
1355 B = A_.reshape(3,4)
1356
1357 Here this einsum calculation is the same as normal 'mult'
1358 Res = einsum('ij,jk->ik',A,B)
1359
1360 >>> [[ 20 23 26 29]
1361 [ 56 68 80 92]
1362 [ 92 113 134 155]
1363 [128 158 188 218]]
1364
1365 A_ = [0,1,2,3,4,5,6,7,8,9,10,11]
1366 A = A_.reshape(4,3)
1367 B = A_.reshape(4,3)
1368
1369 Here the einsum calculation is the same as normol 'eltwise_mult'
1370 Res = einsum('ki,ki->ki',A,B)
1371
1372 >>> [[ 0 1 4]
1373 [ 9 16 25]
1374 [ 36 49 64]
1375 [ 81 100 121]]
1376
1377 A = [0,1,2,3,4,5,6,7,8,9,10,11]
1378 A = A.reshape(4,3)
1379
1380 Res = einsum('ki,kj->kij',A,A)
1381 >>> [[[ 0 0 0]
1382 [ 0 1 2]
1383 [ 0 2 4]]
1384 [[ 9 12 15]
1385 [ 12 16 20]
1386 [ 15 20 25]]
1387 [[ 36 42 48]
1388 [ 42 49 56]
1389 [ 48 56 64]]
1390 [[ 81 90 99]
1391 [ 90 100 110]
1392 [ 99 110 121]]]

Callers

nothing calls this directly

Calls 8

indexMethod · 0.80
repeatFunction · 0.70
productFunction · 0.70
transposeFunction · 0.70
eltwise_multFunction · 0.70
sumFunction · 0.70
ndimMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected