Add util::array::subarray
This commit is contained in:
parent
e4fcf82f70
commit
769b5786ae
1 changed files with 20 additions and 0 deletions
|
|
@ -118,6 +118,7 @@ namespace psemek::util
|
||||||
T const & operator()(std::initializer_list<I> const & index) const;
|
T const & operator()(std::initializer_list<I> const & index) const;
|
||||||
|
|
||||||
array copy() const;
|
array copy() const;
|
||||||
|
array subarray(dims_type const & start, dims_type const & end) const;
|
||||||
|
|
||||||
void resize(dims_type const & dims);
|
void resize(dims_type const & dims);
|
||||||
|
|
||||||
|
|
@ -383,6 +384,25 @@ namespace psemek::util
|
||||||
return array{dims_, std::move(data)};
|
return array{dims_, std::move(data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, std::size_t N>
|
||||||
|
array<T, N> array<T, N>::subarray(dims_type const & start, dims_type const & end) const
|
||||||
|
{
|
||||||
|
dims_type size;
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
size[i] = end[i] - start[i];
|
||||||
|
|
||||||
|
array<T, N> result(size);
|
||||||
|
for (auto const & idx : result.indices())
|
||||||
|
{
|
||||||
|
auto jdx = idx;
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
jdx[i] += start[i];
|
||||||
|
result(idx) = (*this)(jdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
void array<T, N>::resize(dims_type const & dims)
|
void array<T, N>::resize(dims_type const & dims)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue