object that mimic the python slice to access elements in C++ [this is for c++ API only].
More...
#include <Accessor.hpp>
|
| | Accessor (const cytnx_int64 &loc) |
| | access the specific index at the assigned rank in Tensor.
|
| |
| template<class T > |
| | Accessor (const std::initializer_list< T > &list) |
| |
| template<class T > |
| | Accessor (const std::vector< T > &list) |
| |
| int | type () const |
| |
|
| static Accessor | all () |
| | access the whole rank, this is similar to [:] in python
|
| |
| static Accessor | range (const cytnx_int64 &min, const cytnx_int64 &max, const cytnx_int64 &step=1) |
| | access the range at assigned rank, this is similar to min:max:step in python
|
| |
| static Accessor | tilend (const cytnx_int64 &min, const cytnx_int64 &step=1) |
| |
| static Accessor | step (const cytnx_int64 &step) |
| |
| static Accessor | qns (const std::vector< std::vector< cytnx_int64 > > &qns) |
| |
object that mimic the python slice to access elements in C++ [this is for c++ API only].
◆ Accessor() [1/3]
| cytnx::Accessor::Accessor |
( |
const cytnx_int64 & |
loc | ) |
|
|
explicit |
access the specific index at the assigned rank in Tensor.
- Parameters
-
See also cytnx::Tensor.get() for how to using them.
Example:
c++ API:
#include <iostream>
using namespace std;
int main() {
cout << A << endl;
Tensor B = A(0, ac::all(), ac::range(0, 2, 1));
cout << B << endl;
return 0;
}
object that mimic the python slice to access elements in C++ [this is for c++ API only].
Definition Accessor.hpp:17
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
Tensor & reshape_(const std::vector< cytnx_int64 > &new_shape)
reshape the Tensor, inplacely
Definition Tensor.hpp:788
Definition Accessor.hpp:12
Tensor arange(const cytnx_int64 &Nelem)
create an rank-1 Tensor with incremental unsigned integer elements start with [0,Nelem)
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
python API:
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = arange(24);
A.reshape_(2,3,4);
print(A)
B = A[0,:,0:2:1]
print(B)
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
◆ Accessor() [2/3]
template<class T >
| cytnx::Accessor::Accessor |
( |
const std::initializer_list< T > & |
list | ) |
|
|
inlineexplicit |
◆ Accessor() [3/3]
template<class T >
| cytnx::Accessor::Accessor |
( |
const std::vector< T > & |
list | ) |
|
|
inlineexplicit |
◆ all()
| static Accessor cytnx::Accessor::all |
( |
| ) |
|
|
inlinestatic |
access the whole rank, this is similar to [:] in python
Example:
c++ API:
#include <iostream>
using namespace std;
int main() {
cout << A << endl;
Tensor B = A(0, ac::all(), ac::range(0, 2, 1));
cout << B << endl;
return 0;
}
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
python API:
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = arange(24);
A.reshape_(2,3,4);
print(A)
B = A[0,:,0:2:1]
print(B)
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
◆ qns()
| static Accessor cytnx::Accessor::qns |
( |
const std::vector< std::vector< cytnx_int64 > > & |
qns | ) |
|
|
inlinestatic |
◆ range()
| static Accessor cytnx::Accessor::range |
( |
const cytnx_int64 & |
min, |
|
|
const cytnx_int64 & |
max, |
|
|
const cytnx_int64 & |
step = 1 |
|
) |
| |
|
inlinestatic |
access the range at assigned rank, this is similar to min:max:step in python
- Parameters
-
Example:
c++ API:
#include <iostream>
using namespace std;
int main() {
cout << A << endl;
Tensor B = A(0, ac::all(), ac::range(0, 2, 1));
cout << B << endl;
return 0;
}
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
python API:
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = arange(24);
A.reshape_(2,3,4);
print(A)
B = A[0,:,0:2:1]
print(B)
output>
Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
◆ step()
| static Accessor cytnx::Accessor::step |
( |
const cytnx_int64 & |
step | ) |
|
|
inlinestatic |
◆ tilend()
| static Accessor cytnx::Accessor::tilend |
( |
const cytnx_int64 & |
min, |
|
|
const cytnx_int64 & |
step = 1 |
|
) |
| |
|
inlinestatic |
◆ type()
| int cytnx::Accessor::type |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following file: