Skip to content

Commit 5778167

Browse files
FrancescAltedricardosp4
authored andcommitted
Add new measurements
1 parent 428355a commit 5778167

6 files changed

Lines changed: 203 additions & 11 deletions

File tree

bench/ndarray/jit-reduc-float64-plot-semilogx.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@
3939
create_BLOSCLZ_l7_disk = [ 0.0701, 0.2656, 1.0553, 4.0486, 9.2255, 12.2674, 16.4618, 20.1527, 25.3657, 33.7537, 37.3551, 43.0586, 48.4968, 53.9183, 62.9415, 71.7656, 80.5597, 85.5704, 97.0770, 109.7463, 119.2675 ]
4040
compute_BLOSCLZ_l7_disk = [ 0.0019, 0.0213, 0.0788, 0.3002, 0.7252, 0.9276, 1.2053, 1.4999, 1.9109, 3.4081, 2.8205, 3.3593, 3.6086, 4.2295, 4.9548, 5.6996, 6.0085, 7.0802, 7.4786, 8.4466, 9.4861 ]
4141

42-
create_LZ4_l1 = [ 0.0304, 0.2582, 1.0298, 3.9502, 8.8945, 11.9267, 16.3965, 20.2368, 24.6837, 29.3425, 36.2631, 42.1709, 48.0605, 52.3962, 61.5175, 68.6328, 80.1160, 85.4322, 97.1122, 106.9973, 114.8584, 219.8679, 372.3182, 650.2087, 876.6964, 1535.3019, 1717.6310 ]
43-
compute_LZ4_l1 = [ 0.0018, 0.0210, 0.0756, 0.3003, 0.6609, 0.8886, 1.1285, 1.4453, 1.7959, 2.1889, 2.6978, 3.1586, 3.4286, 3.9929, 4.4590, 5.3601, 5.6702, 6.4690, 6.9764, 7.8714, 8.6404, 15.7214, 29.4130, 46.5909, 87.1930, 164.6234, 258.9626 ]
42+
create_LZ4_l1 = [ 0.0304, 0.2582, 1.0298, 3.9502, 8.8945, 11.9267, 16.3965, 20.2368, 24.6837, 29.3425, 36.2631, 42.1709, 48.0605, 52.3962, 61.5175, 68.6328, 80.1160, 85.4322, 97.1122, 106.9973, 114.8584, 219.8679, 372.3182, 650.2087, 876.6964, 1535.3019, 1717.6310, 2605.6513, 3490.7571, 4253.5521, 4192.6208, 6181.3742, 6793.9787 ]
43+
compute_LZ4_l1 = [ 0.0018, 0.0210, 0.0756, 0.3003, 0.6609, 0.8886, 1.1285, 1.4453, 1.7959, 2.1889, 2.6978, 3.1586, 3.4286, 3.9929, 4.4590, 5.3601, 5.6702, 6.4690, 6.9764, 7.8714, 8.6404, 15.7214, 29.4130, 46.5909, 87.1930, 164.6234, 258.9626, 256.4864, 378.0102, 476.1793, 585.9910, 734.2687, 853.7598 ]
4444

45-
create_LZ4_l1_disk = [ 1.7980, 0.2617, 1.0480, 4.0809, 9.0720, 13.8294, 16.7269, 20.5108, 24.9465, 30.0428, 37.1903, 42.8075, 48.7775, 52.9890, 63.4071, 70.1766, 81.9747, 88.1830, 97.7921, 111.0611, 119.7673, 214.8363, 370.7900, 600.6060, 872.7770, 1314.0561, 1581.3989 ]
46-
compute_LZ4_l1_disk = [ 0.0019, 0.0214, 0.0795, 0.3060, 0.6985, 0.9195, 1.1766, 1.5213, 1.8845, 2.2972, 2.8044, 3.2587, 3.5898, 4.1524, 4.6293, 5.5485, 5.8715, 6.7386, 7.3019, 8.2307, 9.0145, 16.1475, 30.1677, 59.1110, 81.9494, 112.0279, 169.0670 ]
45+
create_LZ4_l1_disk = [ 1.7980, 0.2617, 1.0480, 4.0809, 9.0720, 13.8294, 16.7269, 20.5108, 24.9465, 30.0428, 37.1903, 42.8075, 48.7775, 52.9890, 63.4071, 70.1766, 81.9747, 88.1830, 97.7921, 111.0611, 119.7673, 214.8363, 370.7900, 600.6060, 872.7770, 1314.0561, 1581.3989, 1898.3007, 2910.3205, 3476.1479, 4753.6958, 5590.7596, 6627.1739 ]
46+
compute_LZ4_l1_disk = [ 0.0019, 0.0214, 0.0795, 0.3060, 0.6985, 0.9195, 1.1766, 1.5213, 1.8845, 2.2972, 2.8044, 3.2587, 3.5898, 4.1524, 4.6293, 5.5485, 5.8715, 6.7386, 7.3019, 8.2307, 9.0145, 16.1475, 30.1677, 59.1110, 81.9494, 112.0279, 169.0670, 173.9750, 248.5645, 332.5040, 354.8242, 448.8191, 493.8022 ]
4747

