44 template <
typename MT>
51 return do_index_op (idx);
57 std::string nm = type_name ();
58 error (
"%s cannot be indexed with %c", nm.c_str (), type);
67 template <
typename MT>
70 const std::list<octave_value_list>& idx)
77 retval = do_index_op (idx.front ());
83 std::string nm = type_name ();
84 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
95 template <
typename MT>
98 const std::list<octave_value_list>& idx,
107 if (type.length () == 1)
108 retval = numeric_assign (type, idx, rhs);
117 error (
"invalid assignment expression");
121 retval = tmp.
subsasgn (type, idx, rhs);
125 std::string nm = type_name ();
126 error (
"in indexed assignment of %s, last lhs index must be ()",
137 std::string nm = type_name ();
138 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
143 retval = tmp.
subsasgn (type, idx, rhs);
154 template <
typename MT>
163 int nd = m_matrix.ndims ();
164 const MT& cmatrix = m_matrix;
186 if (! resize_ok && i.is_scalar ())
187 retval = cmatrix.checkelem (i(0));
189 retval = MT (m_matrix.index (i, resize_ok));
201 if (! resize_ok && i.is_scalar () && j.is_scalar ())
202 retval = cmatrix.checkelem (i(0), j(0));
204 retval = MT (m_matrix.index (i, j, resize_ok));
211 bool scalar_opt = n_idx == nd && ! resize_ok;
214 for (k = 0; k < n_idx; k++)
216 idx_vec(k) = idx(k).index_vector ();
218 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ());
224 retval = MT (m_matrix.index (idx_vec, resize_ok));
229 catch (octave::index_exception& ie)
232 ie.set_pos_if_unset (n_idx, k+1);
246 template <
typename MT>
270 m_matrix.assign (i, rhs);
281 m_matrix.assign (i, j, rhs);
289 for (k = 0; k < n_idx; k++)
290 idx_vec(k) = idx(k).index_vector ();
292 m_matrix.assign (idx_vec, rhs);
297 catch (octave::index_exception& ie)
300 ie.set_pos_if_unset (n_idx, k+1);
305 clear_cached_info ();
308 template <
typename MT>
317 template <
typename MT>
320 typename MT::element_type rhs)
324 int nd = m_matrix.ndims ();
347 if (i.is_scalar () && i(0) < m_matrix.numel ())
348 m_matrix(i(0)) = rhs;
350 m_matrix.assign (i, mrhs);
362 if (i.is_scalar () && j.is_scalar () && nd == 2
363 && i(0) < m_matrix.rows () && j(0) < m_matrix.columns ())
364 m_matrix(i(0), j(0)) = rhs;
366 m_matrix.assign (i, j, mrhs);
373 bool scalar_opt = n_idx == nd;
376 for (k = 0; k < n_idx; k++)
378 idx_vec(k) = idx(k).index_vector ();
380 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ()
381 && idx_vec(k)(0) < dv(k));
392 j += idx_vec(i)(0) *
n;
398 m_matrix.assign (idx_vec, mrhs);
403 catch (octave::index_exception& ie)
406 ie.set_pos_if_unset (n_idx, k+1);
411 clear_cached_info ();
414 template <
typename MT>
423 ra_idx(i) = idx(i).index_vector ();
425 m_matrix.delete_elements (
ra_idx);
428 clear_cached_info ();
431 template <
typename MT>
435 MT retval (m_matrix);
437 retval.resize (dv, 0);
444 template <
typename MT>
450 int nel = dv.
numel ();
454 MT t1 (m_matrix.reshape (
dim_vector (nel, 1)));
456 if (t1.any_element_is_nan ())
470 template <
typename MT>
479 template <
typename MT>
483 print_raw (os, pr_as_read_syntax);
487 template <
typename MT>
490 const std::string& prefix)
const
492 m_matrix.print_info (os, prefix);
495 template <
typename MT>
499 if (m_matrix.isempty ())
501 else if (m_matrix.ndims () == 2)
518 std::ostringstream buf;
520 std::string tmp = buf.str ();
521 std::size_t pos = tmp.find_first_not_of (
' ');
522 if (pos != std::string::npos)
523 os << tmp.substr (pos);
524 else if (! tmp.empty ())
527 if (++elts >= max_elts)
534 if (i < nr - 1 && elts < max_elts)
547 template <
typename MT>
554 template <
typename MT>
560 std::ostringstream buf;
565 template <
typename MT>
569 if (
n < m_matrix.numel ())
575 template <
typename MT>
580 if (
n < m_matrix.numel ())
583 typedef typename MT::element_type ET;
589 void *here =
reinterpret_cast<void *
> (&m_matrix(
n));
591 return x.get_rep ().fast_elem_insert_self (here, btyp);
Array< octave_idx_type > conv_to_int_array(const Array< octave::idx_vector > &a)
N Dimensional Array with copy-on-write semantics.
boolNDArray all(int dim=-1) const
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
bool print_as_scalar() const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
octave_value resize(const dim_vector &dv, bool fill=false) const
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
float_display_format get_edit_display_format() const
virtual void assign(const std::string &, const octave_value &)
void delete_elements(const octave_value_list &idx)
octave_value fast_elem_extract(octave_idx_type n) const
void print_info(std::ostream &os, const std::string &prefix) const
octave_value_list simple_subsref(char type, octave_value_list &idx, int nargout)
void print(std::ostream &os, bool pr_as_read_syntax=false)
void short_disp(std::ostream &os) const
MatrixType matrix_type() const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_idx_type length() const
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)
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_empty_index(const std::string &type_name)
void warn_array_as_logical(const dim_vector &dv)
octave::idx_vector idx_vector
void err_nan_to_logical_conversion()
F77_RET_T const F77_DBLE * x
const octave_base_value const Array< octave_idx_type > & ra_idx
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)
float_display_format make_format(const double &d)