Skip to content

Commit 6e405d5

Browse files
committed
removed redudancy in code
1 parent 6ab34ef commit 6e405d5

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

numpy/linalg/linalg.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -940,20 +940,17 @@ def qr(a, mode='reduced'):
940940
# handle modes that don't return q
941941
if mode == 'r':
942942
r = triu(a[..., :mn, :])
943-
if t != result_t:
944-
r = r.astype(result_t, copy=False)
943+
r = r.astype(result_t, copy=False)
945944
return wrap(r)
946945

947946
if mode == 'raw':
948947
q = transpose(a)
949-
if t != result_t:
950-
q = q.astype(result_t, copy=False)
951-
tau = tau.astype(result_t, copy=False)
948+
q = q.astype(result_t, copy=False)
949+
tau = tau.astype(result_t, copy=False)
952950
return wrap(q), tau
953951

954952
if mode == 'economic':
955-
if t != result_t :
956-
a = a.astype(result_t, copy=False)
953+
a = a.astype(result_t, copy=False)
957954
return wrap(a)
958955

959956
# mc is the number of columns in the resulting q
@@ -962,25 +959,18 @@ def qr(a, mode='reduced'):
962959
# then it is the minimum of number of rows and columns.
963960
if mode == 'complete' and m > n:
964961
mc = m
965-
if m <= n:
966-
gufunc = _umath_linalg.qr_complete_m
967-
else:
968-
gufunc = _umath_linalg.qr_complete_n
962+
gufunc = _umath_linalg.qr_complete
969963
else:
970964
mc = mn
971-
if m <= n:
972-
gufunc = _umath_linalg.qr_reduced_m
973-
else:
974-
gufunc = _umath_linalg.qr_reduced_n
965+
gufunc = _umath_linalg.qr_reduced
975966

976967
signature = 'DD->D' if isComplexType(t) else 'dd->d'
977968
extobj = get_linalg_error_extobj(_raise_linalgerror_qr)
978969
q = gufunc(a, tau, signature=signature, extobj=extobj)
979970
r = triu(a[..., :mc, :])
980971

981-
if t != result_t:
982-
q = q.astype(result_t, copy=False)
983-
r = r.astype(result_t, copy=False)
972+
q = q.astype(result_t, copy=False)
973+
r = r.astype(result_t, copy=False)
984974

985975
return wrap(q), wrap(r)
986976

numpy/linalg/umath_linalg.c.src

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,6 +3973,10 @@ static void *array_of_nulls[] = {
39733973
CDOUBLE_ ## NAME \
39743974
}
39753975

3976+
/* The single precision functions are not used at all,
3977+
* due to input data being promoted to double precision
3978+
* in Python, so they are not implemented here.
3979+
*/
39763980
#define GUFUNC_FUNC_ARRAY_QR(NAME) \
39773981
static PyUFuncGenericFunction \
39783982
FUNC_ARRAY_NAME(NAME)[] = { \
@@ -4285,7 +4289,7 @@ GUFUNC_DESCRIPTOR_t gufunc_descriptors [] = {
42854289
"(m,n)->(m)",
42864290
"Compute TAU vector for the last two dimensions \n"\
42874291
"and broadcast to the rest. For m <= n. \n",
4288-
4, 1, 1,
4292+
2, 1, 1,
42894293
FUNC_ARRAY_NAME(qr_r_raw),
42904294
qr_r_raw_types
42914295
},
@@ -4294,43 +4298,25 @@ GUFUNC_DESCRIPTOR_t gufunc_descriptors [] = {
42944298
"(m,n)->(n)",
42954299
"Compute TAU vector for the last two dimensions \n"\
42964300
"and broadcast to the rest. For m > n. \n",
4297-
4, 1, 1,
4301+
2, 1, 1,
42984302
FUNC_ARRAY_NAME(qr_r_raw),
42994303
qr_r_raw_types
43004304
},
43014305
{
4302-
"qr_reduced_m",
4303-
"(m,n),(m)->(m,m)",
4304-
"Compute Q matrix for the last two dimensions \n"\
4305-
"and broadcast to the rest. For m <= n. \n",
4306-
4, 2, 1,
4307-
FUNC_ARRAY_NAME(qr_reduced),
4308-
qr_reduced_types
4309-
},
4310-
{
4311-
"qr_reduced_n",
4312-
"(m,n),(n)->(m,n)",
4306+
"qr_reduced",
4307+
"(m,n),(k)->(m,k)",
43134308
"Compute Q matrix for the last two dimensions \n"\
4314-
"and broadcast to the rest. For m > n. \n",
4315-
4, 2, 1,
4309+
"and broadcast to the rest. \n",
4310+
2, 2, 1,
43164311
FUNC_ARRAY_NAME(qr_reduced),
43174312
qr_reduced_types
43184313
},
43194314
{
4320-
"qr_complete_m",
4321-
"(m,n),(m)->(m,m)",
4322-
"Compute Q matrix for the last two dimensions \n"\
4323-
"and broadcast to the rest. For m <= n. \n",
4324-
4, 2, 1,
4325-
FUNC_ARRAY_NAME(qr_complete),
4326-
qr_complete_types
4327-
},
4328-
{
4329-
"qr_complete_n",
4315+
"qr_complete",
43304316
"(m,n),(n)->(m,m)",
43314317
"Compute Q matrix for the last two dimensions \n"\
43324318
"and broadcast to the rest. For m > n. \n",
4333-
4, 2, 1,
4319+
2, 2, 1,
43344320
FUNC_ARRAY_NAME(qr_complete),
43354321
qr_complete_types
43364322
},

0 commit comments

Comments
 (0)