This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <size_t dim = 0, class S> | |
auto data_offset(const S&) noexcept | |
{ | |
return typename S::value_type(0); | |
} | |
template <size_t dim = 0, class S, class I, class... Args> | |
auto data_offset(const S& strides, I i, Args... args) noexcept | |
{ | |
return i*strides[dim] + data_offset<dim + 1>(strides, args...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class I, class... Args> | |
auto sum(I i, Args... args) | |
{ | |
return i + sum(args...); | |
} | |
template <> | |
auto sum() | |
{ | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, layout_type L, class A> | |
template <class... I> | |
auto xarray<T, L, A>::operator()(I... i) -> reference | |
{ | |
size_type offset = data_offset(strides(), i...); | |
return m_storage[offset]; | |
} | |
template <class T, layout_type L, class A> | |
template <class... I> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xarray<double> xa; | |
xa.reshape({3, 2 ,4}); | |
double v0 = xa(1, 0, 2); | |
xarray<double> xa2; | |
xa2.reshape({2, 4}); | |
double v1 = xa2(1, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, layout_type L, class A> | |
class xarray | |
{ | |
public: | |
template <class... I> | |
reference operator()(I... i); | |
template <class... I> | |
const_reference operator()(I... i) const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, layout_type L, class A> | |
class xarray | |
{ | |
public: | |
reference operator()(); | |
reference operator()(size_type i0); | |
reference operator()(size_type i0, size_type i1); | |
reference operator()(size_type i0, size_type i1, size_type i2); | |
// ... etc ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xarray<double> xa; | |
std::vector<std::size_t> shape = { 3, 2, 4 }; | |
xa.reshape(shape); | |
double v = xa[1, 0, 2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class F, class... CT> | |
inline auto xfunction_iterator<F, CT...>::operator++() -> self_type& | |
{ | |
auto f = [](auto& it) { ++it; }; | |
for_each(f, m_it); | |
return *this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace detail | |
{ | |
template <std::size_t I, class F, class... T> | |
inline typename std::enable_if<I == sizeof...(T), void>::type | |
for_each_impl(F&& /*f*/, std::tuple<T...>& /*t*/) | |
{ | |
} | |
template <std::size_t I, class F, class... T> | |
inline typename std::enable_if<I < sizeof...(T), void>::type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class F, class... CT> | |
inline auto xfunction_iterator<F, CT...>::operator*() const -> reference | |
{ | |
return deref_impl(std::make_index_sequence<sizeof...(CT)>()); | |
} | |
template <class F, class... CT> | |
template <std::size_t... I> | |
inline auto xfunction_iterator<F, CT...>::deref_impl(std::index_sequence<I...>) const -> reference | |
{ |