@@ -5454,6 +5454,10 @@ def arange_fill(inputs, output, offset):
54545454 else : # use linspace to have finer control over exclusion of endpoint for float types
54555455 output [:] = np .linspace (start , stop , lout , endpoint = False , dtype = output .dtype )
54565456
5457+ @blosc2 .dsl_kernel
5458+ def ramp_arange (start , step ):
5459+ return start + _flat_idx * step # noqa: F821 # DSL index/shape symbols resolved by miniexpr
5460+
54575461 if step is None : # not array-api compliant but for backwards compatibility
54585462 step = 1
54595463 if stop is None :
@@ -5478,14 +5482,19 @@ def arange_fill(inputs, output, offset):
54785482 # We already have the dtype and shape, so return immediately
54795483 return blosc2 .zeros (shape , dtype = dtype , ** kwargs )
54805484
5481- lshape = (math .prod (shape ),)
5482- lazyarr = blosc2 .lazyudf (arange_fill , (start , stop , step ), dtype = dtype , shape = lshape )
5485+ # Windows and wasm32 does not support complex numbers in DSL
5486+ if blosc2 .isdtype (dtype , "complex floating" ):
5487+ lshape = (math .prod (shape ),)
5488+ lazyarr = blosc2 .lazyudf (arange_fill , (start , stop , step ), dtype = dtype , shape = lshape )
54835489
5484- if len (shape ) == 1 :
5485- # C order is guaranteed, and no reshape is needed
5486- return lazyarr .compute (** kwargs )
5490+ if len (shape ) == 1 :
5491+ # C order is guaranteed, and no reshape is needed
5492+ return lazyarr .compute (** kwargs )
54875493
5488- return reshape (lazyarr , shape , c_order = c_order , ** kwargs )
5494+ return reshape (lazyarr , shape , c_order = c_order , ** kwargs )
5495+ else :
5496+ lazyarr = blosc2 .lazyudf (ramp_arange , (start , step ), dtype = dtype , shape = shape )
5497+ return lazyarr .compute (** kwargs )
54895498
54905499
54915500# Define a numpy linspace-like function
@@ -5550,6 +5559,10 @@ def linspace_fill(inputs, output, offset):
55505559 else :
55515560 output [:] = np .linspace (start_ , stop_ , lout , endpoint = False , dtype = output .dtype )
55525561
5562+ @blosc2 .dsl_kernel
5563+ def ramp_linspace (start , step ):
5564+ return float (start ) + _flat_idx * float (step ) # noqa: F821 # DSL index/shape symbols resolved by miniexpr
5565+
55535566 if shape is None :
55545567 if num is None :
55555568 raise ValueError ("Either `shape` or `num` must be specified." )
@@ -5579,13 +5592,21 @@ def linspace_fill(inputs, output, offset):
55795592 # We already have the dtype and shape, so return immediately
55805593 return blosc2 .zeros (shape , dtype = dtype , ** kwargs ) # will return empty array for num == 0
55815594
5582- inputs = (start , stop , num , endpoint )
5583- lazyarr = blosc2 .lazyudf (linspace_fill , inputs , dtype = dtype , shape = (num ,))
5584- if len (shape ) == 1 :
5585- # C order is guaranteed, and no reshape is needed
5586- return lazyarr .compute (** kwargs )
5595+ # Windows and wasm32 does not support complex numbers in DSL
5596+ if blosc2 .isdtype (dtype , "complex floating" ):
5597+ inputs = (start , stop , num , endpoint )
5598+ lazyarr = blosc2 .lazyudf (linspace_fill , inputs , dtype = dtype , shape = (num ,))
5599+ if len (shape ) == 1 :
5600+ # C order is guaranteed, and no reshape is needed
5601+ return lazyarr .compute (** kwargs )
55875602
5588- return reshape (lazyarr , shape , c_order = c_order , ** kwargs )
5603+ return reshape (lazyarr , shape , c_order = c_order , ** kwargs )
5604+ else :
5605+ nitems = num - 1 if endpoint else num
5606+ step = (float (stop ) - float (start )) / float (nitems ) if nitems > 0 else 0.0
5607+ inputs = (start , step )
5608+ lazyarr = blosc2 .lazyudf (ramp_linspace , inputs , dtype = dtype , shape = shape )
5609+ return lazyarr .compute (** kwargs )
55895610
55905611
55915612def eye (N , M = None , k = 0 , dtype = np .float64 , ** kwargs : Any ) -> NDArray :
0 commit comments