|
55 | 55 | "einsum_path", |
56 | 56 | "inner", |
57 | 57 | "kron", |
| 58 | + "matmul", |
58 | 59 | "outer", |
59 | 60 | "tensordot", |
60 | 61 | "vdot" |
@@ -220,6 +221,70 @@ def kron(a, b): |
220 | 221 | return call_origin(numpy.kron, a, b) |
221 | 222 |
|
222 | 223 |
|
| 224 | +def matmul(in_array1, in_array2, out=None, **kwargs): |
| 225 | + """ |
| 226 | + Matrix product of two arrays. |
| 227 | +
|
| 228 | + For full documentation refer to :obj:`numpy.matmul`. |
| 229 | +
|
| 230 | + Limitations |
| 231 | + ----------- |
| 232 | + Input arrays are supported as :obj:`dpnp.ndarray`. |
| 233 | + Otherwise the function will be executed sequentially on CPU. |
| 234 | + Parameter ``out`` is supported as :obj:`dpnp.ndarray` and as default value ``None``. |
| 235 | + Input array data types are limited by supported DPNP :ref:`Data types`. |
| 236 | +
|
| 237 | + See Also |
| 238 | + -------- |
| 239 | + :obj:`dpnp.vdot` : Complex-conjugating dot product. |
| 240 | + :obj:`dpnp.tensordot` : Sum products over arbitrary axes. |
| 241 | + :obj:`dpnp.einsum` : Einstein summation convention. |
| 242 | + :obj:`dpnp.dot` : Alternative matrix product with |
| 243 | + different broadcasting rules. |
| 244 | +
|
| 245 | + Examples |
| 246 | + -------- |
| 247 | + >>> import dpnp as np |
| 248 | + >>> a = np.ones([9, 5, 7, 4]) |
| 249 | + >>> c = np.ones([9, 5, 4, 3]) |
| 250 | + >>> np.matmul(a, c).shape |
| 251 | + (9, 5, 7, 3) |
| 252 | + >>> a = np.array([[1, 0], [0, 1]]) |
| 253 | + >>> b = np.array([[4, 1], [2, 2]]) |
| 254 | + >>> np.matmul(a, b) |
| 255 | + array([[4, 1], |
| 256 | + [2, 2]]) |
| 257 | +
|
| 258 | + """ |
| 259 | + |
| 260 | + if not use_origin_backend(in_array1) and not kwargs: |
| 261 | + if not isinstance(in_array1, dparray): |
| 262 | + pass |
| 263 | + elif not isinstance(in_array2, dparray): |
| 264 | + pass |
| 265 | + elif out is not None and not isinstance(out, dparray): |
| 266 | + pass |
| 267 | + else: |
| 268 | + """ |
| 269 | + Cost model checks |
| 270 | + """ |
| 271 | + |
| 272 | + dparray1_size = in_array1.size |
| 273 | + dparray2_size = in_array2.size |
| 274 | + cost_size = 4096 # 2D array shape(64, 64) |
| 275 | + |
| 276 | + if ((in_array1.dtype == numpy.float64) or (in_array1.dtype == numpy.float32)): |
| 277 | + """ |
| 278 | + Floating point types are handled via original math library better than SYCL math library |
| 279 | + """ |
| 280 | + cost_size = 262144 # 2D array shape(512, 512) |
| 281 | + |
| 282 | + if (dparray1_size > cost_size) and (dparray2_size > cost_size): |
| 283 | + return dpnp_matmul(in_array1, in_array2, out=out) |
| 284 | + |
| 285 | + return call_origin(numpy.matmul, in_array1, in_array2, out=out, **kwargs) |
| 286 | + |
| 287 | + |
223 | 288 | def outer(x1, x2, **kwargs): |
224 | 289 | """ |
225 | 290 | Returns the outer product of two arrays. |
|
0 commit comments