48-
create_ZSTD_l1 = [ 0.0302, 0.2704, 1.0703, 4.1243, 9.2185, 12.5026, 17.0585, 20.8708, 25.5844, 31.0571, 37.7114, 42.8297, 50.2696, 54.5773, 63.6311, 73.0370, 84.0092, 89.0686, 100.3300, 108.8173, 119.1154 ]
49-
compute_ZSTD_l1 = [ 0.0021, 0.0296, 0.1045, 0.3979, 0.8787, 1.3064, 1.7404, 2.1938, 2.6780, 3.3929, 3.8601, 4.3665, 5.0127, 5.7346, 6.1056, 7.9448, 8.2872, 9.4659, 9.2376, 10.4273, 11.6572 ]
48+
create_ZSTD_l1 = [ 0.0302, 0.2704, 1.0703, 4.1243, 9.2185, 12.5026, 17.0585, 20.8708, 25.5844, 31.0571, 37.7114, 42.8297, 50.2696, 54.5773, 63.6311, 73.0370, 84.0092, 89.0686, 100.3300, 108.8173, 119.1154, 265.8825, 493.3042, 851.1048, 1165.6934, 1589.0762, 2055.2161, 2481.3166, 3501.0184, 4258.2440, 4151.9682, 6119.5858, 6518.2127 ]
49+
compute_ZSTD_l1 = [ 0.0021, 0.0296, 0.1045, 0.3979, 0.8787, 1.3064, 1.7404, 2.1938, 2.6780, 3.3929, 3.8601, 4.3665, 5.0127, 5.7346, 6.1056, 7.9448, 8.2872, 9.4659, 9.2376, 10.4273, 11.6572, 22.0410, 36.7011, 65.2484, 84.9773, 123.1597, 147.6101, 274.7479, 384.7447, 442.0842, 512.2530, 641.9793, 702.5878 ]
5050

51-
create_ZSTD_l1_disk = [ 0.6564, 0.2825, 1.0826, 4.1968, 9.5022, 13.4840, 17.5387, 21.5807, 26.0052, 31.3524, 38.5889, 44.1105, 49.8849, 55.5297, 64.6479, 72.7471, 84.6595, 90.4970, 99.9710, 111.6817, 120.8941 ]
52-
compute_ZSTD_l1_disk = [ 0.0022, 0.0300, 0.1066, 0.4099, 0.8974, 1.3218, 1.7679, 2.2154, 2.7007, 3.4267, 3.9255, 4.4597, 5.1155, 5.8251, 6.2064, 8.0141, 8.4316, 9.3195, 9.4570, 10.7034, 11.9192 ]
51+
create_ZSTD_l1_disk = [ 0.6564, 0.2825, 1.0826, 4.1968, 9.5022, 13.4840, 17.5387, 21.5807, 26.0052, 31.3524, 38.5889, 44.1105, 49.8849, 55.5297, 64.6479, 72.7471, 84.6595, 90.4970, 99.9710, 111.6817, 120.8941, 234.9739, 391.9157, 648.5382, 920.2396, 1367.7080, 1647.1145, 2440.9581, 3028.6825, 3518.1483, 4601.6684, 5660.8254, 6723.2414 ]
52+
compute_ZSTD_l1_disk = [ 0.0022, 0.0300, 0.1066, 0.4099, 0.8974, 1.3218, 1.7679, 2.2154, 2.7007, 3.4267, 3.9255, 4.4597, 5.1155, 5.8251, 6.2064, 8.0141, 8.4316, 9.3195, 9.4570, 10.7034, 11.9192, 22.1895, 36.6542, 66.7209, 89.2111, 126.3853, 155.7241, 203.4894, 288.3248, 352.8067, 383.0908, 478.0074, 545.8722 ]
5353

5454
create_numpy = [ 0.0020, 0.0527, 0.2292, 0.9412, 2.1043, 2.8286, 3.7046, 4.7217, 5.8308, 7.0491 ]
5555
compute_numpy = [ 0.0179, 0.2495, 0.9840, 3.9263, 8.8450, 12.0259, 16.3507, 40.1672, 155.1292, 302.5115 ]

