dpnp
dpnp copied to clipboard
Array manipulation routines
Need to implement following functions as described here Array manipulation routines
Basic operations
- [x] copyto(dst, src[, casting, where]) Copies values from one array to another, broadcasting as necessary.
- [x] shape(a) Return the shape of an array.
Changing array shape
- [x] reshape(a, newshape[, order]) Gives a new shape to an array without changing its data.
- [x] ravel(a[, order]) Return a contiguous flattened array.
- [x] ndarray.flat A 1-D iterator over the array.
- [x] ndarray.flatten([order]) Return a copy of the array collapsed into one dimension.
Transpose-like operations
- [x] moveaxis(a, source, destination) Move axes of an array to new positions.
- [x] rollaxis(a, axis[, start]) Roll the specified axis backwards, until it lies in a given position.
- [x] swapaxes(a, axis1, axis2) Interchange two axes of an array.
- [x] ndarray.T The transposed array.
- [x] transpose(a[, axes]) Reverse or permute the axes of an array; returns the modified array.
Changing number of dimensions
- [x] atleast_1d(*arys) Convert inputs to arrays with at least one dimension.
- [x] atleast_2d(*arys) View inputs as arrays with at least two dimensions.
- [x] atleast_3d(*arys) View inputs as arrays with at least three dimensions.
- [ ] broadcast Produce an object that mimics broadcasting.
- [ ] broadcast_to(array, shape[, subok]) Broadcast an array to a new shape.
- [ ] broadcast_arrays(*args[, subok]) Broadcast any number of arrays against each other.
- [x] expand_dims(a, axis) Expand the shape of an array.
- [x] squeeze(a[, axis]) Remove single-dimensional entries from the shape of an array.
Changing kind of array
- [x] asarray(a[, dtype, order]) Convert the input to an array.
- [x] asanyarray(a[, dtype, order]) Convert the input to an ndarray, but pass ndarray subclasses through.
- [ ] asmatrix(data[, dtype]) Interpret the input as a matrix.
- [x] asfarray(a[, dtype]) Return an array converted to a float type.
- [x] asfortranarray(a[, dtype]) Return an array (ndim >= 1) laid out in Fortran order in memory.
- [x] ascontiguousarray(a[, dtype]) Return a contiguous array (ndim >= 1) in memory (C order).
- [x] asarray_chkfinite(a[, dtype, order]) Convert the input to an array, checking for NaNs or Infs.
- [ ] asscalar(a) Convert an array of size 1 to its scalar equivalent.
- [x] require(a[, dtype, requirements]) Return an ndarray of the provided type that satisfies requirements.
Joining arrays
- [x] concatenate([axis, out]) Join a sequence of arrays along an existing axis.
- [x] stack(arrays[, axis, out]) Join a sequence of arrays along a new axis.
- [ ] block(arrays) Assemble an nd-array from nested lists of blocks.
- [x] vstack(tup) Stack arrays in sequence vertically (row wise).
- [x] hstack(tup) Stack arrays in sequence horizontally (column wise).
- [x] dstack(tup) Stack arrays in sequence depth wise (along third axis).
- [x] column_stack(tup) Stack 1-D arrays as columns into a 2-D array.
Splitting arrays
- [x] split(ary, indices_or_sections[, axis]) Split an array into multiple sub-arrays as views into ary.
- [x] array_split(ary, indices_or_sections[, axis]) Split an array into multiple sub-arrays.
- [x] dsplit(ary, indices_or_sections) Split array into multiple sub-arrays along the 3rd axis (depth).
- [x] hsplit(ary, indices_or_sections) Split an array into multiple sub-arrays horizontally (column-wise).
- [x] vsplit(ary, indices_or_sections) Split an array into multiple sub-arrays vertically (row-wise).
Tiling arrays
- [x] tile(A, reps) Construct an array by repeating A the number of times given by reps.
- [x] repeat(a, repeats[, axis]) Repeat elements of an array.
Adding and removing elements
- [x] delete(arr, obj[, axis]) Return a new array with sub-arrays along an axis deleted.
- [x] insert(arr, obj, values[, axis]) Insert values along the given axis before the given indices.
- [x] append(arr, values[, axis]) Append values to the end of an array.
- [x] resize(a, new_shape) Return a new array with the specified shape.
- [x] trim_zeros(filt[, trim]) Trim the leading and/or trailing zeros from a 1-D array or sequence.
- [x] unique(ar[, return_index, return_inverse, …]) Find the unique elements of an array.
Rearranging elements
- [x] flip(m[, axis]) Reverse the order of elements in an array along the given axis.
- [x] fliplr(m) Flip array in the left/right direction.
- [x] flipud(m) Flip array in the up/down direction.
- [x] reshape(a, newshape[, order]) Gives a new shape to an array without changing its data.
- [x] roll(a, shift[, axis]) Roll array elements along a given axis.
- [x] rot90(m[, k, axes]) Rotate an array by 90 degrees in the plane specified by axes.
Just noticed that numpy repeat and dpnp repeat are slightly different, as dpnp doesn't allow repeating a non-array.
eg
import dpnp as dnp
dnp.repeat(0.05, 3) # error 'float' object has no attribute 'ndim'
import numpy as np
np.repeat(0.05, 3) # ok
Just leaving this here in case someone else is confused by the same thing.
@stisa, thank you for noticing that.
As per documentation dpnp.repeat supports input array x of either dpnp.ndarray or usm_ndarray type.
We will prepare a PR to raise an explicit TypeError exception in case when x passed with unsupported type to make the issue more clear.