Skip to content

Commit 9b9a084

Browse files
committed
[mlir][sparse][pytaco] test with 3-dim tensor and scalar
Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D120163
1 parent c12d49c commit 9b9a084

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# RUN: SUPPORTLIB=%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext %PYTHON %s | FileCheck %s
2+
3+
import filecmp
4+
import numpy as np
5+
import os
6+
import sys
7+
import tempfile
8+
9+
_SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
10+
sys.path.append(_SCRIPT_PATH)
11+
12+
from tools import mlir_pytaco_api as pt
13+
from tools import testing_utils as utils
14+
15+
i, j, k = pt.get_index_vars(3)
16+
17+
# Set up scalar and sparse tensors.
18+
alpha = pt.tensor(42.0)
19+
S = pt.tensor([8, 8, 8],
20+
pt.format([pt.compressed, pt.compressed, pt.compressed]))
21+
X = pt.tensor([8, 8, 8],
22+
pt.format([pt.compressed, pt.compressed, pt.compressed]))
23+
S.insert([0, 0, 0], 2.0)
24+
S.insert([1, 1, 1], 3.0)
25+
S.insert([4, 4, 4], 4.0)
26+
S.insert([7, 7, 7], 5.0)
27+
28+
# TODO: make this work:
29+
# X[i, j, k] = alpha[0] * S[i, j, k]
30+
X[i, j, k] = S[i, j, k]
31+
32+
expected = """; extended FROSTT format
33+
3 4
34+
8 8 8
35+
1 1 1 2
36+
2 2 2 3
37+
5 5 5 4
38+
8 8 8 5
39+
"""
40+
41+
# Force evaluation of the kernel by writing out X.
42+
with tempfile.TemporaryDirectory() as test_dir:
43+
x_file = os.path.join(test_dir, 'X.tns')
44+
pt.write(x_file, X)
45+
#
46+
# CHECK: Compare result True
47+
#
48+
x_data = utils.file_as_string(x_file)
49+
print(f'Compare result {x_data == expected}')

0 commit comments

Comments
 (0)