Vector representing the dimensions (size) of an Array. More...
#include "dim-vector.h"
Public Member Functions | |
| dim_vector () | |
| dim_vector (const dim_vector &dv) | |
| 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. | |
| dim_vector (dim_vector &&dv) | |
| ~dim_vector () | |
| bool | all_ones () const |
| bool | all_zero () const |
| bool | any_neg () const |
| bool | any_zero () const |
| Array< octave_idx_type > | as_array () const |
| dim_vector | as_column () const |
| dim_vector | as_row () const |
| void | chop_all_singletons () |
| void | chop_trailing_singletons () |
| octave_idx_type | compute_index (const octave_idx_type *idx) const |
| Linear index from an index tuple. | |
| octave_idx_type | compute_index (const octave_idx_type *idx, int nidx) const |
| Linear index from an incomplete index tuple (nidx < length ()). | |
| bool | concat (const dim_vector &dvb, int dim) |
| This corresponds to cat(). | |
| octave_idx_type | cum_compute_index (const octave_idx_type *idx) const |
| Compute a linear index from an index tuple. | |
| dim_vector | cumulative () const |
| Return cumulative dimensions. | |
| octave_idx_type & | elem (int i) |
| octave_idx_type | elem (int i) const |
| bool | empty_2d () 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). | |
| int | increment_index (octave_idx_type *idx, int start=0) const |
| Increment a multi-dimensional index tuple, optionally starting from an offset position and return the index of the last index position that was changed, or length () if just cycled over. | |
| bool | is_nd_vector () const |
| bool | isvector () const |
| int | length () const |
| Number of dimensions. | |
| dim_vector | make_nd_vector (octave_idx_type n) const |
| octave_idx_type | ndims () const |
| Number of dimensions. | |
| int | num_ones () const |
| octave_idx_type | numel (int n=0) const |
| Number of elements that a matrix with this dimensions would have. | |
| octave_idx_type & | operator() (int i) |
| octave_idx_type | operator() (int i) const |
| dim_vector & | operator= (const dim_vector &dv) |
| dim_vector & | operator= (dim_vector &&dv) |
| dim_vector | redim (int n) const |
| Force certain dimensionality, preserving numel (). | |
| void | resize (int n, int fill_value=0) |
| octave_idx_type | safe_numel () 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. | |
| dim_vector | squeeze () const |
| std::string | str (char sep='x') const |
| octave_idx_type & | xelem (int i) |
| octave_idx_type | xelem (int i) const |
| bool | zero_by_zero () const |
Static Public Member Functions | |
| static dim_vector | alloc (int n) |
| static constexpr octave_idx_type | dim_max () |
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 91 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, ![$[7, 5]$](../../form_0.png)
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:
![$[N, 1]$](../../form_1.png)
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 137 of file dim-vector.h.
|
inlineexplicit |
Definition at line 190 of file dim-vector.h.
Referenced by hvcat().
|
inline |
Definition at line 196 of file dim-vector.h.
|
inline |
Definition at line 202 of file dim-vector.h.
|
inline |
Definition at line 248 of file dim-vector.h.
|
inline |
Definition at line 330 of file dim-vector.h.
References num_ones().
Referenced by octave_value_list::all_scalars(), Finputname(), octave_base_diag< DMT, MT >::print_as_scalar(), octave_base_matrix< MT >::print_as_scalar(), octave_base_sparse< T >::print_as_scalar(), and octave_perm_matrix::print_as_scalar().
|
inline |
Definition at line 306 of file dim-vector.h.
Referenced by octave_map::concat(), and Ffind().
|
inlinestatic |
Definition at line 208 of file dim-vector.h.
Referenced by Array< T, Alloc >::assign(), do_mat2cell(), do_mat2cell_nd(), F__base64_decode_bytes__(), Fbase64_decode(), Freshape(), Fvec(), Array< T, Alloc >::index(), Array< T, Alloc >::permute(), redim(), and zero_dims_inquire().
|
inline |
Definition at line 394 of file dim-vector.h.
Referenced by Array< T, Alloc >::resize().
|
inline |
Definition at line 322 of file dim-vector.h.
Referenced by Farrayfun(), Fcellfun(), octave_base_diag< DMT, MT >::print_as_scalar(), octave_base_matrix< MT >::print_as_scalar(), octave_base_sparse< T >::print_as_scalar(), and octave_perm_matrix::print_as_scalar().
| Array< octave_idx_type > dim_vector::as_array | ( | ) | const |
Definition at line 237 of file dim-vector.cc.
References elem(), and ndims().
Referenced by octave_base_value::dump(), and octave_classdef::reshape().
|
inline |
|
inline |
| void dim_vector::chop_all_singletons | ( | ) |
Definition at line 40 of file dim-vector.cc.
References ndims(), and xelem().
Referenced by Array< T, Alloc >::assign(), Array< T, Alloc >::assign(), squeeze(), zero_dims_inquire(), and zero_dims_inquire().
|
inline |
Definition at line 162 of file dim-vector.h.
Referenced by Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Array< T, Alloc >::assign(), Array< T, Alloc >::clear(), concat(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_red_op(), do_mx_red_op(), Fcell(), Frandi(), and octave_map::reshape().
|
inline |
Linear index from an index tuple.
Definition at line 493 of file dim-vector.h.
References compute_index().
Referenced by compute_index(), do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inline |
Linear index from an incomplete index tuple (nidx < length ()).
Definition at line 497 of file dim-vector.h.
| bool dim_vector::concat | ( | const dim_vector & | dvb, |
| int | dim | ||
| ) |
This corresponds to cat().
Definition at line 111 of file dim-vector.cc.
References chop_trailing_singletons(), ndims(), resize(), and xelem().
Referenced by Array< T, Alloc >::cat(), octave_map::cat(), Sparse< T, Alloc >::cat(), and hvcat().
|
inline |
Compute a linear index from an index tuple.
Dimensions are required to be cumulative.
Definition at line 540 of file dim-vector.h.
Referenced by do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inline |
Return cumulative dimensions.
Definition at line 525 of file dim-vector.h.
References xelem().
Referenced by do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), and do_inplace_bsxfun_op().
|
inlinestaticconstexpr |
Definition at line 185 of file dim-vector.h.
Referenced by Fsizemax().
|
inline |
Definition at line 155 of file dim-vector.h.
Referenced by as_array(), and squeeze().
|
inline |
Definition at line 160 of file dim-vector.h.
|
inline |
Definition at line 312 of file dim-vector.h.
Definition at line 481 of file dim-vector.h.
Referenced by Fcellslices(), Fcumsum(), Fdot(), Ffilter(), filter(), Fnth_element(), Fsort(), get_extent_triplet(), MArray< T >::idx_add_nd(), SparseComplexMatrix::max(), SparseMatrix::max(), SparseComplexMatrix::min(), and SparseMatrix::min().
| bool dim_vector::hvcat | ( | const dim_vector & | dvb, |
| int | dim | ||
| ) |
This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1).
Definition at line 172 of file dim-vector.cc.
References dim_vector(), concat(), ndims(), and xelem().
Referenced by Array< T, Alloc >::cat(), and Sparse< T, Alloc >::cat().
|
inline |
Increment a multi-dimensional index tuple, optionally starting from an offset position and return the index of the last index position that was changed, or length () if just cycled over.
Definition at line 510 of file dim-vector.h.
Referenced by do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), do_inplace_bsxfun_op(), do_mat2cell(), and do_mat2cell_nd().
|
inline |
Definition at line 437 of file dim-vector.h.
Referenced by Array< octave_value >::index(), and Array< T, Alloc >::is_nd_vector().
|
inline |
Definition at line 432 of file dim-vector.h.
Referenced by Fdot(), Ffind(), Fissorted(), get_dimensions(), range< T, typename std::enable_if< std::is_floating_point< T >::value >::type >::index(), Array< T, Alloc >::isvector(), and idx_vector::isvector().
|
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 272 of file dim-vector.h.
Referenced by Fsub2ind().
|
inline |
Definition at line 458 of file dim-vector.h.
References ndims().
|
inline |
Number of dimensions.
Returns the number of dimensions of the dim_vector. This is number of elements in the dim_vector including trailing singletons. It is also the number of dimensions an Array with this dim_vector would have.
Definition at line 263 of file dim-vector.h.
Referenced by Sparse< T, Alloc >::Sparse(), Sparse< T, Alloc >::Sparse(), all_colon_equiv(), as_array(), Array< T, Alloc >::as_column(), Array< T, Alloc >::as_matrix(), Array< T, Alloc >::as_row(), Array< T, Alloc >::assign(), Array< T, Alloc >::assign(), Array< T, Alloc >::cat(), check_dimensions(), chop_all_singletons(), octave_uint64_matrix::complex_matrix_value(), Array< octave_value >::compute_index(), concat(), Array< T, Alloc >::diag(), Array< T, Alloc >::dim3(), do_mx_diff_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_minmax_op(), do_mx_red_op(), do_mx_red_op(), octave_base_diag< ComplexDiagMatrix, ComplexMatrix >::fast_elem_extract(), Fbsxfun(), Fcellslices(), Fcumsum(), Fellipj(), Ffilter(), filter(), filter(), Flinspace(), octave_uint64_matrix::float_complex_matrix_value(), octave_uint64_matrix::float_matrix_value(), ComplexNDArray::fourier(), NDArray::fourier(), FloatComplexNDArray::fourier(), FloatNDArray::fourier(), ComplexNDArray::fourier2d(), NDArray::fourier2d(), FloatComplexNDArray::fourier2d(), FloatNDArray::fourier2d(), ComplexNDArray::fourierNd(), NDArray::fourierNd(), FloatComplexNDArray::fourierNd(), FloatNDArray::fourierNd(), freeze(), Fsize(), Fstruct2cell(), get_extent_triplet(), get_ra_idx(), hvcat(), ComplexNDArray::ifourier(), NDArray::ifourier(), FloatComplexNDArray::ifourier(), FloatNDArray::ifourier(), ComplexNDArray::ifourier2d(), NDArray::ifourier2d(), FloatComplexNDArray::ifourier2d(), FloatNDArray::ifourier2d(), ComplexNDArray::ifourierNd(), NDArray::ifourierNd(), FloatComplexNDArray::ifourierNd(), FloatNDArray::ifourierNd(), increment_index(), ind2sub(), index_in_bounds(), ComplexNDArray::insert(), FloatComplexNDArray::insert(), is_scalar(), is_valid_bsxfun(), is_valid_inplace_bsxfun(), isvector(), isvector(), make_nd_vector(), octave_uint64_matrix::matrix_value(), SparseComplexMatrix::max(), SparseMatrix::max(), SparseComplexMatrix::min(), SparseMatrix::min(), Array< T, Alloc >::ndims(), Sparse< T, Alloc >::ndims(), num_ones(), operator<<(), Array< T, Alloc >::permute(), octave_classdef::print_raw(), redim(), Sparse< T, Alloc >::reshape(), Sparse< T, Alloc >::resize(), Array< T, Alloc >::resize(), octave_base_int_matrix< T >::save_ascii(), octave_bool_matrix::save_ascii(), octave_cell::save_ascii(), octave_classdef::save_ascii(), octave_complex_matrix::save_ascii(), octave_float_complex_matrix::save_ascii(), octave_float_matrix::save_ascii(), octave_matrix::save_ascii(), octave_char_matrix_str::save_ascii(), octave_struct::save_ascii(), octave_scalar_struct::save_ascii(), octave_bool_matrix::save_binary(), octave_sparse_bool_matrix::save_binary(), octave_cell::save_binary(), octave_complex_matrix::save_binary(), octave_sparse_complex_matrix::save_binary(), octave_float_complex_matrix::save_binary(), octave_float_matrix::save_binary(), octave_matrix::save_binary(), octave_sparse_matrix::save_binary(), octave_char_matrix_str::save_binary(), octave_struct::save_binary(), octave_base_int_matrix< T >::save_binary(), save_binary_data(), octave_bool_matrix::save_hdf5(), octave_cell::save_hdf5(), octave_complex_matrix::save_hdf5(), octave_float_complex_matrix::save_hdf5(), octave_float_matrix::save_hdf5(), octave_matrix::save_hdf5(), octave_char_matrix_str::save_hdf5(), octave_base_int_matrix< T >::save_hdf5_internal(), save_mat5_element_length(), octave_base_value::size(), octave_class::size(), octave_lazy_index::sort(), octave_lazy_index::sort(), squeeze(), str(), vector_equivalent(), zero_dims_inquire(), and zero_dims_inquire().
| int dim_vector::num_ones | ( | ) | const |
Definition at line 76 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 341 of file dim-vector.h.
Referenced by airy(), airy(), biry(), biry(), compute_index(), compute_index(), compute_index(), octave_float_matrix::convert_to_str_internal(), octave_matrix::convert_to_str_internal(), octave_sparse_matrix::convert_to_str_internal(), octave_base_int_matrix< T >::convert_to_str_internal(), dims_to_numel(), do_bessel(), do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), do_inplace_bsxfun_op(), do_mat2cell(), do_mat2cell_nd(), do_randi_array< bool >(), Fbsxfun(), Fcellfun(), fftw::fftNd(), fftw::fftNd(), filter(), Fregexprep(), Freshape(), get_dimensions(), get_extent_triplet(), get_ra_idx(), fftw::ifftNd(), fftw::ifftNd(), ind2sub(), octave_base_matrix< MT >::is_true(), octave_perm_matrix::is_true(), octave_cell::load_ascii(), octave_classdef::load_ascii(), octave_char_matrix_str::load_ascii(), octave_bool_matrix::load_binary(), octave_cell::load_binary(), octave_complex_matrix::load_binary(), octave_float_complex_matrix::load_binary(), octave_float_matrix::load_binary(), octave_matrix::load_binary(), octave_char_matrix_str::load_binary(), octave_base_int_matrix< T >::load_binary(), octave_bool_matrix::load_hdf5(), octave_cell::load_hdf5(), load_mcos_object(), octave_class::numel(), octave_print_internal(), read_mat5_binary_element(), cdef_object_scalar::reshape(), Sparse< T, Alloc >::reshape(), cdef_object_scalar::resize(), octave_bool::resize(), octave_complex::resize(), octave_float_scalar::resize(), octave_float_complex::resize(), octave_uint64_scalar::resize(), octave_scalar::resize(), octave_cell::save_ascii(), octave_char_matrix_str::save_ascii(), octave_cell::save_binary(), octave_complex_matrix::save_binary(), octave_float_complex_matrix::save_binary(), octave_float_matrix::save_binary(), octave_matrix::save_binary(), octave_char_matrix_str::save_binary(), octave_cell::save_hdf5(), octave_char_matrix_str::save_hdf5(), save_mat5_binary_element(), subsystem_handler::set_mcos_object_metadata(), Array< T, Alloc >::sort(), octave_cell::subsasgn(), and octave_struct::subsasgn().
|
inline |
Definition at line 274 of file dim-vector.h.
|
inline |
Definition at line 276 of file dim-vector.h.
|
inline |
Definition at line 213 of file dim-vector.h.
|
inline |
Definition at line 228 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 2-D and the second dim is 1 (dim_vectors are always at least 2-D).
Definition at line 197 of file dim-vector.cc.
References alloc(), ndims(), and xelem().
Referenced by Array< T, Alloc >::as_matrix(), Array< octave_value >::assign(), Array< T, Alloc >::assign(), Array< T, Alloc >::assign(), octave_base_matrix< MT >::assign(), compute_index(), dims_to_numel(), do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), do_inplace_bsxfun_op(), Fcell2struct(), Fdot(), Array< octave_value >::find(), Find2sub(), Fsize(), MArray< T >::idx_add_nd(), Array< T, Alloc >::index(), Sparse< T, Alloc >::index(), Array< T, Alloc >::index(), Array< T, Alloc >::insert(), Array< T, Alloc >::resize(), sub2ind(), octave_cell::subsasgn(), octave_struct::subsasgn(), and tree_evaluator::visit_simple_for_command().
Definition at line 278 of file dim-vector.h.
Referenced by octave_map::cat(), concat(), Array< T, Alloc >::delete_elements(), do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), do_mx_diff_op(), Fbsxfun(), Fcell(), Fcell2struct(), Frandi(), freeze(), Fresize(), Fstruct2cell(), get_dimensions(), octave_base_int_matrix< T >::load_ascii(), octave_bool_matrix::load_ascii(), octave_cell::load_ascii(), octave_classdef::load_ascii(), octave_complex_matrix::load_ascii(), octave_float_complex_matrix::load_ascii(), octave_float_matrix::load_ascii(), octave_matrix::load_ascii(), octave_char_matrix_str::load_ascii(), octave_struct::load_ascii(), octave_bool_matrix::load_binary(), octave_cell::load_binary(), octave_complex_matrix::load_binary(), octave_float_complex_matrix::load_binary(), octave_float_matrix::load_binary(), octave_matrix::load_binary(), octave_char_matrix_str::load_binary(), octave_struct::load_binary(), octave_base_int_matrix< T >::load_binary(), octave_bool_matrix::load_hdf5(), octave_cell::load_hdf5(), octave_complex_matrix::load_hdf5(), octave_float_complex_matrix::load_hdf5(), octave_float_matrix::load_hdf5(), octave_matrix::load_hdf5(), octave_char_matrix_str::load_hdf5(), octave_base_int_matrix< T >::load_hdf5_internal(), load_mcos_object(), Array< T, Alloc >::permute(), read_mat5_binary_element(), Sparse< T, Alloc >::reshape(), Array< T, Alloc >::squeeze(), and zero_dims_inquire().
|
inline |
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 364 of file dim-vector.h.
Referenced by Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), Sparse< T, Alloc >::Sparse(), Array< T, Alloc >::clear(), octave_base_sparse< T >::numel(), and Sparse< T, Alloc >::numel().
| dim_vector dim_vector::squeeze | ( | ) | const |
Definition at line 88 of file dim-vector.cc.
References as_row(), chop_all_singletons(), elem(), ndims(), and xelem().
Referenced by octave_map::squeeze().
| std::string dim_vector::str | ( | char | sep = 'x' | ) | const |
Definition at line 58 of file dim-vector.cc.
References ndims(), and xelem().
Referenced by Array< T, Alloc >::Array(), Array< T, Alloc >::Array(), do_bsxfun1_op(), do_bsxfun2_op(), do_bsxfun_op(), octave_char_matrix_str::edit_display(), octave_struct::edit_display(), octave_scalar_struct::edit_display(), err_nonconformant(), operator<<(), octave_cell::print_raw(), octave_classdef::print_raw(), octave_struct::print_raw(), octave_scalar_struct::print_raw(), cdef_object_scalar::reshape(), Sparse< T, Alloc >::reshape(), octave_base_value::short_disp(), and warn_array_as_logical().
|
inline |
Definition at line 149 of file dim-vector.h.
Referenced by chop_all_singletons(), concat(), cumulative(), hvcat(), num_ones(), redim(), squeeze(), and str().
|
inline |
Definition at line 151 of file dim-vector.h.
|
inline |
Definition at line 317 of file dim-vector.h.
Referenced by Array< T, Alloc >::assign(), Array< T, Alloc >::assign(), Array< T, Alloc >::cat(), and tm_row_const::cellify().
|
friend |
Definition at line 557 of file dim-vector.h.