8000 MAINT: use copy=False in a few astype() calls by argriffing · Pull Request #5909 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: use copy=False in a few astype() calls #5909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MAINT: conditional copy=False in some astype calls
  • Loading branch information
alexbrc committed May 22, 2015
commit 1ff2be174f86ebca2e7a006012bcc5744ace2f6e
20 changes: 16 additions & 4 deletions numpy/linalg/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
csingle, cdouble, inexact, complexfloating, newaxis, ravel, all, Inf, dot,
add, multiply, sqrt, maximum, fastCopyAndTranspose, sum, isfinite, size,
finfo, errstate, geterrobj, longdouble, rollaxis, amin, amax, product, abs,
broadcast, atleast_2d, intp, asanyarray
broadcast, atleast_2d, intp, asanyarray, isscalar
)
from numpy.lib import triu, asfarray
from numpy.linalg import lapack_lite, _umath_linalg
Expand Down Expand Up @@ -782,7 +782,7 @@ def qr(a, mode='reduced'):

if mode == 'economic':
if t != result_t :
a = a.astype(result_t)
a = a.astype(result_t, copy=False)
return wrap(a.T)

# generate q from a
Expand Down Expand Up @@ -1696,7 +1696,15 @@ def slogdet(a):
real_t = _realType(result_t)
signature = 'D->Dd' if isComplexType(t) else 'd->dd'
sign, logdet = _umath_linalg.slogdet(a, signature=signature)
return sign.astype(result_t), logdet.astype(real_t)
if isscalar(sign):
sign = sign.astype(result_t)
else:
sign = sign.astype(result_t, copy=False)
if isscalar(logdet):
logdet = logdet.astype(real_t)
else:
logdet = logdet.astype(real_t, copy=False)
return sign, logdet

def det(a):
"""
Expand Down Expand Up @@ -1751,7 +1759,11 @@ def det(a):
t, result_t = _commonType(a)
signature = 'D->D' if isComplexType(t) else 'd->d'
r = _umath_linalg.det(a, signature=signature)
return r.astype(result_t)
if isscalar(r):
r = r.astype(result_t)
else:
r = r.astype(result_t, copy=False)
return r

# Linear Least Squares

Expand Down
0