GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
dim_vector Class Reference

#include "dim-vector.h"

Collaboration diagram for dim_vector:
Collaboration graph
[legend]

Public Member Functions

 dim_vector (octave_idx_type d0, octave_idx_type d1)
 Construct dim_vector for 2 dimensional array. More...
 
 dim_vector (octave_idx_type d0, octave_idx_type d1, octave_idx_type d2)
 Construct dim_vector for 3 dimensional array. More...
 
 dim_vector (octave_idx_type d0, octave_idx_type d1, octave_idx_type d2, octave_idx_type d3)
 Construct dim_vector for 4 dimensional array. More...
 
 dim_vector (octave_idx_type d0, octave_idx_type d1, octave_idx_type d2, octave_idx_type d3, octave_idx_type d4)
 Construct dim_vector for 5 dimensional array. More...
 
 dim_vector (octave_idx_type d0, octave_idx_type d1, octave_idx_type d2, octave_idx_type d3, octave_idx_type d4, octave_idx_type d5)
 Construct dim_vector for 6 dimensional array. More...
 
 dim_vector (octave_idx_type d0, octave_idx_type d1, octave_idx_type d2, octave_idx_type d3, octave_idx_type d4, octave_idx_type d5, octave_idx_type d6)
 Construct dim_vector for 7 dimensional array. More...
 
 dim_vector (void)
 
 dim_vector (const dim_vector &dv)
 
 dim_vector (octave_idx_type *r)
 
 ~dim_vector (void)
 
bool all_ones (void) const
 
bool all_zero (void) const
 
bool any_neg (void) const
 
bool any_zero (void) const
 
dim_vector as_column (void) const
 
dim_vector as_row (void) const
 
void chop_all_singletons (void)
 
void chop_trailing_singletons (void)
 
octave_idx_type compute_index (const octave_idx_type *idx) const
 Compute a linear index from an index tuple. More...
 
octave_idx_type compute_index (const octave_idx_type *idx, int nidx) const
 Ditto, but the tuple may be incomplete (nidx < length ()). More...
 
bool concat (const dim_vector &dvb, int dim)
 This corresponds to cat(). More...
 
octave_idx_type cum_compute_index (const octave_idx_type *idx) const
 Compute a linear index from an index tuple. More...
 
dim_vector cumulative (void) const
 Return cumulative dimensions. More...
 
octave_idx_typeelem (int i)
 
octave_idx_type elem (int i) const
 
bool empty_2d (void) const
 
int first_non_singleton (int def=0) const
 
bool hvcat (const dim_vector &dvb, int dim)
 This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1). More...
 
int increment_index (octave_idx_type *idx, int start=0) const
 
bool is_vector (void) const
 
int length (void) const
 
int num_ones (void) const
 
octave_idx_type numel (int n=0) const
 Number of elements that a matrix with this dimensions would have. More...
 
octave_idx_typeoperator() (int i)
 
octave_idx_type operator() (int i) const
 
dim_vectoroperator= (const dim_vector &dv)
 
dim_vector redim (int n) const
 
void resize (int n, int fill_value=0)
 
octave_idx_type safe_numel (void) const
 
dim_vector squeeze (void) const
 
std::string str (char sep= 'x') const
 
octave_idx_typeto_jit (void) const
 
bool zero_by_zero (void) const
 

Static Public Member Functions

static dim_vector alloc (int n)
 
static octave_idx_type dim_max (void)
 

Private Member Functions

octave_idx_typeclonerep (void)
 Clone this->rep. More...
 
octave_idx_typecount (void) const
 
void freerep (void)
 Free the rep. More...
 
void make_unique (void)
 
octave_idx_typendims (void) const
 
octave_idx_typeresizerep (int n, octave_idx_type fill_value)
 Clone and resize this->rep to length n, filling by given value. More...
 

Static Private Member Functions

static octave_idx_typenewrep (int ndims)
 Construct a new rep with count = 1 and ndims given. More...
 
static octave_idx_typenil_rep (void)
 

Private Attributes

octave_idx_typerep
 

Friends

bool operator== (const dim_vector &a, const dim_vector &b)
 

Detailed Description

Definition at line 53 of file dim-vector.h.

Constructor & Destructor Documentation

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1 
)
inline

Construct dim_vector for 2 dimensional array.

It can be used to construct a 2D array. Example:

dim_vector dv (7, 5);
Matrix mat (dv);

