|
5 | 5 | #
|
6 | 6 | # see http://frostt.io/tensors/file-formats.html
|
7 | 7 | #
|
8 |
| -# This matrix represents the "B" input to the MTTKRP kernel: |
| 8 | +# This tensor represents the "B" input to the MTTKRP kernel: |
9 | 9 | # http://tensor-compiler.org/docs/data_analytics/index.html
|
10 |
| -# |
11 |
| -# It can be generated with the following script, adapted from the above link: |
12 |
| -# |
13 |
| -#> import pytaco as pt |
14 |
| -#> import numpy as np |
15 |
| -#> from pytaco import compressed, dense |
16 |
| -#> import random |
17 |
| -#> |
18 |
| -#> # Define formats for storing the sparse tensor and dense matrices. |
19 |
| -#> csf = pt.format([compressed, compressed, compressed]) |
20 |
| -#> rm = pt.format([dense, dense]) |
21 |
| -# |
22 |
| -#> B=pt.tensor((2,3,4),csf) |
23 |
| -#> density = 0.25 |
24 |
| -#> for i in range(2): |
25 |
| -#> for j in range(3): |
26 |
| -#> for k in range(4): |
27 |
| -#> if random.random() > density: |
28 |
| -#> B.insert((i,j,k), random.randint(0,100)) |
29 |
| -#> |
30 |
| -#> C = pt.from_array(np.arange(B.shape[1]*5).reshape(B.shape[1],5)) |
31 |
| -#> D = pt.from_array(np.arange(B.shape[2]*5).reshape(B.shape[2],5)) |
32 |
| -#> |
33 |
| -#> # Declare the result to be a dense matrix. |
34 |
| -#> A = pt.tensor([B.shape[0], 5], rm) |
35 |
| -#> |
36 |
| -#> # Declare index vars. |
37 |
| -#> i, j, k, l = pt.get_index_vars(4) |
38 |
| -#> |
39 |
| -#> # Define the MTTKRP computation. |
40 |
| -#> A[i, j] = B[i, k, l] * D[l, j] * C[k, j] |
41 |
| -#> |
42 |
| -#> # Perform the MTTKRP computation and write the result to file. |
43 |
| -#> pt.write("A.tns", A) |
44 |
| -#> pt.write("B.tns", B) |
45 |
| -# |
46 | 10 | 3 17
|
47 | 11 | 2 3 4
|
48 | 12 | 1 1 3 3
|
|
0 commit comments