26 #ifndef TILEDARRAY_PERM_INDEX_H__INCLUDED 27 #define TILEDARRAY_PERM_INDEX_H__INCLUDED 40 std::size_t* weights_;
53 weights_(NULL), ndim_(perm.
dim())
63 weights_ =
static_cast<std::size_t*
>(malloc((ndim_ + ndim_) *
sizeof(std::size_t)));
65 throw std::bad_alloc();
68 const auto* MADNESS_RESTRICT
const inv_perm = & inv_perm_.data().front();
69 const auto* MADNESS_RESTRICT
const range_size = range.
extent_data();
70 const auto* MADNESS_RESTRICT
const range_weight = range.
stride_data();
73 std::size_t* MADNESS_RESTRICT
const input_weight = weights_;
74 std::size_t* MADNESS_RESTRICT
const output_weight = weights_ + ndim_;
77 std::size_t volume = 1ul;
78 for(
int i =
int(ndim_) - 1; i >= 0; --i) {
80 const auto inv_perm_i = inv_perm[i];
81 const auto weight = range_weight[i];
82 const auto size = range_size[inv_perm_i];
85 output_weight[inv_perm_i] = volume;
87 input_weight[i] = weight;
93 weights_(NULL), ndim_(other.ndim_)
97 weights_ =
static_cast<std::size_t*
>(malloc((ndim_ + ndim_) *
sizeof(std::size_t)));
99 throw std::bad_alloc();
102 memcpy(weights_, other.weights_, (ndim_ + ndim_) *
sizeof(std::size_t));
113 if(ndim_ && (ndim_ != other.ndim_)) {
118 const std::size_t bytes = (other.ndim_ + other.ndim_) *
sizeof(std::size_t);
120 if(! weights_ && bytes) {
122 weights_ =
static_cast<std::size_t*
>(malloc(bytes));
124 throw std::bad_alloc();
129 memcpy(weights_, other.weights_, bytes);
137 int dim()
const {
return ndim_; }
142 const std::size_t*
data()
const {
return weights_; }
150 const std::size_t* MADNESS_RESTRICT
const input_weight = weights_;
151 const std::size_t* MADNESS_RESTRICT
const output_weight = weights_ + ndim_;
154 std::size_t perm_index = 0ul;
156 for(
unsigned int i = 0u; i < ndim_; ++i) {
157 const std::size_t input_weight_i = input_weight[i];
158 const std::size_t output_weight_i = output_weight[i];
159 perm_index += index / input_weight_i * output_weight_i;
160 index %= input_weight_i;
167 operator bool()
const {
return ndim_; }
173 #endif // MADNESS_PERM_INDEX_H__INCLUDED 174 TILEDARRAY_PERM_INDEX_H__INCLUDED
A functor that permutes ordinal indices.
A (hyperrectangular) interval on , space of integer n-indices.
const size_type * extent_data() const
Range extent data accessor.
PermIndex(const Range &range, const Permutation &perm)
Construct permuting functor.
const std::size_t * data() const
Data accessor.
std::size_t operator()(std::size_t index) const
Compute the permuted index for the current block.
unsigned int rank() const
Rank accessor.
const size_type * stride_data() const
Range stride data accessor.
PermIndex(const PermIndex &other)
index_type dim() const
Domain size accessor.
constexpr std::size_t size(T(&)[N])
Array size accessor.
Permutation of a sequence of objects indexed by base-0 indices.
PermIndex()
Default constructor.
int dim() const
Dimension accessor.
PermIndex & operator=(const PermIndex &other)