26 #if defined (HAVE_CONFIG_H)
46 (*current_liboctave_warning_with_id_handler)
47 (
"Octave:matrix-type-info",
"using cached matrix type");
53 (*current_liboctave_warning_with_id_handler)
54 (
"Octave:matrix-type-info",
"invalid matrix type");
58 warn_calculating_sparse_type ()
60 (*current_liboctave_warning_with_id_handler)
61 (
"Octave:matrix-type-info",
"calculating sparse matrix type");
69 m_bandden (0), m_upper_band (0), m_lower_band (0),
70 m_dense (false), m_full (false), m_nperm (0), m_perm (nullptr) { }
73 : m_type (a.m_type), m_sp_bandden (a.m_sp_bandden), m_bandden (a.m_bandden),
74 m_upper_band (a.m_upper_band), m_lower_band (a.m_lower_band),
75 m_dense (a.m_dense), m_full (a.m_full),
76 m_nperm (a.m_nperm), m_perm (nullptr)
82 m_perm[i] = a.m_perm[i];
100 bool hermitian =
true;
106 j < ncols && upper; j++)
109 upper = upper && (
d != zero);
110 lower = lower && (
d != zero);
111 hermitian = hermitian && (
d > zero);
116 j < ncols && (upper || lower || hermitian); j++)
120 T aij = a.
elem (i, j);
121 T aji = a.
elem (j, i);
122 lower = lower && (aij == zero);
123 upper = upper && (aji == zero);
124 hermitian = hermitian && (aij == aji
125 && aij*aij < diag[i]*diag[j]);
144 template <
typename T>
159 bool hermitian =
true;
165 j < ncols && upper; j++)
167 std::complex<T>
d = a.elem (j, j);
168 upper = upper && (
d != zero);
169 lower = lower && (
d != zero);
170 hermitian = hermitian && (
d.real () > zero &&
d.imag () == zero);
175 j < ncols && (upper || lower || hermitian); j++)
179 std::complex<T> aij = a.elem (i, j);
180 std::complex<T> aji = a.elem (j, i);
181 lower = lower && (aij == zero);
182 upper = upper && (aji == zero);
205 m_sp_bandden (0), m_bandden (0), m_upper_band (0), m_lower_band (0),
206 m_dense (false), m_full (true), m_nperm (0), m_perm (nullptr)
213 m_sp_bandden (0), m_bandden (0), m_upper_band (0), m_lower_band (0),
214 m_dense (false), m_full (true), m_nperm (0), m_perm (nullptr)
221 m_sp_bandden (0), m_bandden (0), m_upper_band (0), m_lower_band (0),
222 m_dense (false), m_full (true), m_nperm (0), m_perm (nullptr)
229 m_sp_bandden (0), m_bandden (0), m_upper_band (0), m_lower_band (0),
230 m_dense (false), m_full (true), m_nperm (0), m_perm (nullptr)
236 template <
typename T>
239 m_sp_bandden (0), m_bandden (0), m_upper_band (0), m_lower_band (0),
240 m_dense (false), m_full (false), m_nperm (0), m_perm (nullptr)
247 if (octave::sparse_params::get_key (
"spumoni") != 0.)
248 warn_calculating_sparse_type ();
250 m_sp_bandden = octave::sparse_params::get_bandden ();
251 bool maybe_hermitian =
false;
259 for (i = 0; i < nm; i++)
275 std::vector<bool> found (nrows);
285 || ((a.
cidx (j+1) == a.
cidx (j) + 1) && found[a.
ridx (j)]))
290 found[a.
ridx (j)] =
true;
299 bool singular =
false;
304 bool zero_on_diagonal =
false;
307 zero_on_diagonal =
true;
311 zero_on_diagonal =
false;
316 if (zero_on_diagonal)
327 if (j - ru > m_upper_band)
328 m_upper_band = j - ru;
330 if (rl - j > m_lower_band)
331 m_lower_band = rl - j;
337 m_bandden = double (nnz) /
338 (double (ncols) * (double (m_lower_band) +
339 double (m_upper_band)) -
340 0.5 *
double (m_upper_band + 1) * double (m_upper_band) -
341 0.5 * double (m_lower_band + 1) * double (m_lower_band));
343 if (nrows == ncols && m_sp_bandden != 1. && m_bandden > m_sp_bandden)
345 if (m_upper_band == 1 && m_lower_band == 1)
351 = ((m_upper_band + m_lower_band + 1) * nrows
352 - (1 + m_upper_band) * m_upper_band / 2
353 - (1 + m_lower_band) * m_lower_band / 2);
355 if (nnz_in_band == nnz)
362 if (m_upper_band == 0)
364 else if (m_lower_band == 0)
367 if (m_upper_band == m_lower_band && nrows == ncols)
368 maybe_hermitian =
true;
415 else if (a.
cidx (nm) == a.
cidx (ncols))
430 m_perm[a.
ridx (i)] = j;
542 is_herm = a.
data (l) ==
d;
566 m_bandden (0), m_upper_band (0), m_lower_band (0),
567 m_dense (false), m_full (_full), m_nperm (0), m_perm (nullptr)
583 m_bandden (0), m_upper_band (0), m_lower_band (0),
584 m_dense (false), m_full (_full), m_nperm (0), m_perm (nullptr)
587 && np > 0 && p !=
nullptr)
603 m_bandden (0), m_upper_band (0), m_lower_band (0),
604 m_dense (false), m_full (_full), m_nperm (0), m_perm (nullptr)
630 m_sp_bandden = a.m_sp_bandden;
631 m_bandden = a.m_bandden;
632 m_upper_band = a.m_upper_band;
633 m_lower_band = a.m_lower_band;
646 m_perm[i] = a.m_perm[i];
659 && (m_full || m_sp_bandden == octave::sparse_params::get_bandden ()))
661 if (! quiet && octave::sparse_params::get_key (
"spumoni") != 0.)
668 && octave::sparse_params::get_key (
"spumoni") != 0.)
669 (*current_liboctave_warning_with_id_handler)
670 (
"Octave:matrix-type-info",
"invalidating matrix type");
681 && (m_full || m_sp_bandden == octave::sparse_params::get_bandden ()))
683 if (octave::sparse_params::get_key (
"spumoni") != 0.)
690 m_type = tmp_typ.m_type;
691 m_sp_bandden = tmp_typ.m_sp_bandden;
692 m_bandden = tmp_typ.m_bandden;
693 m_upper_band = tmp_typ.m_upper_band;
694 m_lower_band = tmp_typ.m_lower_band;
695 m_dense = tmp_typ.m_dense;
696 m_full = tmp_typ.m_full;
697 m_nperm = tmp_typ.m_nperm;
703 m_perm[i] = tmp_typ.m_perm[i];
713 && (m_full || m_sp_bandden == octave::sparse_params::get_bandden ()))
715 if (octave::sparse_params::get_key (
"spumoni") != 0.)
722 m_type = tmp_typ.m_type;
723 m_sp_bandden = tmp_typ.m_sp_bandden;
724 m_bandden = tmp_typ.m_bandden;
725 m_upper_band = tmp_typ.m_upper_band;
726 m_lower_band = tmp_typ.m_lower_band;
727 m_dense = tmp_typ.m_dense;
728 m_full = tmp_typ.m_full;
729 m_nperm = tmp_typ.m_nperm;
735 m_perm[i] = tmp_typ.m_perm[i];
746 if (octave::sparse_params::get_key (
"spumoni") != 0.)
753 m_type = tmp_typ.m_type;
754 m_full = tmp_typ.m_full;
755 m_nperm = tmp_typ.m_nperm;
761 m_perm[i] = tmp_typ.m_perm[i];
772 if (octave::sparse_params::get_key (
"spumoni") != 0.)
779 m_type = tmp_typ.m_type;
780 m_full = tmp_typ.m_full;
781 m_nperm = tmp_typ.m_nperm;
787 m_perm[i] = tmp_typ.m_perm[i];
798 if (octave::sparse_params::get_key (
"spumoni") != 0.)
805 m_type = tmp_typ.m_type;
806 m_full = tmp_typ.m_full;
807 m_nperm = tmp_typ.m_nperm;
813 m_perm[i] = tmp_typ.m_perm[i];
824 if (octave::sparse_params::get_key (
"spumoni") != 0.)
831 m_type = tmp_typ.m_type;
832 m_full = tmp_typ.m_full;
833 m_nperm = tmp_typ.m_nperm;
839 m_perm[i] = tmp_typ.m_perm[i];
848 if (octave::sparse_params::get_key (
"spumoni") != 0.)
851 (*current_liboctave_warning_with_id_handler)
852 (
"Octave:matrix-type-info",
"unknown matrix type");
854 (*current_liboctave_warning_with_id_handler)
855 (
"Octave:matrix-type-info",
"diagonal sparse matrix");
857 (*current_liboctave_warning_with_id_handler)
858 (
"Octave:matrix-type-info",
"permuted diagonal sparse matrix");
860 (*current_liboctave_warning_with_id_handler)
861 (
"Octave:matrix-type-info",
"upper triangular matrix");
863 (*current_liboctave_warning_with_id_handler)
864 (
"Octave:matrix-type-info",
"lower triangular matrix");
866 (*current_liboctave_warning_with_id_handler)
867 (
"Octave:matrix-type-info",
"permuted upper triangular matrix");
869 (*current_liboctave_warning_with_id_handler)
870 (
"Octave:matrix-type-info",
"permuted lower triangular Matrix");
872 (*current_liboctave_warning_with_id_handler)
873 (
"Octave:matrix-type-info",
874 "banded sparse matrix %" OCTAVE_IDX_TYPE_FORMAT
"-1-"
875 "%" OCTAVE_IDX_TYPE_FORMAT
" (density %f)",
876 m_lower_band, m_upper_band, m_bandden);
878 (*current_liboctave_warning_with_id_handler)
879 (
"Octave:matrix-type-info",
880 "banded hermitian/symmetric sparse matrix %" OCTAVE_IDX_TYPE_FORMAT
881 "-1-%" OCTAVE_IDX_TYPE_FORMAT
" (density %f)",
882 m_lower_band, m_upper_band, m_bandden);
884 (*current_liboctave_warning_with_id_handler)
885 (
"Octave:matrix-type-info",
"hermitian/symmetric matrix");
887 (*current_liboctave_warning_with_id_handler)
888 (
"Octave:matrix-type-info",
"tridiagonal sparse matrix");
890 (*current_liboctave_warning_with_id_handler)
891 (
"Octave:matrix-type-info",
892 "hermitian/symmetric tridiagonal sparse matrix");
894 (*current_liboctave_warning_with_id_handler)
895 (
"Octave:matrix-type-info",
"rectangular/singular matrix");
897 (*current_liboctave_warning_with_id_handler)
898 (
"Octave:matrix-type-info",
"m_full matrix");
916 (
"Can not mark current matrix type as symmetric");
951 (
"Can not mark current matrix type as symmetric");
986 retval.m_upper_band = m_lower_band;
987 retval.m_lower_band = m_upper_band;
ComplexColumnVector conj(const ComplexColumnVector &a)
MatrixType::matrix_type matrix_real_probe(const MArray< T > &a)
MatrixType::matrix_type matrix_complex_probe(const MArray< std::complex< T >> &a)
T & elem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type rows() const
octave_idx_type cols() const
Template for N-dimensional array classes with like-type math operators.
void mark_as_unsymmetric()
void mark_as_permuted(const octave_idx_type np, const octave_idx_type *p)
void mark_as_unpermuted()
MatrixType & operator=(const MatrixType &a)
MatrixType transpose() const
int type(bool quiet=true)
octave_idx_type cols() const
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
double norm(const ColumnVector &v)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define OCTAVE_LOCAL_BUFFER(T, buf, size)