Skip to content

Commit 4702ff3

Browse files
committed
Preliminary DSL implementation for blosc2.arange
1 parent 53e5635 commit 4702ff3

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ endif()
6363

6464
FetchContent_Declare(miniexpr
6565
GIT_REPOSITORY https://github.com/Blosc/miniexpr.git
66-
GIT_TAG 574ce6953bfa5106ac18113831200e3173add1f8
66+
GIT_TAG 4b611752e0598955a3b2e8931868f7b3a8ad3e77
6767
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../miniexpr
6868
)
6969
FetchContent_MakeAvailable(miniexpr)

src/blosc2/ndarray.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5406,6 +5406,10 @@ def arange_fill(inputs, output, offset):
54065406
else: # use linspace to have finer control over exclusion of endpoint for float types
54075407
output[:] = np.linspace(start, stop, lout, endpoint=False, dtype=output.dtype)
54085408

5409+
@blosc2.dsl_kernel
5410+
def kernel_ramp(start, step):
5411+
return start + _global_linear_idx * step # noqa: F821 # DSL index/shape symbols resolved by miniexpr
5412+
54095413
if step is None: # not array-api compliant but for backwards compatibility
54105414
step = 1
54115415
if stop is None:
@@ -5430,14 +5434,18 @@ def arange_fill(inputs, output, offset):
54305434
# We already have the dtype and shape, so return immediately
54315435
return blosc2.zeros(shape, dtype=dtype, **kwargs)
54325436

5433-
lshape = (math.prod(shape),)
5434-
lazyarr = blosc2.lazyudf(arange_fill, (start, stop, step), dtype=dtype, shape=lshape)
5437+
if False:
5438+
lshape = (math.prod(shape),)
5439+
lazyarr = blosc2.lazyudf(arange_fill, (start, stop, step), dtype=dtype, shape=lshape)
54355440

5436-
if len(shape) == 1:
5437-
# C order is guaranteed, and no reshape is needed
5438-
return lazyarr.compute(**kwargs)
5441+
if len(shape) == 1:
5442+
# C order is guaranteed, and no reshape is needed
5443+
return lazyarr.compute(**kwargs)
54395444

5440-
return reshape(lazyarr, shape, c_order=c_order, **kwargs)
5445+
return reshape(lazyarr, shape, c_order=c_order, **kwargs)
5446+
else:
5447+
lazyarr = blosc2.lazyudf(kernel_ramp, (start, step), dtype=dtype, shape=shape)
5448+
return lazyarr.compute(**kwargs)
54415449

54425450

54435451
# Define a numpy linspace-like function

0 commit comments

Comments
 (0)