Skip to content

Commit

Permalink
fix: fix 0 sparse array (#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Aug 2, 2021
1 parent 27d93c2 commit 671a310
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jina/types/ndarray/dense/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def value(self) -> 'np.ndarray':
x = x.astype(blob.original_dtype) * blob.scale + blob.min_val

return x.reshape(blob.shape)
elif len(blob.shape) > 0:
return np.zeros(blob.shape)

@value.setter
def value(self, value: 'np.ndarray'):
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/types/document/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,3 +1094,11 @@ def test_tags_update_nested_lists():
assert d.tags['hey']['list'][1] is True
assert d.tags['hey']['list'][2]['inlist'] == 'not here'
assert d.tags['hoy'][0] == 1


def test_empty_sparse_array():
matrix = csr_matrix([[0, 0, 0, 0, 0]])
doc = Document()
doc.embedding = matrix
assert isinstance(doc.embedding, coo_matrix)
assert (doc.embedding != matrix).nnz == 0

0 comments on commit 671a310

Please sign in to comment.