Commit 283fcd6f authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Added TensorRange.shift()


Signed-off-by: default avatarDmitry I. Lyakh <quant4me@gmail.com>
parent 8e55d91d
/** ExaTN::Numerics: Tensor range
REVISION: 2021/09/21
REVISION: 2021/11/02
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -72,6 +72,9 @@ public:
/** Resets the current multi-index value to the beginning. **/
inline void reset();
/** Resets the current multi-index value to a given flattened local offset. **/
inline void reset(DimOffset offset);
/** Resets the current multi-index for a number of concurrent progress agents,
each given an exclusive subrange of this range to iterate within. Returns
TRUE on success, FALSE if the subrange is empty for the current progress agent. **/
......@@ -116,20 +119,24 @@ public:
each is in a monotonically non-increasing order. **/
inline bool nonincreasingOrderDiag() const;
/** Returns the flat offset produced by the current multi-index value per se. **/
/** Returns the flattened offset produced by the current multi-index value per se. **/
inline DimOffset localOffset() const; //little endian
/** Returns the flat offset produced by the current multi-index value within the global tensor range. **/
/** Returns the flattened offset produced by the current multi-index value within the global tensor range. **/
inline DimOffset globalOffset() const; //based on strides
/** Increments the current multi-index value.
If the tensor range is over, return false. **/
If the tensor range (or subrange) is over, return false. **/
inline bool next(DimOffset increment = 1); //increment value
/** Decrements the current multi-index value.
If the tensor range is over, return false. **/
If the tensor range (or subrange) is over, return false. **/
inline bool prev(DimOffset increment = 1); //increment value
/** Shifts the current multi-index value by a given flattend local offset.
If the tensor range (or subrange) is over, return false. **/
inline bool shift(long long offset);
/** Prints the current multi-index value. **/
void printCurrent() const{
std::cout << "{";
......@@ -250,6 +257,15 @@ inline void TensorRange::reset()
}
inline void TensorRange::reset(DimOffset offset)
{
assert(offset < volume_);
reset();
shift(static_cast<long long>(offset));
return;
}
inline bool TensorRange::reset(unsigned int num_agents,
unsigned int agent_rank)
{
......@@ -483,6 +499,29 @@ inline bool TensorRange::prev(DimOffset increment)
return false;
}
inline bool TensorRange::shift(long long offset)
{
long long local_offset = localOffset();
long long range_begin = 0;
long long range_end = volume_;
if(subrange_end_ > 0){
range_begin = subrange_begin_;
range_end = subrange_end_;
}
local_offset += offset;
if(local_offset >= range_begin && local_offset < range_end){
for(unsigned int i = 0; i < extents_.size(); ++i){
mlndx_[i] = local_offset % extents_[i];
local_offset /= extents_[i];
}
}else{
reset();
return false;
}
return true;
}
} //namespace numerics
} //namespace exatn
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment