20 #include <tensor/tensor.h>
21 #include <tensor/tensor_lapack.h>
22 #include <tensor/linalg.h>
26 using namespace lapack;
54 assert(A.
rank() == 2);
58 integer k = std::min(m, n);
59 integer lwork, ldu, lda, ldv, info;
61 cdouble *work, *u, *v, *a = tensor_pointer(A), foo;
62 double *rwork, *s = tensor_pointer(output);
63 char jobv[1], jobu[1];
66 *U =
CTensor(m, economic? k : m);
67 u = tensor_pointer(*U);
68 jobu[0] = economic?
'S' :
'A';
76 (*VT) =
CTensor(economic? k : n, n);
77 v = tensor_pointer(*VT);
78 jobv[0] = economic?
'S' :
'A';
79 ldv = economic? k : n;
86 #ifdef TENSOR_USE_ACML
87 zgesvd(*jobu, *jobv, m, n, a, m, s, u, ldu, v, ldv, &info);
91 rwork = (
double *)&foo;
92 F77NAME(zgesvd)(jobu, jobv, &m, &n, a, &m, s, u, &ldu, v, &ldv,
93 work, &lwork, rwork, &info);
94 lwork = lapack::real(work[0]);
95 work =
new cdouble[lwork];
96 rwork =
new double[5 * k];
97 F77NAME(zgesvd)(jobu, jobv, &m, &n, a, &m, s, u, &ldu, v, &ldv,
98 work, &lwork, rwork, &info);
int rank() const
Number of Tensor indices.
index columns() const
Query the size of 2nd index.
index rows() const
Query then size of 1st index.
Real Tensor with elements of type "double".
Complex Tensor with elements of type "cdouble".
RTensor svd(RTensor A, RTensor *pU=0, RTensor *pVT=0, bool economic=0)
Singular value decomposition of a real matrix.