@@ -207,17 +207,18 @@ def __init__(
207
207
fill_value = None ,
208
208
idx_dtype = None ,
209
209
):
210
+ if isinstance (coords , COO ):
211
+ self ._make_shallow_copy_of (coords )
212
+ if data is not None or shape is not None :
213
+ raise ValueError ("If `coords` is `COO`, then no other arguments should be provided." )
214
+ if fill_value is not None :
215
+ self .fill_value = self .data .dtype .type (fill_value )
216
+ return
217
+
210
218
self ._cache = None
211
219
if cache :
212
220
self .enable_caching ()
213
221
214
- if not isinstance (coords , np .ndarray ):
215
- warnings .warn (
216
- "coords should be an ndarray. This will raise a ValueError in the future." ,
217
- DeprecationWarning ,
218
- stacklevel = 1 ,
219
- )
220
-
221
222
if data is None :
222
223
arr = as_coo (coords , shape = shape , fill_value = fill_value , idx_dtype = idx_dtype )
223
224
self ._make_shallow_copy_of (arr )
@@ -238,15 +239,10 @@ def __init__(
238
239
self .data = np .broadcast_to (self .data , self .coords .shape [1 ])
239
240
240
241
if self .data .ndim != 1 :
241
- raise ValueError ("data must be a scalar or 1-dimensional." )
242
+ raise ValueError ("` data` must be a scalar or 1-dimensional." )
242
243
243
244
if shape is None :
244
- warnings .warn (
245
- "shape should be provided. This will raise a ValueError in the future." ,
246
- DeprecationWarning ,
247
- stacklevel = 1 ,
248
- )
249
- shape = tuple (self .coords .max (axis = 1 ) + 1 ) if self .coords .nbytes else ()
245
+ raise ValueError ("`shape` was not provided." )
250
246
251
247
if not isinstance (shape , Iterable ):
252
248
shape = (shape ,)
@@ -256,7 +252,6 @@ def __init__(
256
252
257
253
if shape and not self .coords .size :
258
254
self .coords = np .zeros ((len (shape ) if isinstance (shape , Iterable ) else 1 , 0 ), dtype = np .intp )
259
-
260
255
super ().__init__ (shape , fill_value = fill_value )
261
256
if idx_dtype :
262
257
if not can_store (idx_dtype , max (shape )):
@@ -417,11 +412,12 @@ def todense(self):
417
412
coords = tuple ([self .coords [i , :] for i in range (self .ndim )])
418
413
data = self .data
419
414
420
- if coords != () :
415
+ if len ( coords ) != 0 :
421
416
x [coords ] = data
422
417
else :
423
418
if len (data ) != 0 :
424
- x [coords ] = data
419
+ assert data .shape == (1 ,)
420
+ x [...] = data [0 ]
425
421
426
422
return x
427
423
@@ -1157,52 +1153,6 @@ def squeeze(self, axis=None):
1157
1153
fill_value = self .fill_value ,
1158
1154
)
1159
1155
1160
- def resize (self , * args , refcheck = True , coords_dtype = np .intp ):
1161
- """
1162
- This method changes the shape and size of an array in-place.
1163
- Parameters
1164
- ----------
1165
- args : tuple, or series of integers
1166
- The desired shape of the output array.
1167
-
1168
- See Also
1169
- --------
1170
- [`numpy.ndarray.resize`][] : The equivalent Numpy function.
1171
-
1172
- """
1173
- warnings .warn ("resize is deprecated on all SpraseArray objects." , DeprecationWarning , stacklevel = 1 )
1174
- if len (args ) == 1 and isinstance (args [0 ], tuple ):
1175
- shape = args [0 ]
1176
- elif all (isinstance (arg , int ) for arg in args ):
1177
- shape = tuple (args )
1178
- else :
1179
- raise ValueError ("Invalid input" )
1180
-
1181
- if any (d < 0 for d in shape ):
1182
- raise ValueError ("negative dimensions not allowed" )
1183
-
1184
- new_size = reduce (operator .mul , shape , 1 )
1185
-
1186
- # TODO: this self.size enforces a 2**64 limit to array size
1187
- linear_loc = self .linear_loc ()
1188
- end_idx = np .searchsorted (linear_loc , new_size , side = "left" )
1189
- linear_loc = linear_loc [:end_idx ]
1190
-
1191
- idx_dtype = self .coords .dtype
1192
- if shape != () and not can_store (idx_dtype , max (shape )):
1193
- idx_dtype = np .min_scalar_type (max (shape ))
1194
- coords = np .empty ((len (shape ), len (linear_loc )), dtype = idx_dtype )
1195
- strides = 1
1196
- for i , d in enumerate (shape [::- 1 ]):
1197
- coords [- (i + 1 ), :] = (linear_loc // strides ) % d
1198
- strides *= d
1199
-
1200
- self .shape = shape
1201
- self .coords = coords
1202
-
1203
- if len (self .data ) != len (linear_loc ):
1204
- self .data = self .data [:end_idx ].copy ()
1205
-
1206
1156
def to_scipy_sparse (self , / , * , accept_fv = None ):
1207
1157
"""
1208
1158
Converts this [`sparse.COO`][] object into a [`scipy.sparse.coo_matrix`][].
0 commit comments