26#if defined (HAVE_CONFIG_H)
45sqrtm_utri_inplace (T& m)
47 typedef typename T::element_type element_type;
48 typedef typename T::real_matrix_type real_matrix_type;
49 typedef typename T::real_elt_type real_elt_type;
51 const element_type zero = element_type ();
53 bool singular =
false;
59 real_matrix_type abs_m = m.abs ();
61 real_elt_type max_abs_diag = abs_m.diag ().max ()(0);
63 const real_elt_type tol = n * max_abs_diag
64 * std::numeric_limits<real_elt_type>::epsilon ();
78 element_type *mp = m.rwdata ();
85 if (mp[idx_diag] != zero)
86 mp[idx_diag] = sqrt (mp[idx_diag]);
112 element_type *colj = mp + n*j;
114 colj[j] = sqrt (colj[j]);
120 const element_type *coli = mp + n*i;
122 colj[i] /= (coli[i] + colj[j]);
123 const element_type colji = colj[i];
125 colj[k] -= coli[k] * colji;
132 "sqrtm: matrix is singular, may not have a square root");
135template <
typename Matrix,
typename ComplexMatrix,
typename ComplexSCHUR>
148 real_type cutoff = 0;
150 real_type
eps = std::numeric_limits<real_type>::epsilon ();
163 if (!
x.diag ().any_element_is_negative ())
166 sqrtm_utri_inplace (
x);
175 if (!
x.diag ().any_element_is_negative ())
178 sqrtm_utri_inplace (
x);
179 retval =
x.transpose ();
192 cutoff = 10 *
x.rows () *
eps *
xnorm (
x, one);
206 sqrtm_utri_inplace (
x);
213 sqrtm_utri_inplace (
x);
214 retval =
x.transpose ();
224 ComplexSCHUR schur_fact (
x,
"",
true);
225 x = schur_fact.schur_matrix ();
226 u = schur_fact.unitary_schur_matrix ();
230 sqrtm_utri_inplace (
x);
235 if (cutoff > 0 &&
xnorm (
imag (res), one) <= cutoff)
247DEFUN (sqrtm, args, nargout,
259 if (args.length () != 1)
267 if (n != nc || arg.
ndims () > 2)
281 retval(0) = arg.
sqrt ();
284 math::schur<FloatComplexMatrix>> (arg);
287 math::schur<ComplexMatrix>> (arg);
320OCTAVE_END_NAMESPACE(octave)
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
MatrixType transpose() const
int type(bool quiet=true)
bool is_diag_matrix() const
octave_value sqrt() const
octave_idx_type rows() const
MatrixType matrix_type() const
bool is_single_type() const
octave_idx_type columns() const
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning_with_id(const char *id, const char *fmt,...)
void err_square_matrix_required(const char *fcn, const char *name)
F77_RET_T const F77_DBLE * x
double xfrobnorm(const Matrix &x)
double xnorm(const ColumnVector &x, double p)
ComplexMatrix octave_value_extract< ComplexMatrix >(const octave_value &v)
Matrix octave_value_extract< Matrix >(const octave_value &v)