GNU Octave
4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
|
Vector representing the dimensions (size) of an Array. More...
#include "dim-vector.h"
Public Member Functions | |
template<typename... Ints> | |
dim_vector (const octave_idx_type r, const octave_idx_type c, Ints...lengths) | |
Construct dim_vector for a N 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 |
Linear index from an index tuple. More... | |
octave_idx_type | compute_index (const octave_idx_type *idx, int nidx) const |
Linear index from an incomplete index tuple (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_type & | elem (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 |
Number of dimensions. More... | |
octave_idx_type | ndims (void) const |
Number of dimensions. More... | |
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_type & | operator() (int i) |
octave_idx_type | operator() (int i) const |
dim_vector & | operator= (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_type * | to_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_type * | clonerep (void) |
Clone this->rep. More... | |
octave_idx_type & | count (void) const |
void | freerep (void) |
Free the rep. More... | |
void | make_unique (void) |
octave_idx_type * | resizerep (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_type * | newrep (int ndims) |
Construct a new rep with count = 1 and ndims given. More... | |
static octave_idx_type * | nil_rep (void) |
Private Attributes | |
octave_idx_type * | rep |
Friends | |
bool | operator== (const dim_vector &a, const dim_vector &b) |
Vector representing the dimensions (size) of an Array.
A dim_vector is used to represent dimensions of an Array. It is used on its constructor to specify its size, or when reshaping it.
The main thing to understand about this class, is that methods such as ndims() and numel(), return the value for an Array of these dimensions, not the actual number of elements in the dim_vector.
This implementation is more tricky than Array, but the big plus is that dim_vector requires only one allocation instead of two. It is (slightly) patterned after GCC's basic_string implementation. rep is a pointer to an array of memory, comprising count, length, and the data:
<count> <ndims> rep --> <dims[0]> <dims[1]> ...
The inlines count(), ndims() recover this data from the rep. Note that rep points to the beginning of dims to grant faster access (reinterpret_cast is assumed to be an inexpensive operation).
Definition at line 87 of file dim-vector.h.
|
inline |
Construct dim_vector for a N dimensional array.
Each argument to constructor defines the length of an additional dimension. A dim_vector always represents a minimum of 2 dimensions (just like an Array has at least 2 dimensions) and there is no upper limit on the number of dimensions.
The constructed dim_vector dv
will have two elements, , one for each dimension. It can then be used to construct a Matrix with such dimensions, i.e., 7 rows and 5 columns.
This will construct a 3 dimensional NDArray of lengths 7, 5, and 10, on the first, second, and third dimension (rows, columns, and pages) respectively.
Note that that there is no constructor that accepts only one dimension length to avoid confusion. The source for such confusion is that constructor could mean:
Using r, c, and lengths... as arguments, allow us to check at compile time that there's at least 2 dimensions specified, while maintaining type safety.
Definition at line 206 of file dim-vector.h.
References c.
|
inlineexplicit |
Definition at line 261 of file dim-vector.h.
References OCTAVE_ATOMIC_INCREMENT.
|
inline |
Definition at line 264 of file dim-vector.h.
References OCTAVE_ATOMIC_INCREMENT.
|
inlineexplicit |
Definition at line 268 of file dim-vector.h.
|
inline |
Definition at line 289 of file dim-vector.h.
References OCTAVE_ATOMIC_DECREMENT.
|
inline |
Definition at line 377 of file dim-vector.h.
References Sparse< bool >::ndims(), and num_ones().
Referenced by octave_value_list::all_scalars(), octave_base_sparse< T >::print_as_scalar(), octave_base_matrix< MT >::print_as_scalar(), octave_base_diag< DMT, MT >::print_as_scalar(), and octave_perm_matrix::print_as_scalar().
|
inline |
Definition at line 333 of file dim-vector.h.
References elem, Sparse< bool >::ndims(), and retval.
Referenced by octave_map::concat(), do_fft2(), do_fftn(), octave_rand::do_float_nd_array(), octave_rand::do_nd_array(), idx_vector::idx_mask_rep::idx_mask_rep(), idx_vector::idx_vector_rep::idx_vector_rep(), oct_catop_matrix_struct(), and oct_catop_struct_matrix().
|
inlinestatic |
Definition at line 270 of file dim-vector.h.
Referenced by Array< T >::assign(), convolve(), symbol_table::do_workspace_info(), get_dims_str(), get_red_dims(), Array< T >::index(), Array< T >::permute(), redim(), patch::properties::update_data(), and zero_dims_inquire().
|
inline |
Definition at line 413 of file dim-vector.h.
References elem, and Sparse< bool >::ndims().
Referenced by Array< T >::resize().
|
inline |
Definition at line 359 of file dim-vector.h.
References elem, Sparse< bool >::ndims(), and retval.
Referenced by do_fft(), octave_base_sparse< T >::print_as_scalar(), octave_base_matrix< MT >::print_as_scalar(), octave_base_diag< DMT, MT >::print_as_scalar(), octave_perm_matrix::print_as_scalar(), print_empty_nd_array(), and single_type_concat().
|
inline |
Definition at line 442 of file dim-vector.h.
References elem, Sparse< bool >::ndims(), and numel().
|
inline |
Definition at line 450 of file dim-vector.h.
References elem, Sparse< bool >::ndims(), and numel().
void dim_vector::chop_all_singletons | ( | void | ) |
Definition at line 53 of file dim-vector.cc.
References make_unique(), ndims(), and rep.
Referenced by Array< T >::assign(), and zero_dims_inquire().
|
inline |
Definition at line 232 of file dim-vector.h.
References Sparse< bool >::make_unique(), and Sparse< bool >::ndims().
Referenced by Array< octave_value >::Array(), Array< T >::Array(), Array< T >::assign(), Array< T >::clear(), concat(), do_mx_minmax_op(), do_rand(), Array< T >::index(), and make_vector_dims().
|
inlineprivate |
|
inline |
Linear index from an index tuple.
Definition at line 475 of file dim-vector.h.
References compute_index(), and Sparse< bool >::ndims().
Referenced by compute_index(), Array< octave_value >::compute_index_unchecked(), do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inline |
Linear index from an incomplete index tuple (nidx < length ()).
Definition at line 479 of file dim-vector.h.
References k.
bool dim_vector::concat | ( | const dim_vector & | dvb, |
int | dim | ||
) |
This corresponds to cat().
Definition at line 187 of file dim-vector.cc.
References chop_trailing_singletons(), make_unique(), ndims(), rep, and resize().
Referenced by octave_map::cat(), Sparse< T >::cat(), Array< T >::cat(), and hvcat().
|
inlineprivate |
Definition at line 95 of file dim-vector.h.
|
inline |
Compute a linear index from an index tuple.
Dimensions are required to be cumulative.
Definition at line 524 of file dim-vector.h.
References k, and Sparse< bool >::ndims().
Referenced by do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inline |
Return cumulative dimensions.
Definition at line 509 of file dim-vector.h.
References k, Sparse< bool >::ndims(), rep, and retval.
Referenced by convolve(), do_bsxfun_op(), and do_inplace_bsxfun_op().
|
static |
|
inline |
Definition at line 215 of file dim-vector.h.
References Sparse< bool >::make_unique(), and Sparse< bool >::ndims().
Referenced by tm_const::cols(), num_ones(), tm_const::rows(), squeeze(), and str().
|
inline |
Definition at line 224 of file dim-vector.h.
References Sparse< bool >::ndims().
|
inline |
Definition at line 349 of file dim-vector.h.
References elem, and Sparse< bool >::ndims().
Definition at line 463 of file dim-vector.h.
References elem, and Sparse< bool >::ndims().
Referenced by do_fft(), Ffilter(), filter(), MArray< T >::idx_add_nd(), SparseMatrix::max(), SparseComplexMatrix::max(), SparseMatrix::min(), and SparseComplexMatrix::min().
|
inlineprivate |
Free the rep.
Definition at line 148 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 250 of file dim-vector.cc.
References concat(), dim_vector(), ndims(), and rep.
Referenced by Sparse< T >::cat(), Array< T >::cat(), tm_row_const::tm_row_const_rep::cellify(), tm_row_const::tm_row_const_rep::init(), and tm_const::init().
|
inline |
Definition at line 494 of file dim-vector.h.
References Sparse< bool >::ndims(), and start.
Referenced by do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inline |
Definition at line 458 of file dim-vector.h.
References elem, and Sparse< bool >::ndims().
Referenced by Range::index(), Array< T >::index(), Array< octave_value >::is_vector(), idx_vector::is_vector(), and unbox().
|
inline |
Number of dimensions.
Synonymous with ndims().
While this method is not officially deprecated, consider using ndims() instead to avoid confusion. Array does not have length because of its odd definition as length of the longest dimension.
Definition at line 310 of file dim-vector.h.
References Sparse< bool >::ndims().
Referenced by jit_operation::add_overload(), jit_operation::overload(), and save_hdf5_empty().
|
inlineprivate |
Definition at line 154 of file dim-vector.h.
References OCTAVE_ATOMIC_DECREMENT.
Referenced by chop_all_singletons(), and concat().
|
inline |
Number of dimensions.
Returns the number of dimensions of the dim_vector. This is number of elements in the dim_vector including trailing singetons. It is also the number of dimensions an Array with this dim_vector would have.
Definition at line 301 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(), box(), Array< T >::cat(), chop_all_singletons(), OCTAVE_VALUE_INT_MATRIX_T::complex_matrix_value(), compute_array_dimensions(), concat(), convert_cdata(), convert_packcomplex_Nd(), octave::opengl_texture::create(), octave::out_of_range::details(), Array< T >::diag(), do_fft(), do_fft2(), do_fftn(), do_mx_minmax_op(), do_trilu(), symbol_table::do_workspace_info(), octave::opengl_renderer::draw_image(), Fellipj(), Ffilter(), filter(), 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(), 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(), QtHandles::Utils::makeImageFromCData(), OCTAVE_VALUE_INT_MATRIX_T::matrix_value(), SparseMatrix::max(), SparseComplexMatrix::max(), maybe_update_column(), SparseMatrix::min(), SparseComplexMatrix::min(), Sparse< bool >::ndims(), Array< octave_value >::ndims(), num_ones(), operator<<(), 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(), 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(), unbox(), update_index(), array_property::validate(), vector_equivalent(), and zero_dims_inquire().
|
inlinestaticprivate |
Construct a new rep with count = 1 and ndims given.
Definition at line 99 of file dim-vector.h.
References Sparse< bool >::ndims().
|
staticprivate |
Definition at line 36 of file dim-vector.cc.
References rep.
int dim_vector::num_ones | ( | void | ) | const |
Definition at line 91 of file dim-vector.cc.
|
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 389 of file dim-vector.h.
References elem, Sparse< bool >::ndims(), and retval.
Referenced by octave::math::airy(), octave::math::betainc(), octave::math::betaincinv(), octave::math::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(), do_bessel(), octave::math::do_bessel(), do_bsxfun_op(), do_inplace_bsxfun_op(), octave_fftw::fftNd(), filter(), octave::math::gammainc(), get_ra_idx(), octave_fftw::ifftNd(), ind2sub(), octave_perm_matrix::is_true(), octave_base_sparse< T >::is_true(), octave_base_matrix< MT >::is_true(), octave_range::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_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().
|
inline |
Definition at line 312 of file dim-vector.h.
References elem.
|
inline |
Definition at line 314 of file dim-vector.h.
References elem.
|
inline |
Definition at line 275 of file dim-vector.h.
References OCTAVE_ATOMIC_DECREMENT, OCTAVE_ATOMIC_INCREMENT, and rep.
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 275 of file dim-vector.cc.
References alloc(), for(), k, ndims(), rep, and retval.
Referenced by Array< octave_value >::as_matrix(), Array< T >::assign(), compute_index(), convolve(), do_bsxfun_op(), do_inplace_bsxfun_op(), MArray< T >::idx_add_nd(), Sparse< T >::index(), Array< T >::index(), Array< T >::insert(), Array< T >::resize(), sub2ind(), octave_struct::subsasgn(), octave_cell::subsasgn(), and octave::tree_evaluator::visit_simple_for_command().
Definition at line 316 of file dim-vector.h.
References Sparse< bool >::ndims(), and OCTAVE_ATOMIC_DECREMENT.
Referenced by jit_operation::add_overload(), box(), octave_map::cat(), compute_array_dimensions(), concat(), convert_cdata(), mxArray_matlab::dims_to_dim_vector(), do_bsxfun_op(), octave_map::do_cat(), do_rand(), freeze(), get_dim_vector(), octave_base_int_matrix< T >::load_ascii(), octave_struct::load_ascii(), octave_float_complex_matrix::load_ascii(), octave_char_matrix_str::load_ascii(), octave_complex_matrix::load_ascii(), octave_cell::load_ascii(), octave_float_matrix::load_ascii(), octave_bool_matrix::load_ascii(), octave_matrix::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_base_int_matrix< T >::load_hdf5(), octave_float_complex_matrix::load_hdf5(), octave_char_matrix_str::load_hdf5(), octave_complex_matrix::load_hdf5(), octave_cell::load_hdf5(), octave_float_matrix::load_hdf5(), octave_bool_matrix::load_hdf5(), octave_matrix::load_hdf5(), load_hdf5_empty(), Array< T >::permute(), read_mat5_binary_element(), Sparse< T >::reshape(), Array< T >::sort(), squeeze(), Array< T >::squeeze(), and zero_dims_inquire().
|
inlineprivate |
Clone and resize this->rep to length n, filling by given value.
Definition at line 125 of file dim-vector.h.
References Sparse< bool >::ndims().
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 103 of file dim-vector.cc.
References dim_max(), idx_max, ndims(), and rep.
Referenced by Array< T >::Array(), Array< T >::clear(), Sparse< bool >::numel(), and Sparse< T >::Sparse().
dim_vector dim_vector::squeeze | ( | void | ) | const |
Definition at line 122 of file dim-vector.cc.
References dim_vector(), elem(), k, ndims(), resize(), and tmp.
Referenced by octave_map::squeeze().
std::string dim_vector::str | ( | char | sep = 'x' | ) | const |
Definition at line 73 of file dim-vector.cc.
References elem(), ndims(), retval, and string.
Referenced by Array< T >::Array(), octave::out_of_range::details(), do_bsxfun_op(), symbol_table::do_workspace_info(), octave_base_value::dump(), octave::math::err_betainc_nonconformant(), octave::math::err_betaincinv_nonconformant(), octave::err_nonconformant(), eval_error(), octave::math::gammainc(), get_dims_str(), gripe_nonconformant(), operator<<(), print_empty_nd_array(), octave_struct::print_raw(), octave_cell::print_raw(), octave_scalar_struct::print_raw(), Sparse< T >::reshape(), and warn_array_as_logical().
|
inline |
Definition at line 248 of file dim-vector.h.
References Sparse< bool >::rep.
Referenced by Array< octave_value >::jit_dimensions().
|
inline |
Definition at line 354 of file dim-vector.h.
References elem, and Sparse< bool >::ndims().
Referenced by Array< T >::assign(), Array< T >::cat(), tm_row_const::tm_row_const_rep::cellify(), tm_row_const::tm_row_const_rep::do_init_element(), and tm_row_const::tm_row_const_rep::init().
|
friend |
Definition at line 538 of file dim-vector.h.
|
private |
Definition at line 93 of file dim-vector.h.
Referenced by chop_all_singletons(), concat(), cumulative(), hvcat(), nil_rep(), operator=(), operator==(), redim(), and safe_numel().