doc/reference/linear_algebra.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ The next functions can be used for computing linear algebra operations with :ref
1212
:nosignatures:
1313

1414
matmul
15+
transpose

src/blosc2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class Tuner(Enum):
248248
full,
249249
save,
250250
matmul,
251+
transpose,
251252
)
252253

253254
from .c2array import c2context, C2Array, URLPath

src/blosc2/ndarray.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,6 +3755,49 @@ def matmul(x1: NDArray, x2: NDArray, **kwargs: Any) -> NDArray:
37553755
return result.squeeze()
37563756

37573757

3758+
def transpose(x, **kwargs: Any) -> NDArray:
3759+
"""
3760+
Returns a Blosc2 NDArray with axes transposed.
3761+
3762+
Parameters
3763+
----------
3764+
x: `NDArray`
3765+
The input matrix.
3766+
kwargs: Any, optional
3767+
Keyword arguments that are supported by the :func:`empty` constructor.
3768+
3769+
Returns
3770+
-------
3771+
out: :ref:`NDArray`
3772+
The Blosc2 NDArray with axes transposed.
3773+
3774+
References
3775+
----------
3776+
`numpy.transpose <https://numpy.org/doc/2.2/reference/generated/numpy.transpose.html>`_
3777+
"""
3778+
3779+
# Validate arguments are not scalars
3780+
if np.isscalar(x) or x.ndim < 2:
3781+
return x
3782+
3783+
# Validate arguments are dimension 2
3784+
if x.ndim > 2:
3785+
raise ValueError("Transposing arrays with dimension greater than 2 is not supported yet.")
3786+
3787+
n, m = x.shape
3788+
p, q = x.chunks
3789+
result = blosc2.zeros((m, n), dtype=np.result_type(x), **kwargs)
3790+
3791+
for row in range(0, n, p):
3792+
row_end = (row + p) if (row + p) < n else n
3793+
for col in range(0, m, q):
3794+
col_end = (col + q) if (col + q) < m else m
3795+
aux = x[row:row_end, col:col_end]
3796+
result[col:col_end, row:row_end] = np.transpose(aux).copy()
3797+
3798+
return result
3799+
3800+
37583801
# Class for dealing with fields in an NDArray
37593802
# This will allow to access fields by name in the dtype of the NDArray
37603803
class NDField(Operand):

tests/ndarray/test_matmul.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,50 @@
2121
)
2222
@pytest.mark.parametrize(
2323
"dtype",
24-
{np.float32, np.float64, np.complex64, np.complex128},
24+
{np.float32, np.float64},
2525
)
2626
def test_matmul(ashape, achunks, ablocks, bshape, bchunks, bblocks, dtype):
27-
a = blosc2.linspace(0, 10, dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks)
28-
b = blosc2.linspace(0, 10, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks)
27+
a = blosc2.linspace(0, 1, dtype=dtype, shape=ashape, chunks=achunks, blocks=ablocks)
28+
b = blosc2.linspace(0, 1, dtype=dtype, shape=bshape, chunks=bchunks, blocks=bblocks)
29+
c = blosc2.matmul(a, b)
30+
31+
na = a[:]
32+
nb = b[:]
33+
nc = np.matmul(na, nb)
34+
35+
np.testing.assert_allclose(c, nc, rtol=1e-6)
36+
37+
38+
@pytest.mark.parametrize(
39+
("ashape", "achunks", "ablocks"),
40+
{
41+
((12, 10), (7, 5), (3, 3)),
42+
((10,), (9,), (7,)),
43+
},
44+
)
45+
@pytest.mark.parametrize(
46+
("bshape", "bchunks", "bblocks"),
47+
{
48+
((10,), (4,), (2,)),
49+
((10, 5), (3, 4), (1, 3)),
50+
((10, 12), (2, 4), (1, 2)),
51+
},
52+
)
53+
@pytest.mark.parametrize(
54+
"dtype",
55+
{np.complex64, np.complex128},
56+
)
57+
def test_complex(ashape, achunks, ablocks, bshape, bchunks, bblocks, dtype):
58+
real_part = blosc2.linspace(0, 1, shape=ashape, chunks=achunks, blocks=ablocks, dtype=dtype)
59+
imag_part = blosc2.linspace(0, 1, shape=ashape, chunks=achunks, blocks=ablocks, dtype=dtype)
60+
complex_matrix_a = real_part + 1j * imag_part
61+
a = blosc2.asarray(complex_matrix_a)
62+
63+
real_part = blosc2.linspace(1, 2, shape=bshape, chunks=bchunks, blocks=bblocks, dtype=dtype)
64+
imag_part = blosc2.linspace(1, 2, shape=bshape, chunks=bchunks, blocks=bblocks, dtype=dtype)
65+
complex_matrix_b = real_part + 1j * imag_part
66+
b = blosc2.asarray(complex_matrix_b)
67+
2968
c = blosc2.matmul(a, b)
3069

