Skip to content

First matmul implementation#366

Merged
FrancescAlted merged 15 commits intoBlosc:mainfrom
ricardosp4:matmul
Feb 26, 2025
Merged

First matmul implementation#366
FrancescAlted merged 15 commits intoBlosc:mainfrom
ricardosp4:matmul

Conversation

@ricardosp4
Copy link
Contributor

First implementation of matmul function along with its tests and the documentation. The tests should pass, as they pass locally (Windows).

Incidentally, I proposed a change in the squeeze method to better adapt to the array API.

Copy link
Member

@FrancescAlted FrancescAlted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! See my comments.

p1, q1 = x1.chunks[-2:]
q2 = x2.chunks[-1]

result = blosc2.zeros((n, m), dtype=x1.dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using x1.dtype as the outcome, it would be better to use out_dtype = np.result_type(x1, x2).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you should pass **kwargs to blosc2.zeros() for passing NDArray compression/storage details to the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception error was this one:
> E numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'

What if that line is receives these arguments:
result = blosc2.zeros((n, m), dtype=np.result_type(x1, x2), **kwargs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was suggesting exactly that :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add tests that combines operands with different dtypes. Also, add tests that set kwargs and check that they work (by checking e.g out.cparams.codec).

nb = b[:]
np_res = np.matmul(na, nb)

np.testing.assert_allclose(blosc2_res, np_res, rtol=1e-6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add a new test (say test_matmul_disk) where you pass filenames to operands and result via the urlpath keyword argument. See for example: https://github.com/Blosc/python-blosc2/blob/main/tests/ndarray/test_ndarray.py#L74

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added the test_matmul_disk as you suggested, passing the filenames through the urlpath argument. It's ready for review in commit 5e27651.

Copy link
Member

@FrancescAlted FrancescAlted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@FrancescAlted FrancescAlted merged commit 54609b8 into Blosc:main Feb 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants