@@ -123,7 +123,7 @@ def dataarray_to_matrix(grid):
123
123
inc = [abs (i ) for i in inc ]
124
124
grid = grid .sortby (variables = list (grid .dims ), ascending = True )
125
125
126
- matrix = as_c_contiguous (grid [::- 1 ].to_numpy ())
126
+ matrix = np . ascontiguousarray (grid [::- 1 ].to_numpy ())
127
127
region = [float (i ) for i in region ]
128
128
inc = [float (i ) for i in inc ]
129
129
return matrix , region , inc
@@ -200,53 +200,11 @@ def vectors_to_arrays(vectors):
200
200
for vector in vectors :
201
201
vec_dtype = str (getattr (vector , "dtype" , "" ))
202
202
array = np .asarray (a = vector , dtype = dtypes .get (vec_dtype ))
203
- arrays .append (as_c_contiguous (array ))
203
+ arrays .append (np . ascontiguousarray (array ))
204
204
205
205
return arrays
206
206
207
207
208
- def as_c_contiguous (array ):
209
- """
210
- Ensure a numpy array is C contiguous in memory.
211
-
212
- If the array is not C contiguous, a copy will be necessary.
213
-
214
- Parameters
215
- ----------
216
- array : 1-D array
217
- The numpy array
218
-
219
- Returns
220
- -------
221
- array : 1-D array
222
- Array is C contiguous order.
223
-
224
- Examples
225
- --------
226
-
227
- >>> import numpy as np
228
- >>> data = np.array([[1, 2], [3, 4], [5, 6]])
229
- >>> x = data[:, 0]
230
- >>> x
231
- array([1, 3, 5])
232
- >>> x.flags.c_contiguous
233
- False
234
- >>> new_x = as_c_contiguous(x)
235
- >>> new_x
236
- array([1, 3, 5])
237
- >>> new_x.flags.c_contiguous
238
- True
239
- >>> x = np.array([8, 9, 10])
240
- >>> x.flags.c_contiguous
241
- True
242
- >>> as_c_contiguous(x).flags.c_contiguous
243
- True
244
- """
245
- if not array .flags .c_contiguous :
246
- return array .copy (order = "C" )
247
- return array
248
-
249
-
250
208
def sequence_to_ctypes_array (
251
209
sequence : Sequence | None , ctype , size : int
252
210
) -> ctp .Array | None :
0 commit comments