@@ -2776,6 +2776,11 @@ def _check_shape(shape):
27762776 raise TypeError ("shape should be a tuple or a list!" )
27772777 return shape
27782778
2779+ def _check_dtype (dtype ):
2780+ dtype = np .dtype (dtype )
2781+ if dtype .itemsize > blosc2 .MAX_TYPESIZE :
2782+ raise ValueError (f"dtype itemsize { dtype .itemsize } is too large (>{ blosc2 .MAX_TYPESIZE } )!" )
2783+ return dtype
27792784
27802785def empty (shape : int | tuple | list , dtype : np .dtype | str | None = np .float64 , ** kwargs : Any ) -> NDArray :
27812786 """Create an empty array.
@@ -2822,7 +2827,7 @@ def empty(shape: int | tuple | list, dtype: np.dtype | str | None = np.float64,
28222827 >>> array.dtype
28232828 dtype('int32')
28242829 """
2825- dtype = np . dtype (dtype )
2830+ dtype = _check_dtype (dtype )
28262831 shape = _check_shape (shape )
28272832 kwargs = _check_ndarray_kwargs (** kwargs )
28282833 chunks = kwargs .pop ("chunks" , None )
@@ -2856,7 +2861,7 @@ def uninit(shape: int | tuple | list, dtype: np.dtype | str = np.float64, **kwar
28562861 >>> array.dtype
28572862 dtype('float64')
28582863 """
2859- dtype = np . dtype (dtype )
2864+ dtype = _check_dtype (dtype )
28602865 shape = _check_shape (shape )
28612866 kwargs = _check_ndarray_kwargs (** kwargs )
28622867 chunks = kwargs .pop ("chunks" , None )
@@ -2890,7 +2895,7 @@ def nans(shape: int | tuple | list, dtype: np.dtype | str = np.float64, **kwargs
28902895 >>> array.dtype
28912896 dtype('float64')
28922897 """
2893- dtype = np . dtype (dtype )
2898+ dtype = _check_dtype (dtype )
28942899 shape = _check_shape (shape )
28952900 kwargs = _check_ndarray_kwargs (** kwargs )
28962901 chunks = kwargs .pop ("chunks" , None )
@@ -2930,7 +2935,7 @@ def zeros(shape: int | tuple | list, dtype: np.dtype | str = np.float64, **kwarg
29302935 >>> array.dtype
29312936 dtype('float64')
29322937 """
2933- dtype = np . dtype (dtype )
2938+ dtype = _check_dtype (dtype )
29342939 shape = _check_shape (shape )
29352940 kwargs = _check_ndarray_kwargs (** kwargs )
29362941 chunks = kwargs .pop ("chunks" , None )
@@ -2990,6 +2995,7 @@ def full(
29902995 dtype = np .dtype (type (fill_value ))
29912996 else :
29922997 dtype = np .dtype (dtype )
2998+ dtype = _check_dtype (dtype )
29932999 shape = _check_shape (shape )
29943000 kwargs = _check_ndarray_kwargs (** kwargs )
29953001 chunks = kwargs .pop ("chunks" , None )
@@ -3101,8 +3107,7 @@ def arange_fill(inputs, output, offset):
31013107 # Check that the shape is consistent with the start, stop and step values
31023108 if math .prod (shape ) != int ((stop - start ) / step ):
31033109 raise ValueError ("The shape is not consistent with the start, stop and step values" )
3104- # Check dtype
3105- dtype = np .dtype (dtype )
3110+ dtype = _check_dtype (dtype )
31063111
31073112 if is_inside_new_expr ():
31083113 # We already have the dtype and shape, so return immediately
@@ -3170,8 +3175,7 @@ def linspace_fill(inputs, output, offset):
31703175
31713176 if not shape :
31723177 shape = (num ,)
3173- # Check dtype
3174- dtype = np .dtype (dtype )
3178+ dtype = _check_dtype (dtype )
31753179
31763180 if is_inside_new_expr ():
31773181 # We already have the dtype and shape, so return immediately
@@ -3230,8 +3234,7 @@ def fill_eye(inputs, output: np.array, offset: tuple):
32303234 if M is None :
32313235 M = N
32323236 shape = (N , M )
3233- # Check dtype
3234- dtype = np .dtype (dtype )
3237+ dtype = _check_dtype (dtype )
32353238
32363239 if is_inside_new_expr ():
32373240 # We already have the dtype and shape, so return immediately
@@ -3284,8 +3287,7 @@ def iter_fill(inputs, output, offset):
32843287 (iterable ,) = inputs
32853288 output [:] = np .fromiter (iterable , dtype = output .dtype , count = nout ).reshape (output .shape )
32863289
3287- # Check dtype
3288- dtype = np .dtype (dtype )
3290+ dtype = _check_dtype (dtype )
32893291
32903292 if is_inside_new_expr ():
32913293 # We already have the dtype and shape, so return immediately
0 commit comments