|
38 | 38 |
|
39 | 39 |
|
40 | 40 | __all__ = [
|
41 |
| - "dpnp_divide" |
| 41 | + "dpnp_add", |
| 42 | + "dpnp_divide", |
| 43 | + "dpnp_multiply", |
| 44 | + "dpnp_subtract" |
42 | 45 | ]
|
43 | 46 |
|
44 | 47 |
|
| 48 | +_add_docstring_ = """ |
| 49 | +add(x1, x2, out=None, order='K') |
| 50 | +
|
| 51 | +Calculates the sum for each element `x1_i` of the input array `x1` with |
| 52 | +the respective element `x2_i` of the input array `x2`. |
| 53 | +
|
| 54 | +Args: |
| 55 | + x1 (dpnp.ndarray): |
| 56 | + First input array, expected to have numeric data type. |
| 57 | + x2 (dpnp.ndarray): |
| 58 | + Second input array, also expected to have numeric data type. |
| 59 | + out ({None, dpnp.ndarray}, optional): |
| 60 | + Output array to populate. |
| 61 | + Array have the correct shape and the expected data type. |
| 62 | + order ("C","F","A","K", None, optional): |
| 63 | + Memory layout of the newly output array, if parameter `out` is `None`. |
| 64 | + Default: "K". |
| 65 | +Returns: |
| 66 | + dpnp.ndarray: |
| 67 | + an array containing the result of element-wise division. The data type |
| 68 | + of the returned array is determined by the Type Promotion Rules. |
| 69 | +""" |
| 70 | + |
| 71 | +def dpnp_add(x1, x2, out=None, order='K'): |
| 72 | + """ |
| 73 | + Invokes add() from dpctl.tensor implementation for add() function. |
| 74 | + TODO: add a pybind11 extension of add() from OneMKL VM where possible |
| 75 | + and would be performance effective. |
| 76 | +
|
| 77 | + """ |
| 78 | + |
| 79 | + # dpctl.tensor only works with usm_ndarray or scalar |
| 80 | + x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1) |
| 81 | + x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2) |
| 82 | + out_usm = None if out is None else dpnp.get_usm_ndarray(out) |
| 83 | + |
| 84 | + func = BinaryElementwiseFunc("add", ti._add_result_type, ti._add, |
| 85 | + _add_docstring_, ti._add_inplace) |
| 86 | + res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order) |
| 87 | + return dpnp_array._create_from_usm_ndarray(res_usm) |
| 88 | + |
| 89 | + |
45 | 90 | _divide_docstring_ = """
|
46 | 91 | divide(x1, x2, out=None, order='K')
|
47 | 92 |
|
@@ -88,3 +133,87 @@ def _call_divide(src1, src2, dst, sycl_queue, depends=[]):
|
88 | 133 | func = BinaryElementwiseFunc("divide", ti._divide_result_type, _call_divide, _divide_docstring_)
|
89 | 134 | res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
|
90 | 135 | return dpnp_array._create_from_usm_ndarray(res_usm)
|
| 136 | + |
| 137 | + |
| 138 | +_multiply_docstring_ = """ |
| 139 | +multiply(x1, x2, out=None, order='K') |
| 140 | +
|
| 141 | +Calculates the product for each element `x1_i` of the input array `x1` |
| 142 | +with the respective element `x2_i` of the input array `x2`. |
| 143 | +
|
| 144 | +Args: |
| 145 | + x1 (dpnp.ndarray): |
| 146 | + First input array, expected to have numeric data type. |
| 147 | + x2 (dpnp.ndarray): |
| 148 | + Second input array, also expected to have numeric data type. |
| 149 | + out ({None, dpnp.ndarray}, optional): |
| 150 | + Output array to populate. |
| 151 | + Array have the correct shape and the expected data type. |
| 152 | + order ("C","F","A","K", None, optional): |
| 153 | + Memory layout of the newly output array, if parameter `out` is `None`. |
| 154 | + Default: "K". |
| 155 | +Returns: |
| 156 | + dpnp.ndarray: |
| 157 | + an array containing the result of element-wise division. The data type |
| 158 | + of the returned array is determined by the Type Promotion Rules. |
| 159 | +""" |
| 160 | + |
| 161 | +def dpnp_multiply(x1, x2, out=None, order='K'): |
| 162 | + """ |
| 163 | + Invokes multiply() from dpctl.tensor implementation for multiply() function. |
| 164 | + TODO: add a pybind11 extension of mul() from OneMKL VM where possible |
| 165 | + and would be performance effective. |
| 166 | +
|
| 167 | + """ |
| 168 | + |
| 169 | + # dpctl.tensor only works with usm_ndarray or scalar |
| 170 | + x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1) |
| 171 | + x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2) |
| 172 | + out_usm = None if out is None else dpnp.get_usm_ndarray(out) |
| 173 | + |
| 174 | + func = BinaryElementwiseFunc("multiply", ti._multiply_result_type, ti._multiply, |
| 175 | + _multiply_docstring_, ti._multiply_inplace) |
| 176 | + res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order) |
| 177 | + return dpnp_array._create_from_usm_ndarray(res_usm) |
| 178 | + |
| 179 | + |
| 180 | +_subtract_docstring_ = """ |
| 181 | +subtract(x1, x2, out=None, order='K') |
| 182 | +
|
| 183 | +Calculates the difference bewteen each element `x1_i` of the input |
| 184 | +array `x1` and the respective element `x2_i` of the input array `x2`. |
| 185 | +
|
| 186 | +Args: |
| 187 | + x1 (dpnp.ndarray): |
| 188 | + First input array, expected to have numeric data type. |
| 189 | + x2 (dpnp.ndarray): |
| 190 | + Second input array, also expected to have numeric data type. |
| 191 | + out ({None, dpnp.ndarray}, optional): |
| 192 | + Output array to populate. |
| 193 | + Array have the correct shape and the expected data type. |
| 194 | + order ("C","F","A","K", None, optional): |
| 195 | + Memory layout of the newly output array, if parameter `out` is `None`. |
| 196 | + Default: "K". |
| 197 | +Returns: |
| 198 | + dpnp.ndarray: |
| 199 | + an array containing the result of element-wise division. The data type |
| 200 | + of the returned array is determined by the Type Promotion Rules. |
| 201 | +""" |
| 202 | + |
| 203 | +def dpnp_subtract(x1, x2, out=None, order='K'): |
| 204 | + """ |
| 205 | + Invokes subtract() from dpctl.tensor implementation for subtract() function. |
| 206 | + TODO: add a pybind11 extension of sub() from OneMKL VM where possible |
| 207 | + and would be performance effective. |
| 208 | +
|
| 209 | + """ |
| 210 | + |
| 211 | + # dpctl.tensor only works with usm_ndarray or scalar |
| 212 | + x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1) |
| 213 | + x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2) |
| 214 | + out_usm = None if out is None else dpnp.get_usm_ndarray(out) |
| 215 | + |
| 216 | + func = BinaryElementwiseFunc("subtract", ti._subtract_result_type, ti._subtract, |
| 217 | + _subtract_docstring_, ti._subtract_inplace) |
| 218 | + res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order) |
| 219 | + return dpnp_array._create_from_usm_ndarray(res_usm) |
0 commit comments