The constructed dim_vector dv will have two elements, $[7, 5]$, one for each dimension. It can then be used to construct a Matrix with such dimensions, i.e., 7 rows and 5 columns.

There are constructors available for up to 7 dimensions. For a higher number of dimensions, use redim() or resize().

Note that that there is no constructor for a 1 element dim_vector. This is because there are no 1 dimensional Array in liboctave. Such constructor did exist in liboctave but was removed in version 4.0.0 due to its potential for confusion.

Definition at line 174 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1,
octave_idx_type  d2 
)
inline

Construct dim_vector for 3 dimensional array.

It can be used to construct a 3D array. Example:

NDArray A (dim_vector (7, 5, 4));

This will construct a 3 dimensional NDArray of lengths 7, 5, and 4, on the first, second, and third dimension (rows, columns, and pages) respectively.

Definition at line 186 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1,
octave_idx_type  d2,
octave_idx_type  d3 
)
inline

Construct dim_vector for 4 dimensional array.

See also
dim_vector(octave_idx_type d0, octave_idx_type d1)

Definition at line 188 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1,
octave_idx_type  d2,
octave_idx_type  d3,
octave_idx_type  d4 
)
inline

Construct dim_vector for 5 dimensional array.

See also
dim_vector(octave_idx_type d0, octave_idx_type d1)

Definition at line 190 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1,
octave_idx_type  d2,
octave_idx_type  d3,
octave_idx_type  d4,
octave_idx_type  d5 
)
inline

Construct dim_vector for 6 dimensional array.

See also
dim_vector(octave_idx_type d0, octave_idx_type d1)

Definition at line 192 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type  d0,
octave_idx_type  d1,
octave_idx_type  d2,
octave_idx_type  d3,
octave_idx_type  d4,
octave_idx_type  d5,
octave_idx_type  d6 
)
inline

Construct dim_vector for 7 dimensional array.

See also
dim_vector(octave_idx_type d0, octave_idx_type d1)

Definition at line 194 of file dim-vector.h.

dim_vector::dim_vector ( void  )
inlineexplicit

Definition at line 247 of file dim-vector.h.

References rep.

Referenced by hvcat(), and squeeze().

dim_vector::dim_vector ( const dim_vector dv)
inline

Definition at line 250 of file dim-vector.h.

dim_vector::dim_vector ( octave_idx_type r)
inlineexplicit

Definition at line 254 of file dim-vector.h.

dim_vector::~dim_vector ( void  )
inline

Definition at line 275 of file dim-vector.h.

Member Function Documentation

bool dim_vector::all_ones ( void  ) const
inline
bool dim_vector::all_zero ( void  ) const
inline
static dim_vector dim_vector::alloc ( int  n)
inlinestatic
bool dim_vector::any_neg ( void  ) const
inline

Definition at line 385 of file dim-vector.h.

Referenced by Array< T >::resize().

bool dim_vector::any_zero ( void  ) const
inline
dim_vector dim_vector::as_column ( void  ) const
inline

Definition at line 414 of file dim-vector.h.

dim_vector dim_vector::as_row ( void  ) const
inline

Definition at line 422 of file dim-vector.h.

References elem, and jit_convention::length.

void dim_vector::chop_all_singletons ( void  )

Definition at line 43 of file dim-vector.cc.

References make_unique(), ndims(), and rep.

Referenced by Array< T >::assign(), and zero_dims_inquire().

void dim_vector::chop_trailing_singletons ( void  )
inline
octave_idx_type* dim_vector::clonerep ( void  )
inlineprivate

Clone this->rep.

Definition at line 79 of file dim-vector.h.

octave_idx_type dim_vector::compute_index ( const octave_idx_type idx) const
inline

Compute a linear index from an index tuple.

Definition at line 448 of file dim-vector.h.

Referenced by compute_index(), Array< octave_value >::compute_index_unchecked(), do_bsxfun_op(), and do_inplace_bsxfun_op().

octave_idx_type dim_vector::compute_index ( const octave_idx_type idx,
int  nidx 
) const
inline

Ditto, but the tuple may be incomplete (nidx < length ()).

Definition at line 459 of file dim-vector.h.

bool dim_vector::concat ( const dim_vector dvb,
int  dim 
)

This corresponds to cat().

Definition at line 177 of file dim-vector.cc.

References chop_trailing_singletons(), make_unique(), match(), ndims(), rep, and resize().

Referenced by octave_map::cat(), Sparse< T >::cat(), Array< T >::cat(), do_cat(), and hvcat().

