31 #include <unordered_map>
47 static std::unordered_map<std::
string,
void *>
gsvd_fcn;
53 #define xSTRINGIZE(x) #x
54 #define STRINGIZE(x) xSTRINGIZE(x)
63 (*current_liboctave_error_handler)
64 (
"gsvd: unable to query LAPACK library");
156 template<
class T1,
class T2>
189 template<
class T1,
class T2>
239 double *tmp_dataA,
F77_INT m1,
double *tmp_dataB,
251 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
252 F77_CONST_CHAR_ARG2 (&jobv, 1),
253 F77_CONST_CHAR_ARG2 (&jobq, 1),
254 m,
n, p, k, l, tmp_dataA, m1, tmp_dataB, p1,
256 u, nrow_u, v, nrow_v, q, nrow_q,
257 work, lwork, iwork, info
260 F77_CHAR_ARG_LEN (1));
265 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
266 F77_CONST_CHAR_ARG2 (&jobv, 1),
267 F77_CONST_CHAR_ARG2 (&jobq, 1),
268 m,
n, p, k, l, tmp_dataA, m1, tmp_dataB, p1,
270 u, nrow_u, v, nrow_v, q, nrow_q,
274 F77_CHAR_ARG_LEN (1));
282 float *tmp_dataA,
F77_INT m1,
float *tmp_dataB,
285 float *v,
F77_INT nrow_v,
float *q,
295 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
296 F77_CONST_CHAR_ARG2 (&jobv, 1),
297 F77_CONST_CHAR_ARG2 (&jobq, 1),
298 m,
n, p, k, l, tmp_dataA, m1, tmp_dataB, p1,
300 u, nrow_u, v, nrow_v, q, nrow_q,
301 work, lwork, iwork, info
304 F77_CHAR_ARG_LEN (1));
309 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
310 F77_CONST_CHAR_ARG2 (&jobv, 1),
311 F77_CONST_CHAR_ARG2 (&jobq, 1),
312 m,
n, p, k, l, tmp_dataA, m1, tmp_dataB, p1,
314 u, nrow_u, v, nrow_v, q, nrow_q,
318 F77_CHAR_ARG_LEN (1));
341 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
342 F77_CONST_CHAR_ARG2 (&jobv, 1),
343 F77_CONST_CHAR_ARG2 (&jobq, 1),
352 lwork, rwork, iwork, info
355 F77_CHAR_ARG_LEN (1));
360 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
361 F77_CONST_CHAR_ARG2 (&jobv, 1),
362 F77_CONST_CHAR_ARG2 (&jobq, 1),
374 F77_CHAR_ARG_LEN (1));
400 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
401 F77_CONST_CHAR_ARG2 (&jobv, 1),
402 F77_CONST_CHAR_ARG2 (&jobq, 1),
414 F77_CHAR_ARG_LEN (1));
419 f_ptr (F77_CONST_CHAR_ARG2 (&jobu, 1),
420 F77_CONST_CHAR_ARG2 (&jobv, 1),
421 F77_CONST_CHAR_ARG2 (&jobq, 1),
433 F77_CHAR_ARG_LEN (1));
437 template <
typename T>
442 (*current_liboctave_error_handler)
443 (
"gsvd: U not computed because type == gsvd::sigma_only");
448 template <
typename T>
453 (*current_liboctave_error_handler)
454 (
"gsvd: V not computed because type == gsvd::sigma_only");
459 template <
typename T>
464 (*current_liboctave_error_handler)
465 (
"gsvd: X not computed because type == gsvd::sigma_only");
470 template <
typename T>
473 if (a.isempty () || b.isempty ())
474 (*current_liboctave_error_handler)
475 (
"gsvd: A and B cannot be empty matrices");
481 F77_INT p = to_f77_int (b.rows ());
484 P *tmp_dataA = atmp.fortran_vec ();
487 P *tmp_dataB = btmp.fortran_vec ();
512 jobu = jobv = jobq =
'N';
513 nrow_u = nrow_v = nrow_q = 1;
523 m_left_smA.resize (nrow_u,
m);
525 P *u = m_left_smA.fortran_vec ();
528 m_left_smB.resize (nrow_v, p);
530 P *v = m_left_smB.fortran_vec ();
533 m_right_sm.resize (nrow_q,
n);
535 P *q = m_right_sm.fortran_vec ();
552 tmp_dataA,
m, tmp_dataB, p,
553 alpha, beta, u, nrow_u, v, nrow_v, q, nrow_q,
554 &work_tmp, lwork, iwork, info);
567 tmp_dataA,
m, tmp_dataB, p,
568 alpha, beta, u, nrow_u, v, nrow_v, q, nrow_q,
569 work, lwork, iwork, info);
572 (*current_liboctave_error_handler)
573 (
"*ggsvd.f: argument %" OCTAVE_F77_INT_TYPE_FORMAT
" illegal",
577 (*current_liboctave_error_handler)
578 (
"*ggsvd.f: Jacobi-type procedure failed to converge");
591 for (i = 0; i < k+l; i++)
592 for (j = 0; j < k+l; j++)
593 R.xelem (i, j) = atmp.xelem (i, astart + j);
599 for (i = 0; i <
m; i++)
600 for (j = 0; j < k+l; j++)
601 R.xelem (i, j) = atmp.xelem (i, astart + j);
603 for (i =
m; i < k + l; i++)
604 for (j =
n - l - k +
m; j <
n; j++)
605 R.xelem (i, j) = btmp.xelem (i - k, j);
611 m_right_sm = m_right_sm * R.hermitian ();
631 m_sigmaA.resize (k+l, 1);
632 m_sigmaB.resize (k+l, 1);
636 for (i = 0; i < k; i++)
638 m_sigmaA.xelem (i) = 1.0;
639 m_sigmaB.xelem (i) = 0.0;
641 for (i = k, j = k+l-1; i < k+l; i++, j--)
643 m_sigmaA.xelem (i) = alpha.xelem (i);
644 m_sigmaB.xelem (i) = beta.xelem (i);
649 for (i = 0; i < k; i++)
651 m_sigmaA.xelem (i) = 1.0;
652 m_sigmaB.xelem (i) = 0.0;
654 for (i = k; i <
m; i++)
656 m_sigmaA.xelem (i) = alpha.xelem (i);
657 m_sigmaB.xelem (i) = beta.xelem (i);
659 for (i =
m; i < k+l; i++)
661 m_sigmaA.xelem (i) = 0.0;
662 m_sigmaB.xelem (i) = 1.0;
670 m_sigmaA.resize (
m,
n);
671 m_sigmaB.resize (p,
n);
673 for (i = 0; i < k; i++)
674 m_sigmaA.xelem (i, i) = 1.0;
676 for (i = 0; i < rank; i++)
678 m_sigmaA.xelem (k+i, k+i) = alpha.xelem (k+i);
679 m_sigmaB.xelem (i, k+i) = beta.xelem (k+i);
684 for (i =
m; i <
n; i++)
685 m_sigmaB.xelem (i-k, i) = 1.0;
charNDArray max(char d, const charNDArray &m)
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
void * search(const std::string &nm, const name_mangler &mangler=name_mangler()) const
void ggsvd(char &jobu, char &jobv, char &jobq, octave_f77_int_type m, octave_f77_int_type n, octave_f77_int_type p, octave_f77_int_type &k, octave_f77_int_type &l, P *tmp_dataA, octave_f77_int_type m1, P *tmp_dataB, octave_f77_int_type p1, real_matrix &alpha, real_matrix &beta, P *u, octave_f77_int_type nrow_u, P *v, octave_f77_int_type nrow_v, P *q, octave_f77_int_type nrow_q, P *work, octave_f77_int_type lwork, octave_f77_int_type *iwork, octave_f77_int_type &info)
T right_singular_matrix(void) const
T::real_matrix_type real_matrix
T left_singular_matrix_A(void) const
T left_singular_matrix_B(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define F77_DBLE_CMPLX_ARG(x)
octave_f77_int_type F77_INT
static math::gsvd< T >::Type gsvd_type(int nargout, int nargin)
static std::unordered_map< std::string, void * > gsvd_fcn
comp_ggsvd3_ptr< F77_DBLE_CMPLX, F77_DBLE >::type zggsvd3_type
comp_ggsvd_ptr< F77_CMPLX, F77_REAL >::type cggsvd_type
real_ggsvd_ptr< F77_DBLE >::type dggsvd_type
comp_ggsvd3_ptr< F77_CMPLX, F77_REAL >::type cggsvd3_type
real_ggsvd3_ptr< F77_REAL >::type sggsvd3_type
static void initialize_gsvd(void)
real_ggsvd3_ptr< F77_DBLE >::type dggsvd3_type
comp_ggsvd_ptr< F77_DBLE_CMPLX, F77_DBLE >::type zggsvd_type
real_ggsvd_ptr< F77_REAL >::type sggsvd_type
static bool gsvd_initialized
F77_RET_T F77_CONST_CHAR_ARG_DECL
F77_RET_T const F77_INT F77_INT const F77_DBLE F77_DBLE const F77_INT F77_DBLE const F77_INT F77_INT F77_INT F77_DBLE F77_DBLE const F77_INT F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL
F77_RET_T(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_DBLE *, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
F77_RET_T(* type)(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T2 *, T2 *, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T2 *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T(* type)(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T2 *, T2 *, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, T2 *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T(* type)(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, T1 *, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T(* type)(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, T1 *, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, const F77_INT &, T1 *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg