26 #if defined (HAVE_CONFIG_H)
50 #if defined (HAVE_ARPACK)
89 catch (octave::execution_exception& ee)
94 if (tmp.
length () && tmp(0).is_defined ())
98 warning (
"eigs: ignoring imaginary part returned from user-supplied function");
102 retval = tmp(0).xvector_value (
"eigs: evaluation of user-supplied function failed");
130 catch (octave::execution_exception& ee)
135 if (tmp.
length () && tmp(0).is_defined ())
137 retval = tmp(0).xcomplex_vector_value (
"eigs: evaluation of user-supplied function failed");
151 DEFMETHOD (__eigs__, interp, args, nargout,
176 #if defined (HAVE_ARPACK)
178 int nargin = args.length ();
185 std::string fcn_name;
189 double sigmar, sigmai;
190 bool have_sigma =
false;
191 std::string typ =
"LM";
198 bool have_a_fcn =
false;
199 bool a_is_complex =
false;
200 bool b_is_complex =
false;
201 bool symmetric =
false;
202 bool sym_tested =
false;
204 bool a_is_sparse =
false;
205 bool b_is_sparse =
false;
208 double tol = std::numeric_limits<double>::epsilon ();
222 error (
"eigs: invalid recursive call");
224 if (args(0).is_function_handle () || args(0).is_inline_function ()
225 || args(0).is_string ())
230 error (
"eigs: unknown function");
233 error (
"eigs: incorrect number of arguments");
235 n = args(1).nint_value ();
241 if (args(0).iscomplex ())
243 if (args(0).issparse ())
245 ascm = (args(0).sparse_complex_matrix_value ());
249 acm = (args(0).complex_matrix_value ());
254 if (args(0).issparse ())
256 asmm = (args(0).sparse_matrix_value ());
261 amm = (args(0).matrix_value ());
268 if (nargin > 1 + arg_offset
269 && ! (args(1 + arg_offset).is_real_scalar ()))
271 if (args(1+arg_offset).iscomplex ())
273 b_arg = 1+arg_offset;
274 if (args(b_arg).issparse ())
276 bscm = (args(b_arg).sparse_complex_matrix_value ());
280 bcm = (args(b_arg).complex_matrix_value ());
287 b_arg = 1+arg_offset;
288 if (args(b_arg).issparse ())
290 bsmm = (args(b_arg).sparse_matrix_value ());
294 bmm = (args(b_arg).matrix_value ());
300 if (nargin > (1+arg_offset))
301 k = args(1+arg_offset).nint_value ();
303 if (nargin > (2+arg_offset))
305 if (args(2+arg_offset).is_string ())
307 typ = args(2+arg_offset).string_value ();
310 transform (typ.begin (), typ.end (), typ.begin (), toupper);
316 sigma = args(2+arg_offset).xcomplex_value (
"eigs: SIGMA must be a scalar or a string");
322 sigmar = sigma.real ();
323 sigmai = sigma.imag ();
325 if (nargin > (3+arg_offset))
327 if (! args(3+arg_offset).isstruct ())
328 error (
"eigs: OPTS argument must be a structure");
331 +arg_offset).xscalar_map_value (
"eigs: OPTS argument must be a scalar structure");
339 if (tmp.
numel () != 1)
340 error (
"eigs: OPTS.issym must be a scalar value");
342 symmetric = tmp.
xbool_value (
"eigs: OPTS.issym must be a logical value");
352 if (tmp.
numel () != 1)
353 error (
"eigs: OPTS.isreal must be a scalar value");
355 a_is_complex = ! tmp.
xbool_value (
"eigs: OPTS.isreal must be a logical value");
374 if (a_is_complex || b_is_complex)
387 if (tmp.
numel () != 1)
388 error (
"eigs: OPTS.cholB must be a scalar value");
390 cholB = tmp.
xbool_value (
"eigs: OPTS.cholB must be a logical value");
398 if (nargin > (4+arg_offset))
399 error (
"eigs: incorrect number of arguments");
402 if (! sym_tested && ! have_a_fcn)
422 if (a_is_complex || b_is_complex)
425 bscm = args(b_arg).sparse_complex_matrix_value ();
427 bcm = args(b_arg).complex_matrix_value ();
432 bsmm = args(b_arg).sparse_matrix_value ();
434 bmm = args(b_arg).matrix_value ();
440 if (! have_sigma && typ ==
"SM")
444 if (a_is_complex || b_is_complex)
460 (eigs_complex_fcn,
n, typ, sigma, k, p, info, eig_vec,
462 (nargout > 1), cholB, disp, maxit);
465 (eigs_complex_fcn,
n, typ, sigma, k, p, info, eig_vec,
467 (nargout > 1), cholB, disp, maxit);
473 (ascm, sigma, k, p, info, eig_vec, eig_val, bscm, permB,
478 (acm, sigma, k, p, info, eig_vec, eig_val, bcm, permB,
486 (ascm, typ, k, p, info, eig_vec, eig_val, bscm, permB,
491 (acm, typ, k, p, info, eig_vec, eig_val, bcm, permB,
499 retval(0) =
real (eig_val);
511 else if (sigmai != 0.0)
528 (eigs_complex_fcn,
n, typ, sigma, k, p, info, eig_vec,
530 (nargout > 1), cholB, disp, maxit);
533 (eigs_complex_fcn,
n, typ, sigma, k, p, info, eig_vec,
535 (nargout > 1), cholB, disp, maxit);
554 retval(0) =
real (eig_val);
582 (eigs_fcn,
n, typ, sigmar, k, p, info, eig_vec,
584 (nargout > 1), cholB, disp, maxit);
587 (eigs_fcn,
n, typ, sigmar, k, p, info, eig_vec,
589 (nargout > 1), cholB, disp, maxit);
595 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm,
600 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm,
608 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm,
613 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB,
632 (eigs_fcn,
n, typ, sigmar, k, p, info, eig_vec,
634 (nargout > 1), cholB, disp, maxit);
637 (eigs_fcn,
n, typ, sigmar, k, p, info, eig_vec,
639 (nargout > 1), cholB, disp, maxit);
645 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm,
650 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm,
658 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm,
663 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB,
677 "eigs: None of the %" OCTAVE_IDX_TYPE_FORMAT
678 " requested eigenvalues converged", k);
681 "eigs: Only %" OCTAVE_IDX_TYPE_FORMAT
682 " of the %" OCTAVE_IDX_TYPE_FORMAT
683 " requested eigenvalues converged",
686 if (! fcn_name.empty ())
697 octave_unused_parameter (interp);
698 octave_unused_parameter (args);
699 octave_unused_parameter (nargout);
OCTAVE_API bool ishermitian(void) const
OCTAVE_API bool issymmetric(void) const
OCTAVE_API bool ishermitian(void) const
OCTAVE_API bool issymmetric(void) const
octave_value getfield(const std::string &key) const
octave_idx_type length(void) const
OCTINTERP_API Array< Complex > complex_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type numel(void) const
bool is_defined(void) const
int nint_value(bool frc_str_conv=false) const
OCTINTERP_API bool xbool_value(const char *fmt,...) const
bool is_undefined(void) const
OCTINTERP_API Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double double_value(bool frc_str_conv=false) const
void clear_function(const std::string &name)
ColumnVector real(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
octave_idx_type EigsRealNonSymmetricMatrixShift(const M &m, double sigmar, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsRealSymmetricMatrixShift(const M &m, double sigma, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsRealNonSymmetricMatrix(const M &m, const std::string typ, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsComplexNonSymmetricMatrix(const M &m, const std::string typ, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ComplexColumnVector &cresid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsRealSymmetricFunc(EigsFunc fcn, octave_idx_type n_arg, const std::string &_typ, double sigma, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsRealNonSymmetricFunc(EigsFunc fcn, octave_idx_type n_arg, const std::string &_typ, double sigmar, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsComplexNonSymmetricMatrixShift(const M &m, Complex sigma, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ComplexColumnVector &cresid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsRealSymmetricMatrix(const M &m, const std::string typ, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, Matrix &eig_vec, ColumnVector &eig_val, const M &_b, ColumnVector &permB, ColumnVector &resid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
octave_idx_type EigsComplexNonSymmetricFunc(EigsComplexFunc fcn, octave_idx_type n_arg, const std::string &_typ, Complex sigma, octave_idx_type k_arg, octave_idx_type p_arg, octave_idx_type &info, ComplexMatrix &eig_vec, ComplexColumnVector &eig_val, const M &_b, ColumnVector &permB, ComplexColumnVector &cresid, std::ostream &os, double tol, bool rvec, bool cholB, int disp, int maxit)
std::function< ColumnVector(const ColumnVector &x, int &eigs_error)> EigsFunc
std::function< ComplexColumnVector(const ComplexColumnVector &x, int &eigs_error)> EigsComplexFunc
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
void err_user_supplied_eval(const char *name)
ColumnVector transform(const Matrix &m, double x, double y, double z)
octave_value get_function_handle(interpreter &interp, const octave_value &arg, const std::string ¶meter_name)
F77_RET_T const F77_DBLE * x
class OCTAVE_API ComplexColumnVector
class OCTAVE_API ColumnVector
std::complex< double > Complex
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
ComplexColumnVector eigs_complex_func(const ComplexColumnVector &x, int &eigs_error)
ColumnVector eigs_func(const ColumnVector &x, int &eigs_error)