octave_idx_type& dim_vector::count ( void  ) const
inlineprivate

Definition at line 63 of file dim-vector.h.

octave_idx_type dim_vector::cum_compute_index ( const octave_idx_type idx) const
inline

Compute a linear index from an index tuple.

Dimensions are required to be cumulative.

Definition at line 504 of file dim-vector.h.

Referenced by do_bsxfun_op(), and do_inplace_bsxfun_op().

dim_vector dim_vector::cumulative ( void  ) const
inline

Return cumulative dimensions.

Definition at line 489 of file dim-vector.h.

Referenced by convolve(), do_bsxfun_op(), and do_inplace_bsxfun_op().

octave_idx_type dim_vector::dim_max ( void  )
static

Definition at line 37 of file dim-vector.cc.

References max().

Referenced by Fsizemax(), and safe_numel().

octave_idx_type& dim_vector::elem ( int  i)
inline

Definition at line 197 of file dim-vector.h.

Referenced by num_ones(), squeeze(), and str().

octave_idx_type dim_vector::elem ( int  i) const
inline

Definition at line 206 of file dim-vector.h.

bool dim_vector::empty_2d ( void  ) const
inline

Definition at line 320 of file dim-vector.h.

int dim_vector::first_non_singleton ( int  def = 0) const
inline
void dim_vector::freerep ( void  )
inlineprivate

Free the rep.

Definition at line 122 of file dim-vector.h.

bool dim_vector::hvcat ( const dim_vector dvb,
int  dim 
)

This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1).

Definition at line 241 of file dim-vector.cc.

References concat(), dim_vector(), length(), and rep.

Referenced by Sparse< T >::cat(), Array< T >::cat(), and do_cat().

int dim_vector::increment_index ( octave_idx_type idx,
int  start = 0 
) const
inline

Definition at line 474 of file dim-vector.h.

Referenced by do_bsxfun_op(), do_inplace_bsxfun_op(), do_mat2cell(), and do_mat2cell_nd().

bool dim_vector::is_vector ( void  ) const
inline
int dim_vector::length ( void  ) const
inline

Definition at line 281 of file dim-vector.h.

Referenced by all_colon_equiv(), Array< octave_value >::as_column(), Array< octave_value >::as_matrix(), Array< octave_value >::as_row(), Array< T >::assign(), Array< T >::cat(), check_dimensions(), OCTAVE_VALUE_INT_MATRIX_T::complex_matrix_value(), convert_packcomplex_Nd(), Array< T >::diag(), do_accumdim_sum(), do_cat(), do_cellslices_nda(), do_diff(), do_fft(), do_fft2(), do_fftn(), do_mx_minmax_op(), do_num2cell_helper(), do_trilu(), symbol_table::do_workspace_info(), Fblkmm(), Fbsxfun(), Fcellslices(), Fellipj(), Fend(), Ffilter(), fill_matrix(), filter(), Find2sub(), Fiscolumn(), Fismatrix(), Fisrow(), Fissquare(), Fisvector(), OCTAVE_VALUE_INT_MATRIX_T::float_complex_matrix_value(), OCTAVE_VALUE_INT_MATRIX_T::float_matrix_value(), ComplexNDArray::fourier(), FloatComplexNDArray::fourier(), FloatNDArray::fourier(), NDArray::fourier(), ComplexNDArray::fourier2d(), FloatComplexNDArray::fourier2d(), FloatNDArray::fourier2d(), NDArray::fourier2d(), ComplexNDArray::fourierNd(), FloatComplexNDArray::fourierNd(), FloatNDArray::fourierNd(), NDArray::fourierNd(), freeze(), Fsize(), Fstruct2cell(), get_dims_str(), get_ra_idx(), get_red_dims(), get_vec_dims(), hvcat(), idx_vector::idx_mask_rep::idx_mask_rep(), idx_vector::idx_vector_rep::idx_vector_rep(), ComplexNDArray::ifourier(), FloatComplexNDArray::ifourier(), FloatNDArray::ifourier(), NDArray::ifourier(), ComplexNDArray::ifourier2d(), FloatComplexNDArray::ifourier2d(), FloatNDArray::ifourier2d(), NDArray::ifourier2d(), ComplexNDArray::ifourierNd(), FloatComplexNDArray::ifourierNd(), FloatNDArray::ifourierNd(), NDArray::ifourierNd(), increment_index(), ind2sub(), index_in_bounds(), tm_const::init(), ComplexNDArray::insert(), FloatComplexNDArray::insert(), is_scalar(), is_valid_bsxfun(), is_valid_inplace_bsxfun(), is_vector(), isvector(), octave_value::length(), make_vector_dims(), mat2cell_mismatch(), OCTAVE_VALUE_INT_MATRIX_T::matrix_value(), SparseMatrix::max(), SparseComplexMatrix::max(), maybe_update_column(), SparseMatrix::min(), SparseComplexMatrix::min(), octave_base_value::ndims(), Array< octave_value >::ndims(), Sparse< bool >::ndims(), Array< T >::nth_element(), num_ones(), operator<<(), Array< T >::permute(), rec_index_helper::rec_index_helper(), rec_resize_helper::rec_resize_helper(), redim(), Sparse< T >::reshape(), octave_base_diag< DMT, MT >::resize(), Sparse< T >::resize(), Array< T >::resize(), safe_numel(), octave_base_int_matrix< T >::save_ascii(), octave_struct::save_ascii(), octave_float_complex_matrix::save_ascii(), octave_char_matrix_str::save_ascii(), octave_complex_matrix::save_ascii(), octave_cell::save_ascii(), octave_float_matrix::save_ascii(), octave_bool_matrix::save_ascii(), octave_matrix::save_ascii(), octave_scalar_struct::save_ascii(), octave_base_int_matrix< T >::save_binary(), octave_sparse_bool_matrix::save_binary(), octave_struct::save_binary(), octave_sparse_complex_matrix::save_binary(), octave_sparse_matrix::save_binary(), octave_float_complex_matrix::save_binary(), octave_char_matrix_str::save_binary(), octave_complex_matrix::save_binary(), octave_cell::save_binary(), octave_float_matrix::save_binary(), octave_bool_matrix::save_binary(), octave_matrix::save_binary(), octave_base_int_matrix< T >::save_hdf5(), octave_float_complex_matrix::save_hdf5(), octave_char_matrix_str::save_hdf5(), octave_complex_matrix::save_hdf5(), octave_cell::save_hdf5(), octave_float_matrix::save_hdf5(), octave_bool_matrix::save_hdf5(), octave_matrix::save_hdf5(), save_hdf5_empty(), scalar(), octave_class::size(), octave_base_value::size(), octave_lazy_index::sort(), Array< T >::sort(), idx_vector::idx_vector_rep::sort_uniq_clone(), Sparse< T >::Sparse(), squeeze(), str(), try_cellfun_internal_ops(), update_index(), array_property::validate(), vector_equivalent(), and zero_dims_inquire().

void dim_vector::make_unique ( void  )
inlineprivate

Definition at line 128 of file dim-vector.h.

References OCTREFCOUNT_ATOMIC_DECREMENT.

Referenced by chop_all_singletons(), and concat().

octave_idx_type& dim_vector::ndims ( void  ) const
inlineprivate

Definition at line 61 of file dim-vector.h.

Referenced by chop_all_singletons(), and concat().

static octave_idx_type* dim_vector::newrep ( int  ndims)
inlinestaticprivate

Construct a new rep with count = 1 and ndims given.

Definition at line 67 of file dim-vector.h.

static octave_idx_type* dim_vector::nil_rep ( void  )
inlinestaticprivate

Definition at line 237 of file dim-vector.h.

int dim_vector::num_ones ( void  ) const

Definition at line 81 of file dim-vector.cc.

References elem(), and length().

octave_idx_type dim_vector::numel ( int  n = 0) const
inline

Number of elements that a matrix with this dimensions would have.

Return the number of elements that a matrix with this dimension vector would have, NOT the number of dimensions (elements in the dimension vector).

Definition at line 361 of file dim-vector.h.

