Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mlir][sparse][taco] Use np.array_equal to compare integer values.
Fix MLIR-PyTACO and some tests to use np.array_equal to compare integer
values.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120526
  • Loading branch information
bixia1 committed Feb 25, 2022
1 parent 166968a commit c601dfb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Expand Up @@ -28,7 +28,7 @@
D[i, j] = A[i, j] + B[i, j] - C[i, j]

indices, values = D.get_coordinates_and_values()
passed = np.allclose(indices, [[0, 0], [0, 1], [1, 2]])
passed = np.array_equal(indices, [[0, 0], [0, 1], [1, 2]])
passed += np.allclose(values, [20.0, 5.0, 63.0])

# CHECK: Number of passed: 2
Expand Down
Expand Up @@ -692,7 +692,7 @@ def unpack(self) -> None:
rank, nse, shape, values, indices = utils.sparse_tensor_to_coo_tensor(
self._packed_sparse_value, self._dtype.value)
assert rank == self.order
assert np.allclose(self.shape, shape)
assert np.array_equal(self.shape, shape)
assert nse == len(values)
self._coords = indices
self._values = values
Expand Down
Expand Up @@ -49,7 +49,7 @@ def test_read_mtx_matrix_general():
a.unpack()
passed += (a.is_unpacked())
coords, values = a.get_coordinates_and_values()
passed += np.allclose(coords, [[0, 1], [2, 0], [2, 1]])
passed += np.array_equal(coords, [[0, 1], [2, 0], [2, 1]])
passed += np.allclose(values, [2.0, 3.0, 4.0])
# CHECK: 4
print(passed)
Expand All @@ -71,8 +71,8 @@ def test_read_mtx_matrix_symmetry():
coords, values = a.get_coordinates_and_values()
print(coords)
print(values)
passed += np.allclose(coords,
[[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]])
passed += np.array_equal(coords,
[[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]])
passed += np.allclose(values, [2.0, 3.0, 2.0, 4.0, 3.0, 4.0])
# CHECK: 4
print(passed)
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_read_tns():
a.unpack()
passed += (a.is_unpacked())
coords, values = a.get_coordinates_and_values()
passed += np.allclose(coords, [[0, 1], [2, 0], [2, 1]])
passed += np.array_equal(coords, [[0, 1], [2, 0], [2, 1]])
passed += np.allclose(values, [2.0, 3.0, 4.0])
# CHECK: 4
print(passed)
Expand Down
Expand Up @@ -80,15 +80,15 @@ def _implement_read_tns_test(
passed = 0

# Verify the output shape for the tensor.
if np.allclose(o_shape, t.shape):
if np.array_equal(o_shape, t.shape):
passed += 1

# Use the output MLIR sparse tensor pointer to retrieve the COO-flavored
# values and verify the values.
o_rank, o_nse, o_shape, o_values, o_indices = (
pytaco_utils.sparse_tensor_to_coo_tensor(sparse_tensor, np.float64))
if o_rank == t.rank and o_nse == t.nse and np.allclose(
o_shape, t.shape) and np.allclose(o_values, t.values) and np.allclose(
if o_rank == t.rank and o_nse == t.nse and np.array_equal(
o_shape, t.shape) and np.allclose(o_values, t.values) and np.array_equal(
o_indices, t.indices):
passed += 1

Expand Down

0 comments on commit c601dfb

Please sign in to comment.