Skip to content

Commit 9631d9b

Browse files
authored
Move matmul to linalg py module (#736)
1 parent 4411a82 commit 9631d9b

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

dpnp/dpnp_iface.py

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
"dpnp_queue_initialize",
5858
"dpnp_queue_is_cpu",
5959
"get_dpnp_descriptor",
60-
"get_include",
61-
"matmul"
60+
"get_include"
6261
]
6362

6463
from dpnp.dpnp_iface_arraycreation import *
@@ -169,67 +168,3 @@ def get_include():
169168
dpnp_path = os.path.join(os.path.dirname(__file__), "backend", "include")
170169

171170
return dpnp_path
172-
173-
174-
def matmul(in_array1, in_array2, out=None, **kwargs):
175-
"""
176-
Matrix product of two arrays.
177-
178-
For full documentation refer to :obj:`numpy.matmul`.
179-
180-
Limitations
181-
-----------
182-
Input arrays are supported as :obj:`dpnp.ndarray`.
183-
Otherwise the function will be executed sequentially on CPU.
184-
Parameter ``out`` is supported as :obj:`dpnp.ndarray` and as default value ``None``.
185-
Input array data types are limited by supported DPNP :ref:`Data types`.
186-
187-
See Also
188-
--------
189-
:obj:`dpnp.vdot` : Complex-conjugating dot product.
190-
:obj:`dpnp.tensordot` : Sum products over arbitrary axes.
191-
:obj:`dpnp.einsum` : Einstein summation convention.
192-
:obj:`dpnp.dot` : Alternative matrix product with
193-
different broadcasting rules.
194-
195-
Examples
196-
--------
197-
>>> import dpnp as np
198-
>>> a = np.ones([9, 5, 7, 4])
199-
>>> c = np.ones([9, 5, 4, 3])
200-
>>> np.matmul(a, c).shape
201-
(9, 5, 7, 3)
202-
>>> a = np.array([[1, 0], [0, 1]])
203-
>>> b = np.array([[4, 1], [2, 2]])
204-
>>> np.matmul(a, b)
205-
array([[4, 1],
206-
[2, 2]])
207-
208-
"""
209-
210-
if not use_origin_backend(in_array1) and not kwargs:
211-
if not isinstance(in_array1, dparray):
212-
pass
213-
elif not isinstance(in_array2, dparray):
214-
pass
215-
elif out is not None and not isinstance(out, dparray):
216-
pass
217-
else:
218-
"""
219-
Cost model checks
220-
"""
221-
222-
dparray1_size = in_array1.size
223-
dparray2_size = in_array2.size
224-
cost_size = 4096 # 2D array shape(64, 64)
225-
226-
if ((in_array1.dtype == numpy.float64) or (in_array1.dtype == numpy.float32)):
227-
"""
228-
Floating point types are handled via original math library better than SYCL math library
229-
"""
230-
cost_size = 262144 # 2D array shape(512, 512)
231-
232-
if (dparray1_size > cost_size) and (dparray2_size > cost_size):
233-
return dpnp_matmul(in_array1, in_array2, out=out)
234-
235-
return call_origin(numpy.matmul, in_array1, in_array2, out=out, **kwargs)

dpnp/dpnp_iface_linearalgebra.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"einsum_path",
5656
"inner",
5757
"kron",
58+
"matmul",
5859
"outer",
5960
"tensordot",
6061
"vdot"
@@ -220,6 +221,70 @@ def kron(a, b):
220221
return call_origin(numpy.kron, a, b)
221222

222223

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+
223288
def outer(x1, x2, **kwargs):
224289
"""
225290
Returns the outer product of two arrays.

0 commit comments

Comments
 (0)