Referenced by airy(), betainc(), betaincinv(), biry(), compute_index(), convert_packcomplex_Nd(), octave_base_int_matrix< T >::convert_to_str_internal(), octave_sparse_matrix::convert_to_str_internal(), octave_float_matrix::convert_to_str_internal(), octave_matrix::convert_to_str_internal(), dims_to_numel(), do_bessel(), do_bsxfun_op(), do_inplace_bsxfun_op(), do_object2cell(), Fbsxfun(), octave_fftw::fftNd(), filter(), Fregexprep(), Freshape(), gammainc(), get_ra_idx(), octave_fftw::ifftNd(), ind2sub(), octave_base_sparse< T >::is_true(), octave_base_matrix< MT >::is_true(), octave_char_matrix_str::load_ascii(), octave_cell::load_ascii(), octave_base_int_matrix< T >::load_binary(), octave_float_complex_matrix::load_binary(), octave_char_matrix_str::load_binary(), octave_complex_matrix::load_binary(), octave_cell::load_binary(), octave_float_matrix::load_binary(), octave_bool_matrix::load_binary(), octave_matrix::load_binary(), octave_cell::load_hdf5(), octave_bool_matrix::load_hdf5(), make_vector_dims(), octave_class::numel(), octave_base_value::numel(), octave_print_internal_template(), read_mat5_binary_element(), Sparse< T >::reshape(), octave_float_complex::resize(), octave_complex::resize(), octave_scalar::resize(), octave_float_scalar::resize(), octave_bool::resize(), OCTAVE_VALUE_INT_SCALAR_T::resize(), octave_char_matrix_str::save_ascii(), octave_cell::save_ascii(), octave_float_complex_matrix::save_binary(), octave_char_matrix_str::save_binary(), octave_complex_matrix::save_binary(), octave_cell::save_binary(), octave_float_matrix::save_binary(), octave_matrix::save_binary(), octave_char_matrix_str::save_hdf5(), octave_cell::save_hdf5(), save_mat5_binary_element(), and Array< T >::sort().

octave_idx_type& dim_vector::operator() ( int  i)
inline

Definition at line 283 of file dim-vector.h.

octave_idx_type dim_vector::operator() ( int  i) const
inline

Definition at line 285 of file dim-vector.h.

References OCTREFCOUNT_ATOMIC_DECREMENT.

dim_vector& dim_vector::operator= ( const dim_vector dv)
inline

Definition at line 261 of file dim-vector.h.

dim_vector dim_vector::redim ( int  n) const

Force certain dimensionality, preserving numel (). Missing dimensions are set to 1, redundant are folded into the trailing one. If n = 1, the result is 2d and the second dim is 1 (dim_vectors are always at least 2D).

Definition at line 266 of file dim-vector.cc.

References alloc(), length(), and rep.

Referenced by Array< octave_value >::as_matrix(), octave_base_matrix< MT >::assign(), Array< T >::assign(), compute_index(), convolve(), dims_to_numel(), do_bsxfun_op(), do_inplace_bsxfun_op(), Fcell2struct(), Fdot(), Find2sub(), Fsize(), Fsub2ind(), MArray< T >::idx_add_nd(), Array< T >::index(), Sparse< T >::index(), Array< T >::insert(), Array< T >::resize(), sub2ind(), octave_struct::subsasgn(), octave_cell::subsasgn(), and tree_evaluator::visit_simple_for_command().

void dim_vector::resize ( int  n,
int  fill_value = 0 
)
inline
octave_idx_type* dim_vector::resizerep ( int  n,
octave_idx_type  fill_value 
)
inlineprivate

Clone and resize this->rep to length n, filling by given value.

Definition at line 96 of file dim-vector.h.

octave_idx_type dim_vector::safe_numel ( void  ) const

The following function will throw a std::bad_alloc () exception if the requested size is larger than can be indexed by octave_idx_type. This may be smaller than the actual amount of memory that can be safely allocated on a system. However, if we don't fail here, we can end up with a mysterious crash inside a function that is iterating over an array using octave_idx_type indices.

Definition at line 93 of file dim-vector.cc.

References dim_max(), idx_max, length(), and rep.

Referenced by Array< T >::Array(), Array< T >::clear(), octave_base_sparse< SparseComplexMatrix >::numel(), Sparse< bool >::numel(), and Sparse< T >::Sparse().

dim_vector dim_vector::squeeze ( void  ) const

Definition at line 112 of file dim-vector.cc.

References dim_vector(), elem(), length(), and resize().

Referenced by octave_map::squeeze().

std::string dim_vector::str ( char  sep = 'x') const
octave_idx_type* dim_vector::to_jit ( void  ) const
inline

Definition at line 230 of file dim-vector.h.

Referenced by Array< octave_value >::jit_dimensions().

bool dim_vector::zero_by_zero ( void  ) const
inline

Friends And Related Function Documentation

bool operator== ( const dim_vector a,
const dim_vector b 
)
friend

Definition at line 519 of file dim-vector.h.

Member Data Documentation

octave_idx_type* dim_vector::rep
private

Definition at line 59 of file dim-vector.h.

Referenced by chop_all_singletons(), concat(), dim_vector(), hvcat(), redim(), and safe_numel().


The documentation for this class was generated from the following files: