MCPcopy Create free account
hub / github.com/numpy/numpy / _solve

Function _solve

numpy/array_api/linalg.py:303–329  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

301# To workaround this, the below is the code from np.linalg.solve except
302# only calling solve1 in the exactly 1D case.
303def _solve(a, b):
304 from ..linalg.linalg import (_makearray, _assert_stacked_2d,
305 _assert_stacked_square, _commonType,
306 isComplexType, get_linalg_error_extobj,
307 _raise_linalgerror_singular)
308 from ..linalg import _umath_linalg
309
310 a, _ = _makearray(a)
311 _assert_stacked_2d(a)
312 _assert_stacked_square(a)
313 b, wrap = _makearray(b)
314 t, result_t = _commonType(a, b)
315
316 # This part is different from np.linalg.solve
317 if b.ndim == 1:
318 gufunc = _umath_linalg.solve1
319 else:
320 gufunc = _umath_linalg.solve
321
322 # This does nothing currently but is left in because it will be relevant
323 # when complex dtype support is added to the spec in 2022.
324 signature = 'DD->D' if isComplexType(t) else 'dd->d'
325 with np.errstate(call=_raise_linalgerror_singular, invalid='call',
326 over='ignore', divide='ignore', under='ignore'):
327 r = gufunc(a, b, signature=signature)
328
329 return wrap(r.astype(result_t, copy=False))
330
331def solve(x1: Array, x2: Array, /) -> Array:
332 """

Callers 1

solveFunction · 0.85

Calls 7

_makearrayFunction · 0.85
_assert_stacked_2dFunction · 0.85
_assert_stacked_squareFunction · 0.85
_commonTypeFunction · 0.85
isComplexTypeFunction · 0.85
wrapFunction · 0.85
astypeMethod · 0.80

Tested by

no test coverage detected