49 template <
typename DMT,
typename MT>
52 const std::list<octave_value_list>& idx)
59 retval = do_index_op (idx.front ());
65 std::string nm = type_name ();
66 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
77 template <
typename DMT,
typename MT>
82 if (m_matrix.rows () == 1 || m_matrix.cols () == 1)
90 retval = m_matrix.build_diag_matrix ();
97 retval = m_matrix.extract_diag (k);
101 template <
typename DMT,
typename MT>
117 if (idx0.is_scalar () && idx1.is_scalar ())
119 retval = m_matrix.checkelem (idx0(0), idx1(0));
125 if (idx0.is_colon_equiv (
m) && idx1.is_colon_equiv (
n)
126 &&
m <= m_matrix.rows () &&
n <= m_matrix.rows ())
133 retval = to_dense ().
index_op (idx, resize_ok);
136 catch (octave::index_exception& ie)
139 ie.set_pos_if_unset (2, k+1);
144 retval = to_dense ().
index_op (idx, resize_ok);
149 template <
typename DMT,
typename MT>
152 const std::list<octave_value_list>& idx,
161 if (type.length () != 1)
163 std::string nm = type_name ();
164 error (
"in indexed assignment of %s, last lhs index must be ()",
177 if (jdx.
length () == 1 && jdx(0).is_scalar_type ())
179 typename DMT::element_type val;
191 && chk_valid_scalar (rhs, val))
193 m_matrix.dgelem (i0(0)) = val;
200 catch (octave::index_exception& ie)
203 ie.set_pos_if_unset (2, k+1);
207 else if (jdx.
length () == 2
208 && jdx(0).is_scalar_type () && jdx(1).is_scalar_type ())
210 typename DMT::element_type val;
218 && i0(0) < m_matrix.rows () && i1(0) < m_matrix.cols ()
219 && chk_valid_scalar (rhs, val))
221 m_matrix.dgelem (i0(0)) = val;
228 catch (octave::index_exception& ie)
231 ie.set_pos_if_unset (2, k+1);
237 retval = numeric_assign (type, idx, rhs);
246 std::string nm = type_name ();
247 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
252 retval = tmp.
subsasgn (type, idx, rhs);
263 template <
typename DMT,
typename MT>
268 if (dv.
ndims () == 2)
271 rm.resize (dv(0), dv(1));
275 retval = to_dense ().
resize (dv, fill);
280 template <
typename DMT,
typename MT>
284 if (dims ().
numel () > 1)
292 return to_dense ().is_true ();
298 {
return x.real (); }
305 template <
typename DMT,
typename MT>
309 typedef typename DMT::element_type el_type;
313 "complex matrix",
"real scalar");
319 type_name (),
"real scalar");
324 template <
typename DMT,
typename MT>
328 typedef typename DMT::element_type el_type;
332 "complex matrix",
"real scalar");
334 if (! (
numel () > 0))
338 type_name (),
"real scalar");
343 template <
typename DMT,
typename MT>
347 if (rows () == 0 || columns () == 0)
351 type_name (),
"complex scalar");
353 return m_matrix(0, 0);
356 template <
typename DMT,
typename MT>
364 if (rows () == 0 || columns () == 0)
368 type_name (),
"complex scalar");
370 retval = m_matrix (0, 0);
375 template <
typename DMT,
typename MT>
379 return Matrix (diag_matrix_value ());
382 template <
typename DMT,
typename MT>
389 template <
typename DMT,
typename MT>
396 template <
typename DMT,
typename MT>
403 template <
typename DMT,
typename MT>
407 return NDArray (matrix_value ());
410 template <
typename DMT,
typename MT>
417 template <
typename DMT,
typename MT>
424 template <
typename DMT,
typename MT>
431 template <
typename DMT,
typename MT>
435 return to_dense ().bool_array_value (warn);
438 template <
typename DMT,
typename MT>
442 return to_dense ().char_array_value (warn);
445 template <
typename DMT,
typename MT>
452 template <
typename DMT,
typename MT>
459 template <
typename DMT,
typename MT>
463 return to_dense ().index_vector (require_integers);
466 template <
typename DMT,
typename MT>
474 template <
typename DMT,
typename MT>
482 template <
typename DMT,
typename MT>
488 std::ostringstream buf;
493 template <
typename DMT,
typename MT>
497 os <<
"# rows: " << m_matrix.rows () <<
"\n"
498 <<
"# columns: " << m_matrix.columns () <<
"\n";
500 os << m_matrix.extract_diag ();
505 template <
typename DMT,
typename MT>
514 error (
"load: failed to extract number of rows and columns");
521 error (
"load: failed to load diagonal matrix constant");
526 typedef typename DMT::element_type el_type;
528 m_matrix.resize (
r, c);
536 template <
typename DMT,
typename MT>
539 bool pr_as_read_syntax)
const
542 current_print_indent_level ());
545 template <
typename DMT,
typename MT>
549 return to_dense ().as_mxArray (interleaved);
552 template <
typename DMT,
typename MT>
561 template <
typename DMT,
typename MT>
565 print_raw (os, pr_as_read_syntax);
568 template <
typename DMT,
typename MT>
575 return to_dense ().write (os, block_size, output_type, skip, flt_fmt);
578 template <
typename DMT,
typename MT>
581 const std::string& prefix)
const
583 m_matrix.print_info (os, prefix);
589 template <
typename DMT,
typename MT>
593 if (m_matrix.isempty ())
595 else if (m_matrix.ndims () == 2)
612 std::ostringstream buf;
614 std::string tmp = buf.str ();
615 std::size_t pos = tmp.find_first_not_of (
' ');
616 if (pos != std::string::npos)
617 os << tmp.substr (pos);
618 else if (! tmp.empty ())
621 if (++elts >= max_elts)
628 if (i < nr - 1 && elts < max_elts)
641 template <
typename DMT,
typename MT>
645 if (
n < m_matrix.numel ())
658 template <
typename DMT,
typename MT>
662 if (! m_dense_cache.is_defined ())
663 m_dense_cache = MT (m_matrix);
665 return m_dense_cache;
Array< octave::idx_vector > ind2sub(const dim_vector &dv, const octave::idx_vector &idx)
N Dimensional Array with copy-on-write semantics.
Template for N-dimensional array classes with like-type math operators.
Template for two dimensional diagonal array with math operators.
NDArray diag(octave_idx_type k=0) const
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims() const
Number of dimensions.
bool load_ascii(std::istream &is)
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
void print_info(std::ostream &os, const std::string &prefix) const
boolNDArray bool_array_value(bool warn=false) const
Matrix matrix_value(bool=false) const
bool save_ascii(std::ostream &os)
Complex complex_value(bool=false) const
NDArray array_value(bool=false) const
FloatComplexNDArray float_complex_array_value(bool=false) const
ComplexMatrix complex_matrix_value(bool=false) const
virtual octave_value diag(octave_idx_type k=0) const
FloatComplex float_complex_value(bool=false) const
FloatComplexMatrix float_complex_matrix_value(bool=false) const
FloatNDArray float_array_value(bool=false) const
octave_value resize(const dim_vector &dv, bool fill=false) const
octave::idx_vector index_vector(bool=false) const
octave_value fast_elem_extract(octave_idx_type n) const
octave_value to_dense() const
float float_value(bool=false) const
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
charNDArray char_array_value(bool=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
int write(octave::stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
ComplexNDArray complex_array_value(bool=false) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
void short_disp(std::ostream &os) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
float_display_format get_edit_display_format() const
bool print_as_scalar() const
mxArray * as_mxArray(bool interleaved) const
double double_value(bool=false) const
FloatMatrix float_matrix_value(bool=false) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
SparseMatrix sparse_matrix_value(bool=false) const
octave_idx_type length() const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_value index_op(const octave_value_list &idx, bool resize_ok=false)
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
NDArray array_value(bool frc_str_conv=false) const
octave_value resize(const dim_vector &dv, bool fill=false) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void() error(const char *fmt,...)
#define panic_impossible()
void warn_array_as_logical(const dim_vector &dv)
void err_invalid_conversion(const std::string &from, const std::string &to)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
octave::idx_vector idx_vector
float lo_ieee_float_nan_value()
F77_RET_T const F77_DBLE * x
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
std::complex< double > Complex
std::complex< float > FloatComplex
T::size_type numel(const T &str)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)