/
indexing.py
59 lines (40 loc) · 1.75 KB
/
indexing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def take(a, indices, axis=None, out=None):
"""Takes elements of an array at specified indices along an axis.
This is an implementation of "fancy indexing" at single axis.
This function does not support ``mode`` option.
Args:
a (cupy.ndarray): Array to extract elements.
indices (int or array-like): Indices of elements that this function
takes.
axis (int): The axis along which to select indices. The flattened input
is used by default.
out (cupy.ndarray): Output array. If provided, it should be of
appropriate shape and dtype.
Returns:
cupy.ndarray: The result of fancy indexing.
.. seealso:: :func:`numpy.take`
"""
# TODO(okuta): check type
return a.take(indices, axis, out)
def choose(a, choices, out=None, mode='raise'):
return a.choose(choices, out, mode)
# TODO(okuta): Implement compress
def diagonal(a, offset=0, axis1=0, axis2=1):
"""Returns specified diagonals.
This function extracts the diagonals along two specified axes. The other
axes are not changed. This function returns a writable view of this array
as NumPy 1.10 will do.
Args:
a (cupy.ndarray): Array from which the diagonals are taken.
offset (int): Index of the diagonals. Zero indicates the main
diagonals, a positive value upper diagonals, and a negative value
lower diagonals.
axis1 (int): The first axis to take diagonals from.
axis2 (int): The second axis to take diagonals from.
Returns:
cupy.ndarray: A view of the diagonals of ``a``.
.. seealso:: :func:`numpy.diagonal`
"""
# TODO(okuta): check type
return a.diagonal(offset, axis1, axis2)
# TODO(okuta): Implement select