|
41 | 41 |
|
42 | 42 |
|
43 | 43 | import numpy
|
| 44 | +import dpnp |
44 | 45 |
|
45 | 46 | from dpnp.backend import *
|
46 | 47 | from dpnp.dparray import dparray
|
47 | 48 | from dpnp.dpnp_utils import *
|
48 | 49 |
|
49 | 50 |
|
50 | 51 | __all__ = [
|
| 52 | + "all", |
| 53 | + "any", |
51 | 54 | "equal",
|
52 | 55 | "greater",
|
53 | 56 | "greater_equal",
|
|
65 | 68 | ]
|
66 | 69 |
|
67 | 70 |
|
| 71 | +def all(in_array1, axis=None, out=None, keepdims=False): |
| 72 | + """ |
| 73 | + Test whether all array elements along a given axis evaluate to True. |
| 74 | +
|
| 75 | + Parameters |
| 76 | + ---------- |
| 77 | + a : array_like |
| 78 | + Input array or object that can be converted to an array. |
| 79 | + axis : None or int or tuple of ints, optional |
| 80 | + Axis or axes along which a logical AND reduction is performed. |
| 81 | + The default (``axis=None``) is to perform a logical AND over all |
| 82 | + the dimensions of the input array. `axis` may be negative, in |
| 83 | + which case it counts from the last to the first axis. |
| 84 | +
|
| 85 | + .. versionadded:: 1.7.0 |
| 86 | +
|
| 87 | + If this is a tuple of ints, a reduction is performed on multiple |
| 88 | + axes, instead of a single axis or all the axes as before. |
| 89 | + out : ndarray, optional |
| 90 | + Alternate output array in which to place the result. |
| 91 | + It must have the same shape as the expected output and its |
| 92 | + type is preserved (e.g., if ``dtype(out)`` is float, the result |
| 93 | + will consist of 0.0's and 1.0's). See `ufuncs-output-type` for more |
| 94 | + details. |
| 95 | +
|
| 96 | + keepdims : bool, optional |
| 97 | + If this is set to True, the axes which are reduced are left |
| 98 | + in the result as dimensions with size one. With this option, |
| 99 | + the result will broadcast correctly against the input array. |
| 100 | +
|
| 101 | + If the default value is passed, then `keepdims` will not be |
| 102 | + passed through to the `all` method of sub-classes of |
| 103 | + `ndarray`, however any non-default value will be. If the |
| 104 | + sub-class' method does not implement `keepdims` any |
| 105 | + exceptions will be raised. |
| 106 | +
|
| 107 | + Returns |
| 108 | + ------- |
| 109 | + all : ndarray, bool |
| 110 | + A new boolean or array is returned unless `out` is specified, |
| 111 | + in which case a reference to `out` is returned. |
| 112 | +
|
| 113 | + See Also |
| 114 | + -------- |
| 115 | + ndarray.all : equivalent method |
| 116 | +
|
| 117 | + any : Test whether any element along a given axis evaluates to True. |
| 118 | +
|
| 119 | + Notes |
| 120 | + ----- |
| 121 | + Not a Number (NaN), positive infinity and negative infinity |
| 122 | + evaluate to `True` because these are not equal to zero. |
| 123 | +
|
| 124 | + """ |
| 125 | + |
| 126 | + is_dparray1 = isinstance(in_array1, dparray) |
| 127 | + |
| 128 | + if (not use_origin_backend(in_array1) and is_dparray1): |
| 129 | + if axis is not None: |
| 130 | + checker_throw_value_error("all", "axis", type(axis), None) |
| 131 | + if out is not None: |
| 132 | + checker_throw_value_error("all", "out", type(out), None) |
| 133 | + if keepdims is not False: |
| 134 | + checker_throw_value_error("all", "keepdims", keepdims, False) |
| 135 | + |
| 136 | + result = dpnp_all(in_array1) |
| 137 | + |
| 138 | + # scalar returned |
| 139 | + if result.shape == (1,): |
| 140 | + return result.dtype.type(result[0]) |
| 141 | + |
| 142 | + return result |
| 143 | + |
| 144 | + return call_origin(numpy.all, axis, out, keepdims) |
| 145 | + |
| 146 | + |
| 147 | +def any(in_array1, axis=None, out=None, keepdims=False): |
| 148 | + """ |
| 149 | + Test whether any array element along a given axis evaluates to True. |
| 150 | +
|
| 151 | + Returns single boolean unless `axis` is not ``None`` |
| 152 | +
|
| 153 | + Parameters |
| 154 | + ---------- |
| 155 | + a : array_like |
| 156 | + Input array or object that can be converted to an array. |
| 157 | + axis : None or int or tuple of ints, optional |
| 158 | + Axis or axes along which a logical OR reduction is performed. |
| 159 | + The default (``axis=None``) is to perform a logical OR over all |
| 160 | + the dimensions of the input array. `axis` may be negative, in |
| 161 | + which case it counts from the last to the first axis. |
| 162 | +
|
| 163 | + .. versionadded:: 1.7.0 |
| 164 | +
|
| 165 | + If this is a tuple of ints, a reduction is performed on multiple |
| 166 | + axes, instead of a single axis or all the axes as before. |
| 167 | + out : ndarray, optional |
| 168 | + Alternate output array in which to place the result. It must have |
| 169 | + the same shape as the expected output and its type is preserved |
| 170 | + (e.g., if it is of type float, then it will remain so, returning |
| 171 | + 1.0 for True and 0.0 for False, regardless of the type of `a`). |
| 172 | + See `ufuncs-output-type` for more details. |
| 173 | +
|
| 174 | + keepdims : bool, optional |
| 175 | + If this is set to True, the axes which are reduced are left |
| 176 | + in the result as dimensions with size one. With this option, |
| 177 | + the result will broadcast correctly against the input array. |
| 178 | +
|
| 179 | + If the default value is passed, then `keepdims` will not be |
| 180 | + passed through to the `any` method of sub-classes of |
| 181 | + `ndarray`, however any non-default value will be. If the |
| 182 | + sub-class' method does not implement `keepdims` any |
| 183 | + exceptions will be raised. |
| 184 | +
|
| 185 | + Returns |
| 186 | + ------- |
| 187 | + any : bool or ndarray |
| 188 | + A new boolean or `ndarray` is returned unless `out` is specified, |
| 189 | + in which case a reference to `out` is returned. |
| 190 | +
|
| 191 | + See Also |
| 192 | + -------- |
| 193 | + ndarray.any : equivalent method |
| 194 | +
|
| 195 | + all : Test whether all elements along a given axis evaluate to True. |
| 196 | +
|
| 197 | + Notes |
| 198 | + ----- |
| 199 | + Not a Number (NaN), positive infinity and negative infinity evaluate |
| 200 | + to `True` because these are not equal to zero. |
| 201 | +
|
| 202 | + """ |
| 203 | + |
| 204 | + is_dparray1 = isinstance(in_array1, dparray) |
| 205 | + |
| 206 | + if (not use_origin_backend(in_array1) and is_dparray1): |
| 207 | + if axis is not None: |
| 208 | + checker_throw_value_error("any", "axis", type(axis), None) |
| 209 | + if out is not None: |
| 210 | + checker_throw_value_error("any", "out", type(out), None) |
| 211 | + if keepdims is not False: |
| 212 | + checker_throw_value_error("any", "keepdims", keepdims, False) |
| 213 | + |
| 214 | + result = dpnp_any(in_array1) |
| 215 | + |
| 216 | + # scalar returned |
| 217 | + if result.shape == (1,): |
| 218 | + return result.dtype.type(result[0]) |
| 219 | + |
| 220 | + return result |
| 221 | + |
| 222 | + return call_origin(numpy.any, axis, out, keepdims) |
| 223 | + |
| 224 | + |
68 | 225 | def equal(x1, x2):
|
69 | 226 | """
|
70 | 227 | Return (x1 == x2) element-wise.
|
|
0 commit comments