Skip to content

Commit d65892d

Browse files
authored
fix valgrind errors in unit tests (#3935)
1 parent 4746ae3 commit d65892d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

apis/python/tests/ht/_ht_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def arrow_array_fast(
447447
def gen_unique_floats(
448448
rng: np.random.Generator, lo: float, hi: float, n: int
449449
) -> npt.NDArray[np.float64]:
450-
out = np.empty(n)
450+
out = np.zeros(n)
451451
needed = n
452452
while needed != 0:
453453
arr = rng.uniform(lo, hi, needed)

apis/python/tests/test_libfastercsx.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def test_construction(
7474
# only occurs if we mess up the test params
7575
pytest.skip(reason="NNZ is too large for index type.")
7676

77-
indptr = np.empty((sp.shape[0] + 1), dtype=csr_major_index_dtype)
78-
indices = np.empty((sp.nnz,), dtype=csr_minor_index_dtype)
79-
data = np.empty((sp.nnz,), dtype=sp.dtype)
77+
indptr = np.zeros((sp.shape[0] + 1), dtype=csr_major_index_dtype)
78+
indices = np.zeros((sp.nnz,), dtype=csr_minor_index_dtype)
79+
data = np.zeros((sp.nnz,), dtype=sp.dtype)
8080

8181
fastercsx.compress_coo(
8282
context,
@@ -133,9 +133,9 @@ def test_partitioning(
133133
random_state=rng,
134134
)
135135

136-
indptr = np.empty((sp.shape[0] + 1), dtype=np.int32)
137-
indices = np.empty((sp.nnz,), dtype=np.int32)
138-
data = np.empty((sp.nnz,), dtype=sp.dtype)
136+
indptr = np.zeros((sp.shape[0] + 1), dtype=np.int32)
137+
indices = np.zeros((sp.nnz,), dtype=np.int32)
138+
data = np.zeros((sp.nnz,), dtype=sp.dtype)
139139

140140
fastercsx.compress_coo(
141141
context,
@@ -183,9 +183,9 @@ def test_multichunk(
183183
col_chunks = tuple(np.array_split(sp.col, nchunks))
184184
data_chunks = tuple(np.array_split(sp.data, nchunks))
185185

186-
indptr = np.empty((sp.shape[0] + 1), dtype=np.int32)
187-
indices = np.empty((sp.nnz,), dtype=np.int32)
188-
data = np.empty((sp.nnz,), dtype=sp.dtype)
186+
indptr = np.zeros((sp.shape[0] + 1), dtype=np.int32)
187+
indices = np.zeros((sp.nnz,), dtype=np.int32)
188+
data = np.zeros((sp.nnz,), dtype=sp.dtype)
189189

190190
fastercsx.compress_coo(
191191
context,
@@ -262,9 +262,9 @@ def test_compress_coo_bad_args(
262262
sp = sparse.random(2830, 212, density=0.1, dtype=np.int8, random_state=rng)
263263
i, j, d = sp.row, sp.col, sp.data
264264

265-
indptr = np.empty((sp.shape[0] + 1), dtype=np.int32)
266-
indices = np.empty((sp.nnz,), dtype=np.int32)
267-
data = np.empty((sp.nnz,), dtype=sp.dtype)
265+
indptr = np.zeros((sp.shape[0] + 1), dtype=np.int32)
266+
indices = np.zeros((sp.nnz,), dtype=np.int32)
267+
data = np.zeros((sp.nnz,), dtype=sp.dtype)
268268

269269
with pytest.raises(TypeError):
270270
fastercsx.compress_coo(None, sp.shape, (i,), (j,), (d,), indptr, indices, data)
@@ -399,9 +399,9 @@ def test_ragged_chunk_error(
399399
# is enforced.
400400
nnz = 3
401401
shape = (100, 20)
402-
indptr = np.empty(shape[0] + 1, dtype=np.int32)
403-
indices = np.empty(nnz, dtype=np.int32)
404-
data = np.empty(nnz, dtype=np.int8)
402+
indptr = np.zeros(shape[0] + 1, dtype=np.int32)
403+
indices = np.zeros(nnz, dtype=np.int32)
404+
data = np.zeros(nnz, dtype=np.int8)
405405
with pytest.raises(ValueError):
406406
fastercsx.compress_coo(
407407
context,
@@ -432,8 +432,8 @@ def test_empty_first_frag(rng: np.random.Generator, context: clib.SOMAContext) -
432432
d := np.array([85, 63, 51, 26, 30, 4, 7, 1, 17, 81], dtype=np.int8),
433433
),
434434
indptr := np.zeros(57, dtype=np.int32),
435-
indices := np.empty((10,), dtype=np.int32),
436-
data := np.empty((10,), dtype=np.int8),
435+
indices := np.zeros((10,), dtype=np.int32),
436+
data := np.zeros((10,), dtype=np.int8),
437437
)
438438

439439
csr = sparse.csr_matrix((d, (i, j)), shape=shape)

0 commit comments

Comments
 (0)