28 #if ! defined (octave_dim_vector_h)
29 #define octave_dim_vector_h 1
31 #include "octave-config.h"
36 #include <initializer_list>
138 template <
typename... Ints>
141 : m_num_dims (2 + sizeof... (Ints)), m_dims (new
octave_idx_type [m_num_dims])
143 std::initializer_list<octave_idx_type> all_lengths = {
r, c, lengths...};
166 while (m_num_dims > 2 && xelem(m_num_dims-1) == 1)
175 : m_num_dims (ndims < 2 ? 2 : ndims), m_dims (new
octave_idx_type [m_num_dims])
177 std::fill_n (m_dims, m_num_dims, 0);
187 std::fill_n (m_dims, m_num_dims, 0);
191 : m_num_dims (dv.m_num_dims), m_dims (new
octave_idx_type [m_num_dims])
193 std::copy_n (dv.m_dims, m_num_dims, m_dims);
197 : m_num_dims (0), m_dims (nullptr)
199 *
this = std::move (dv);
213 m_num_dims = dv.m_num_dims;
216 std::copy_n (dv.m_dims, m_num_dims, m_dims);
232 m_num_dims = dv.m_num_dims;
288 std::copy_n (m_dims, m_num_dims, new_rep);
289 std::fill_n (new_rep + m_num_dims,
n - m_num_dims, fill_value);
298 OCTAVE_API std::string str (
char sep =
'x')
const;
302 return std::all_of (m_dims, m_dims + ndims (),
308 return ndims () == 2 && (xelem (0) == 0 || xelem (1) == 0);
313 return ndims () == 2 && xelem (0) == 0 && xelem (1) == 0;
318 return std::any_of (m_dims, m_dims + ndims (),
337 int n_dims = ndims ();
341 for (
int i =
n; i < n_dims; i++)
359 return std::any_of (m_dims, m_dims + ndims (),
381 if (ndims () == 2 && xelem (1) == 1)
389 if (ndims () == 2 && xelem (0) == 1)
397 return (ndims () == 2 && (xelem (0) == 1 || xelem (1) == 1));
404 for (
int i = 0; i < ndims (); i++)
415 return num_non_one == 1;
429 for (
int i = 0; i < orig_dims.
ndims (); i++)
431 if (orig_dims(i) != 1)
446 for (
int i = 0; i < ndims (); i++)
463 for (
int i = nidx - 1; i >= 0; i--)
464 k = xelem(i) * k + idx[i];
476 for (i = start; i < ndims (); i++)
478 if (++(*idx) == xelem(i))
494 for (
int i = 0; i < nd; i++)
495 retval.
xelem(i) = (k *= xelem(i));
507 for (
int i = 1; i < ndims (); i++)
508 k += xelem(i-1) * idx[i];
523 if (a.m_dims == b.m_dims)
526 int a_len = a.
ndims ();
527 int b_len = b.
ndims ();
532 return std::equal (a.m_dims, a.m_dims + a_len, b.m_dims);
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
octave_idx_type num_ones(const Array< octave_idx_type > &ra_idx)
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Vector representing the dimensions (size) of an Array.
octave_idx_type compute_index(const octave_idx_type *idx) const
Linear index from an index tuple.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void chop_trailing_singletons()
void resize(int n, int fill_value=0)
dim_vector(const octave_idx_type r, const octave_idx_type c, Ints... lengths)
Construct dim_vector for a N dimensional array.
static dim_vector alloc(int n)
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...
bool is_nd_vector() const
octave_idx_type ndims() const
Number of dimensions.
bool zero_by_zero() const
octave_idx_type elem(int i) const
dim_vector cumulative() const
Return cumulative dimensions.
dim_vector(const dim_vector &dv)
octave_idx_type cum_compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
octave_idx_type & xelem(int i)
int first_non_singleton(int def=0) const
octave_idx_type compute_index(const octave_idx_type *idx, int nidx) const
Linear index from an incomplete index tuple (nidx < length ()).
octave_idx_type xelem(int i) const
dim_vector(dim_vector &&dv)
dim_vector as_column() const
octave_idx_type & elem(int i)
dim_vector as_row() const
int length() const
Number of dimensions.
dim_vector make_nd_vector(octave_idx_type n) const
bool operator!=(const dim_vector &a, const dim_vector &b)
bool operator==(const dim_vector &a, const dim_vector &b)
T::size_type numel(const T &str)