26 #if defined (HAVE_CONFIG_H)
43 template <
typename Matrix>
45 sqrtm_utri_inplace (
Matrix& T)
49 const element_type zero = element_type ();
51 bool singular =
false;
74 element_type *colj = Tp +
n*j;
76 colj[j] = sqrt (colj[j]);
82 const element_type *coli = Tp +
n*i;
84 colj[i] /= (coli[i] + colj[j]);
85 const element_type colji = colj[i];
87 colj[k] -= coli[k] * colji;
93 "sqrtm: matrix is singular, may not have a square root");
96 template <
typename Matrix,
typename ComplexMatrix,
typename ComplexSCHUR>
109 real_type cutoff = 0;
111 real_type
eps = std::numeric_limits<real_type>::epsilon ();
124 if (!
x.diag ().any_element_is_negative ())
127 sqrtm_utri_inplace (
x);
136 if (!
x.diag ().any_element_is_negative ())
139 sqrtm_utri_inplace (
x);
140 retval =
x.transpose ();
153 cutoff = 10 *
x.rows () *
eps *
xnorm (
x, one);
167 sqrtm_utri_inplace (
x);
174 sqrtm_utri_inplace (
x);
175 retval =
x.transpose ();
185 ComplexSCHUR schur_fact (
x,
"",
true);
186 x = schur_fact.schur_matrix ();
187 u = schur_fact.unitary_schur_matrix ();
191 sqrtm_utri_inplace (
x);
196 if (cutoff > 0 &&
xnorm (
imag (res), one) <= cutoff)
208 DEFUN (sqrtm, args, nargout,
220 if (args.length () != 1)
228 if (
n != nc || arg.
ndims () > 2)
242 retval(0) = arg.
sqrt ();
245 math::schur<FloatComplexMatrix>> (arg);
248 math::schur<ComplexMatrix>> (arg);
281 OCTAVE_END_NAMESPACE(
octave)
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
T * fortran_vec()
Size of the specified dimension.
octave_idx_type rows() 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)