Created
April 6, 2019 11:22
-
-
Save amitsingh19975/767651d8574d6e81aba9a5ef2e652d6f to your computer and use it in GitHub Desktop.
midspan
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 <std::ptrdiff_t FirstRange, std::ptrdiff_t... RestRanges> | |
using Size = static_bounds<FirstRange, RestRanges...>; | |
template < std::ptrdiff_t FirstDimension = dynamic_range, | |
std::ptrdiff_t... RestDimensions> | |
struct basic_extent; | |
template < std::ptrdiff_t FirstDimension, std::ptrdiff_t... RestDimensions> | |
struct basic_extent{ | |
template <std::ptrdiff_t FirstDimension2, | |
std::ptrdiff_t... RestDimensions2> | |
friend struct basic_extent; | |
using bounds_type = static_bounds<FirstDimension, RestDimensions...>; | |
using size_type = typename bounds_type::size_type; | |
using index_type = typename bounds_type::index_type; | |
using const_span = basic_extent<FirstDimension, RestDimensions...>; | |
constexpr basic_extent() noexcept | |
: basic_extent(bounds_type{}) | |
{ | |
static_assert(bounds_type::dynamic_rank != 0 || | |
(bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0), | |
"Default construction of multi_span<T> only possible " | |
"for dynamic or fixed, zero-length spans."); | |
} | |
template <class IntType, typename = std::enable_if_t<std::is_integral<IntType>::value>> | |
constexpr basic_extent(IntType size) : basic_extent(bounds_type{}) | |
{ | |
assert(size==0); | |
} | |
constexpr basic_extent(bounds_type bounds,size_t rank_) | |
: bounds_(std::move(bounds)),Rank(rank_) | |
{ | |
assert((bounds_.size() > 0) || bounds_.size() == 0); | |
} | |
constexpr size_type size() const noexcept { return bounds_.size(); } | |
constexpr size_type length() const noexcept { return this->size(); } | |
constexpr bool empty() const noexcept { return this->size() == 0; } | |
constexpr std::size_t rank() { return Rank; } | |
constexpr std::size_t dynamic_rank() { return ; } | |
template <std::size_t Dim = 0> | |
constexpr size_type extent() const noexcept | |
{ | |
static_assert(Dim < Rank, | |
"Dimension should be less than rank (dimension count starts from 0)."); | |
return bounds_.template extent<Dim>(); | |
} | |
template <typename IntType> | |
constexpr size_type extent(IntType dim) const | |
{ | |
return bounds_.extent(dim); | |
} | |
constexpr bounds_type bounds() const noexcept { return bounds_; } | |
bounds_type bounds_; | |
std::size_t Rank; | |
}; | |
template < class T, class Extents /*, other */> | |
struct tensor{ | |
/* .... */ | |
tensor() {}; | |
basic_extent<> extents_{Extents(),Extents::rank}; | |
/* ... */ | |
}; | |
int main(){ | |
using temp = Size<1,3,4,5>; | |
tensor<int,Size<1,3,4,5>> t; | |
for(auto i = 0u; i < t.extents_.size(); i ++){ | |
cout<<t.extents_.extent(i)<<'\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment