44 template <
typename MT>
47 const std::list<octave_value_list>& idx)
54 retval = do_index_op (idx.front ());
60 std::string nm = type_name ();
61 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
72 template <
typename MT>
75 const std::list<octave_value_list>& idx,
84 if (type.length () == 1)
85 retval = numeric_assign (type, idx, rhs);
94 error (
"invalid assignment expression");
98 retval = tmp.
subsasgn (type, idx, rhs);
102 std::string nm = type_name ();
103 error (
"in indexed assignment of %s, last lhs index must be ()",
114 std::string nm = type_name ();
115 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
120 retval = tmp.
subsasgn (type, idx, rhs);
131 template <
typename MT>
140 int nd = m_matrix.ndims ();
141 const MT& cmatrix = m_matrix;
163 if (! resize_ok && i.is_scalar ())
164 retval = cmatrix.checkelem (i(0));
166 retval = MT (m_matrix.index (i, resize_ok));
178 if (! resize_ok && i.is_scalar () && j.is_scalar ())
179 retval = cmatrix.checkelem (i(0), j(0));
181 retval = MT (m_matrix.index (i, j, resize_ok));
188 bool scalar_opt = n_idx == nd && ! resize_ok;
191 for (k = 0; k < n_idx; k++)
193 idx_vec(k) = idx(k).index_vector ();
195 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ());
201 retval = MT (m_matrix.index (idx_vec, resize_ok));
206 catch (octave::index_exception& ie)
209 ie.set_pos_if_unset (n_idx, k+1);
223 template <
typename MT>
247 m_matrix.assign (i, rhs);
258 m_matrix.assign (i, j, rhs);
266 for (k = 0; k < n_idx; k++)
267 idx_vec(k) = idx(k).index_vector ();
269 m_matrix.assign (idx_vec, rhs);
274 catch (octave::index_exception& ie)
277 ie.set_pos_if_unset (n_idx, k+1);
282 clear_cached_info ();
285 template <
typename MT>
294 template <
typename MT>
297 typename MT::element_type rhs)
301 int nd = m_matrix.ndims ();
324 if (i.is_scalar () && i(0) < m_matrix.numel ())
325 m_matrix(i(0)) = rhs;
327 m_matrix.assign (i, mrhs);
339 if (i.is_scalar () && j.is_scalar () && nd == 2
340 && i(0) < m_matrix.rows () && j(0) < m_matrix.columns ())
341 m_matrix(i(0), j(0)) = rhs;
343 m_matrix.assign (i, j, mrhs);
350 bool scalar_opt = n_idx == nd;
353 for (k = 0; k < n_idx; k++)
355 idx_vec(k) = idx(k).index_vector ();
357 scalar_opt = (scalar_opt && idx_vec(k).is_scalar ()
358 && idx_vec(k)(0) < dv(k));
369 j += idx_vec(i)(0) *
n;
375 m_matrix.assign (idx_vec, mrhs);
380 catch (octave::index_exception& ie)
383 ie.set_pos_if_unset (n_idx, k+1);
388 clear_cached_info ();
391 template <
typename MT>
400 ra_idx(i) = idx(i).index_vector ();
402 m_matrix.delete_elements (
ra_idx);
405 clear_cached_info ();
408 template <
typename MT>
412 MT retval (m_matrix);
414 retval.resize (dv, 0);
421 template <
typename MT>
427 int nel = dv.
numel ();
431 MT t1 (m_matrix.reshape (
dim_vector (nel, 1)));
433 if (t1.any_element_is_nan ())
447 template <
typename MT>
456 template <
typename MT>
460 print_raw (os, pr_as_read_syntax);
464 template <
typename MT>
467 const std::string& prefix)
const
469 m_matrix.print_info (os, prefix);
472 template <
typename MT>
476 if (m_matrix.isempty ())
478 else if (m_matrix.ndims () == 2)
495 std::ostringstream buf;
497 std::string tmp = buf.str ();
498 std::size_t pos = tmp.find_first_not_of (
' ');
499 if (pos != std::string::npos)
500 os << tmp.substr (pos);
501 else if (! tmp.empty ())
504 if (++elts >= max_elts)
511 if (i < nr - 1 && elts < max_elts)
524 template <
typename MT>
531 template <
typename MT>
537 std::ostringstream buf;
542 template <
typename MT>
546 if (
n < m_matrix.numel ())
552 template <
typename MT>
557 if (
n < m_matrix.numel ())
560 typedef typename MT::element_type ET;
566 void *here =
reinterpret_cast<void *
> (&m_matrix(
n));
568 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.
OCTAVE_API 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.
bool all_ones(void) const
OCTAVE_API dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
bool any_zero(void) const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
MatrixType matrix_type(void) const
OCTINTERP_API bool fast_elem_insert(octave_idx_type n, const octave_value &x)
octave_value resize(const dim_vector &dv, bool fill=false) const
OCTINTERP_API octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
virtual void assign(const std::string &, const octave_value &)
OCTINTERP_API void delete_elements(const octave_value_list &idx)
OCTINTERP_API octave_value fast_elem_extract(octave_idx_type n) const
OCTINTERP_API void print_info(std::ostream &os, const std::string &prefix) const
OCTINTERP_API bool print_as_scalar(void) const
OCTINTERP_API void print(std::ostream &os, bool pr_as_read_syntax=false)
OCTINTERP_API float_display_format get_edit_display_format(void) const
OCTINTERP_API void short_disp(std::ostream &os) const
OCTINTERP_API bool is_true(void) const
OCTINTERP_API octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
OCTINTERP_API std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_idx_type length(void) const
static OCTINTERP_API octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
OCTINTERP_API octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
OCTINTERP_API 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(void)
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)