feat(math): add size() and data() to tensor view
This commit is contained in:
@@ -87,6 +87,26 @@ private:
|
||||
else
|
||||
return (calculate_offset_impl<I - 1, Start>(offs) + std::get<I>(offs)) * dimension<Start + I>();
|
||||
}
|
||||
public:
|
||||
constexpr std::size_t size() const { return size_impl(std::make_index_sequence<sizeof...(Dims)>{}); }
|
||||
|
||||
auto dimensions() const { return dimensions_impl(std::make_index_sequence<sizeof...(Dims)>{}); }
|
||||
private:
|
||||
template <std::size_t... Is>
|
||||
constexpr std::size_t size_impl(std::index_sequence<Is...>) const {
|
||||
return (dimension<Is>() * ... * 1);
|
||||
}
|
||||
|
||||
template <std::size_t... Is>
|
||||
constexpr auto dimensions_impl(std::index_sequence<Is...>) const {
|
||||
return std::make_tuple(dimension<Is>()...);
|
||||
}
|
||||
public:
|
||||
value_type& coeff(std::size_t index) { return m_view[index]; }
|
||||
const value_type& coeff(std::size_t index) const { return m_view[index]; }
|
||||
|
||||
value_type* data() { return m_view; }
|
||||
const value_type* data() const { return m_view; }
|
||||
private:
|
||||
template <typename InT, std::size_t Off, std::size_t First, std::size_t... Rest>
|
||||
auto inner_view(value_type* view, std::index_sequence<First, Rest...>) {
|
||||
@@ -97,7 +117,7 @@ private:
|
||||
}
|
||||
private:
|
||||
template <std::size_t I>
|
||||
auto dimension() const {
|
||||
constexpr std::size_t dimension() const {
|
||||
if constexpr (traits::dynamic && traits::dimensions[I] == dynamic_extent) {
|
||||
return m_shape.dimensions[I];
|
||||
} else {
|
||||
@@ -230,9 +250,6 @@ private:
|
||||
shape_type m_shape;
|
||||
};
|
||||
|
||||
template <typename T, std::size_t M, std::size_t N>
|
||||
using matrix = tensor<T, M, N>;
|
||||
|
||||
} // namespace math
|
||||
} // namespace cenet
|
||||
|
||||
|
||||
Reference in New Issue
Block a user