3170
na = a[:]

tests/ndarray/test_transpose.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import numpy as np
2+
import pytest
3+
4+
import blosc2
5+
6+
7+
@pytest.mark.parametrize(
8+
("shape", "chunks", "blocks"),
9+
{
10+
((3, 3), (2, 2), (1, 1)),
11+
((12, 11), (7, 5), (6, 2)),
12+
((1, 5), (1, 4), (1, 3)),
13+
((201, 1903), None, None),
14+
((10,), (5,), None),
15+
},
16+
)
17+
@pytest.mark.parametrize(
18+
"dtype",
19+
{np.int32, np.int64, np.float32, np.float64},
20+
)
21+
def test_transpose(shape, chunks, blocks, dtype):
22+
a = blosc2.linspace(0, 1, shape=shape, chunks=chunks, blocks=blocks, dtype=dtype)
23+
at = blosc2.transpose(a)
24+
25+
na = a[:]
26+
nat = np.transpose(na)
27+
28+
np.testing.assert_allclose(at, nat)
29+
30+
31+
@pytest.mark.parametrize(
32+
("shape", "chunks", "blocks"),
33+
{
34+
((3, 3), (2, 2), (1, 1)),
35+
((12, 11), (7, 5), (6, 2)),
36+
((1, 5), (1, 4), (1, 3)),
37+
((201, 1903), None, None),
38+
((10,), (5,), None),
39+
},
40+
)
41+
@pytest.mark.parametrize(
42+
"dtype",
43+
{np.complex64, np.complex128},
44+
)
45+
def test_complex(shape, chunks, blocks, dtype):
46+
real_part = blosc2.linspace(0, 1, shape=shape, chunks=chunks, blocks=blocks, dtype=dtype)
47+
imag_part = blosc2.linspace(0, 1, shape=shape, chunks=chunks, blocks=blocks, dtype=dtype)
48+
complex_matrix = real_part + 1j * imag_part
49+
50+
a = blosc2.asarray(complex_matrix)
51+
at = blosc2.transpose(a)
52+
53+
na = a[:]
54+
nat = np.transpose(na)
55+
56+
np.testing.assert_allclose(at, nat)
57+
58+
59+
@pytest.mark.parametrize(
60+
"scalar",
61+
{
62+
1, # int
63+
5.1, # float
64+
1 + 2j, # complex
65+
np.int8(2), # NumPy int8
66+
np.int16(3), # NumPy int16
67+
np.int32(4), # NumPy int32
68+
np.int64(5), # NumPy int64
69+
np.float32(5.2), # NumPy float32
70+
np.float64(5.3), # NumPy float64
71+
np.complex64(0 + 3j), # NumPy complex64
72+
np.complex128(2 - 4j), # NumPy complex128
73+
},
74+
)
75+
def test_scalars(scalar):
76+
at = blosc2.transpose(scalar)
77+
nat = np.transpose(scalar)
78+
79+
np.testing.assert_allclose(at, nat)
80+
81+
82+
@pytest.mark.parametrize(
83+
"shape",
84+
[
85+
(3, 3, 3),
86+
(12, 10, 10),
87+
(10, 10, 10, 11),
88+
(5, 4, 3, 2, 1, 0),
89+
],
90+
)
91+
def test_dims(shape):
92+
a = blosc2.linspace(0, 1, shape=shape)
93+
94+
with pytest.raises(ValueError):
95+
blosc2.transpose(a)
96+
97+
98+
def test_disk():
99+
a = blosc2.linspace(0, 1, shape=(3, 4), urlpath="a_test.b2nd", mode="w")
100+
c = blosc2.transpose(a, urlpath="c_test.b2nd", mode="w")
101+
102+
na = a[:]
103+
nc = np.transpose(na)
104+
105+
np.testing.assert_allclose(c, nc, rtol=1e-6)
106+
107+
blosc2.remove_urlpath("a_test.b2nd")
108+
blosc2.remove_urlpath("c_test.b2nd")

0 commit comments

Comments
 (0)