Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
exatn
Commits
283fcd6f
Commit
283fcd6f
authored
Nov 02, 2021
by
Dmitry I. Lyakh
Browse files
Added TensorRange.shift()
Signed-off-by:
Dmitry I. Lyakh
<
quant4me@gmail.com
>
parent
8e55d91d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/numerics/tensor_range.hpp
View file @
283fcd6f
/** 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 flat
tened
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 flat
tened
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment