26 #if defined (HAVE_CONFIG_H)
48 #if defined (HAVE_ARPACK)
74 catch (octave::execution_exception& e)
79 if (tmp.
length () && tmp(0).is_defined ())
83 warning (
"eigs: ignoring imaginary part returned from user-supplied function");
87 retval = tmp(0).xvector_value (
"eigs: evaluation of user-supplied function failed");
114 catch (octave::execution_exception& e)
119 if (tmp.
length () && tmp(0).is_defined ())
121 retval = tmp(0).xcomplex_vector_value (
"eigs: evaluation of user-supplied function failed");
135 DEFMETHOD (__eigs__, interp, args, nargout,
160 #if defined (HAVE_ARPACK)
162 int nargin = args.length ();
169 std::string fcn_name;
173 double sigmar, sigmai;
174 bool have_sigma =
false;
175 std::string typ =
"LM";
182 bool have_a_fun =
false;
183 bool a_is_complex =
false;
184 bool b_is_complex =
false;
185 bool symmetric =
false;
186 bool sym_tested =
false;
188 bool a_is_sparse =
false;
189 bool b_is_sparse =
false;
192 double tol = std::numeric_limits<double>::epsilon ();
208 error (
"eigs: invalid recursive call");
210 if (args(0).is_function_handle () || args(0).is_inline_function ()
211 || args(0).is_string ())
216 error (
"eigs: unknown function");
219 error (
"eigs: incorrect number of arguments");
221 n = args(1).nint_value ();
227 if (args(0).iscomplex ())
229 if (args(0).issparse ())
231 ascm = (args(0).sparse_complex_matrix_value ());
235 acm = (args(0).complex_matrix_value ());
240 if (args(0).issparse ())
242 asmm = (args(0).sparse_matrix_value ());
247 amm = (args(0).matrix_value ());
254 if (nargin > 1 + arg_offset
255 && ! (args(1 + arg_offset).is_real_scalar ()))
257 if (args(1+arg_offset).iscomplex ())
259 b_arg = 1+arg_offset;
260 if (args(b_arg).issparse ())
262 bscm = (args(b_arg).sparse_complex_matrix_value ());
266 bcm = (args(b_arg).complex_matrix_value ());
273 b_arg = 1+arg_offset;
274 if (args(b_arg).issparse ())
276 bsmm = (args(b_arg).sparse_matrix_value ());
280 bmm = (args(b_arg).matrix_value ());
286 if (nargin > (1+arg_offset))
287 k = args(1+arg_offset).nint_value ();
289 if (nargin > (2+arg_offset))
291 if (args(2+arg_offset).is_string ())
293 typ = args(2+arg_offset).string_value ();
296 transform (typ.begin (), typ.end (), typ.begin (), toupper);
302 sigma = args(2+arg_offset).xcomplex_value (
"eigs: SIGMA must be a scalar or a string");
308 sigmar = sigma.real ();
309 sigmai = sigma.imag ();
311 if (nargin > (3+arg_offset))
313 if (! args(3+arg_offset).isstruct ())
314 error (
"eigs: OPTS argument must be a structure");
316 octave_scalar_map map = args(3+arg_offset).xscalar_map_value (
"eigs: OPTS argument must be a scalar structure");
324 if (tmp.
numel () != 1)
325 error (
"eigs: OPTS.issym must be a scalar value");
327 symmetric = tmp.
xbool_value (
"eigs: OPTS.issym must be a logical value");
337 if (tmp.
numel () != 1)
338 error (
"eigs: OPTS.isreal must be a scalar value");
340 a_is_complex = ! tmp.
xbool_value (
"eigs: OPTS.isreal must be a logical value");
359 if (a_is_complex || b_is_complex)
372 if (tmp.
numel () != 1)
373 error (
"eigs: OPTS.cholB must be a scalar value");
375 cholB = tmp.
xbool_value (
"eigs: OPTS.cholB must be a logical value");
383 if (nargin > (4+arg_offset))
384 error (
"eigs: incorrect number of arguments");
387 if (! sym_tested && ! have_a_fun)
407 if (a_is_complex || b_is_complex)
410 bscm = args(b_arg).sparse_complex_matrix_value ();
412 bcm = args(b_arg).complex_matrix_value ();
417 bsmm = args(b_arg).sparse_matrix_value ();
419 bmm = args(b_arg).matrix_value ();
425 if (! have_sigma && typ ==
"SM")
429 if (a_is_complex || b_is_complex)
440 (nargout > 1), cholB, disp, maxit);
445 (nargout > 1), cholB, disp, maxit);
451 (ascm, sigma, k, p, info, eig_vec, eig_val, bscm, permB,
456 (acm, sigma, k, p, info, eig_vec, eig_val, bcm, permB,
464 (ascm, typ, k, p, info, eig_vec, eig_val, bscm, permB,
469 (acm, typ, k, p, info, eig_vec, eig_val, bcm, permB,
489 else if (sigmai != 0.0)
501 (nargout > 1), cholB, disp, maxit);
506 (nargout > 1), cholB, disp, maxit);
548 (
eigs_func,
n, typ, sigmar, k, p, info, eig_vec,
550 (nargout > 1), cholB, disp, maxit);
553 (
eigs_func,
n, typ, sigmar, k, p, info, eig_vec,
555 (nargout > 1), cholB, disp, maxit);
561 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm,
566 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm,
574 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm,
579 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB,
598 (
eigs_func,
n, typ, sigmar, k, p, info, eig_vec,
600 (nargout > 1), cholB, disp, maxit);
603 (
eigs_func,
n, typ, sigmar, k, p, info, eig_vec,
605 (nargout > 1), cholB, disp, maxit);
611 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm,
616 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm,
624 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm,
629 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB,
643 "eigs: None of the %" OCTAVE_IDX_TYPE_FORMAT
644 " requested eigenvalues converged", k);
647 "eigs: Only %" OCTAVE_IDX_TYPE_FORMAT
648 " of the %" OCTAVE_IDX_TYPE_FORMAT
649 " requested eigenvalues converged",
652 if (! fcn_name.empty ())
663 octave_unused_parameter (interp);
664 octave_unused_parameter (args);
665 octave_unused_parameter (nargout);
static bool warned_imaginary
static octave_value eigs_fcn
ColumnVector eigs_func(const ColumnVector &x, int &eigs_error)
ComplexColumnVector eigs_complex_func(const ComplexColumnVector &x, int &eigs_error)
bool ishermitian(void) const
bool issymmetric(void) const
bool ishermitian(void) const
bool issymmetric(void) const
void clear_function(const std::string &name)
octave_value getfield(const std::string &key) const
octave_idx_type length(void) const
octave_idx_type numel(void) const
bool xbool_value(const char *fmt,...) const
bool is_defined(void) const
int nint_value(bool frc_str_conv=false) const
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
bool is_undefined(void) const
Array< Complex > complex_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double double_value(bool frc_str_conv=false) const
ColumnVector real(const ComplexColumnVector &a)
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 EigsRealSymmetricFunc(EigsFunc fun, 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 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 EigsComplexNonSymmetricFunc(EigsComplexFunc fun, 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)
octave_idx_type EigsRealNonSymmetricFunc(EigsFunc fun, 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)
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)
F77_RET_T const F77_DBLE * x
octave_value get_function_handle(interpreter &interp, const octave_value &arg, const std::string ¶meter_name)
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.
std::complex< double > Complex
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.