11#include "utils/vec_range.hpp"
12#include "utils/dynamic_arg_resolver.hpp"
17#include <initializer_list>
26 class Tensor_impl:
public intrusive_ptr_base<Tensor_impl>{
30 Storage_init_interface
__SII;
37 std::vector<cytnx_uint64> _shape;
40 std::vector<cytnx_uint64> _mapper;
41 std::vector<cytnx_uint64> _invmapper;
47 boost::intrusive_ptr<Tensor_impl> _clone_meta_only()
const{
48 boost::intrusive_ptr<Tensor_impl> out(
new Tensor_impl());
49 out->_mapper = this->_mapper;
50 out->_invmapper = this->_invmapper;
51 out->_shape = this->_shape;
52 out->_contiguous = this->_contiguous;
55 Tensor_impl(): _contiguous(true){};
57 void Init(
const std::vector<cytnx_uint64> &shape,
const unsigned int &dtype=
Type.Double,
int device=-1);
58 void Init(
const Storage &in);
70 Tensor_impl(
const Tensor_impl &rhs);
71 Tensor_impl& operator=(
const Tensor_impl &rhs);
73 unsigned int dtype()
const{
74 return this->_storage.dtype();
77 return this->_storage.device();
80 std::string dtype_str()
const {
81 return Type.getname(this->_storage.dtype());
83 std::string device_str()
const{
84 return Device.getname(this->_storage.device());
87 const std::vector<cytnx_uint64>& shape()
const{
91 const bool& is_contiguous()
const{
92 return this->_contiguous;
95 const std::vector<cytnx_uint64>& mapper()
const{
98 const std::vector<cytnx_uint64>& invmapper()
const{
99 return this->_invmapper;
105 const Storage& storage()
const{
109 boost::intrusive_ptr<Tensor_impl> clone()
const{
110 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
111 out->_storage = this->_storage.clone();
116 void to_(
const int &device){
117 this->_storage.to_(device);
119 boost::intrusive_ptr<Tensor_impl> to(
const int &device){
120 if(this->device()==device){
125 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
126 out->_storage = this->_storage.to(device);
131 void permute_(
const std::vector<cytnx_uint64> &rnks);
133 boost::intrusive_ptr<Tensor_impl> permute(
const std::vector<cytnx_uint64> &rnks);
136 T& at(
const std::vector<cytnx_uint64> &locator)
const {
137 cytnx_error_msg(locator.size() != this->_shape.size(),
"%s",
"The input index does not match Tensor's rank.");
147 for(cytnx_int64 i=this->_shape.size()-1; i>=0; i--){
148 if(locator[i]>=this->_shape[i]){
149 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
153 c_shape = this->_shape[this->_invmapper[i]];
154 c_loc = locator[this->_invmapper[i]];
155 RealRank += mtplyr*c_loc;
158 return this->_storage.at<T>(RealRank);
161 const Scalar::Sproxy at(
const std::vector<cytnx_uint64> &locator)
const{
162 cytnx_error_msg(locator.size() != this->_shape.size(),
"%s",
"The input index does not match Tensor's rank.");
172 for(cytnx_int64 i=this->_shape.size()-1; i>=0; i--){
173 if(locator[i]>=this->_shape[i]){
174 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
178 c_shape = this->_shape[this->_invmapper[i]];
179 c_loc = locator[this->_invmapper[i]];
180 RealRank += mtplyr*c_loc;
183 return this->_storage.at(RealRank);
186 Scalar::Sproxy at(
const std::vector<cytnx_uint64> &locator){
187 cytnx_error_msg(locator.size() != this->_shape.size(),
"%s",
"The input index does not match Tensor's rank.");
197 for(cytnx_int64 i=this->_shape.size()-1; i>=0; i--){
198 if(locator[i]>=this->_shape[i]){
199 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
203 c_shape = this->_shape[this->_invmapper[i]];
204 c_loc = locator[this->_invmapper[i]];
205 RealRank += mtplyr*c_loc;
208 return this->_storage.at(RealRank);
211 boost::intrusive_ptr<Tensor_impl> get(
const std::vector<cytnx::Accessor> &accessors);
212 boost::intrusive_ptr<Tensor_impl> get_deprecated(
const std::vector<cytnx::Accessor> &accessors);
213 void set(
const std::vector<cytnx::Accessor> &accessors,
const boost::intrusive_ptr<Tensor_impl> &rhs);
216 void set(
const std::vector<cytnx::Accessor> &accessors,
const T& rc);
218 void set(
const std::vector<cytnx::Accessor> &accessors,
const Scalar::Sproxy& rc);
221 void fill(
const Tx& val){
222 this->storage().fill(val);
225 boost::intrusive_ptr<Tensor_impl> contiguous(){
228 if(this->_contiguous){
229 boost::intrusive_ptr<Tensor_impl> out(
this);
233 boost::intrusive_ptr<Tensor_impl> out(
new Tensor_impl());
234 std::vector<cytnx_uint64> oldshape(this->_shape.size());
235 for(cytnx_uint64 i=0;i<this->_shape.size();i++){
236 oldshape[i] = this->_shape[this->_invmapper[i]];
239 out->_storage._impl = this->_storage._impl->Move_memory(oldshape,this->_mapper, this->_invmapper);
241 out->_invmapper = vec_range(this->_invmapper.size());
242 out->_mapper = out->_invmapper;
243 out->_shape = this->_shape;
244 out->_contiguous =
true;
252 if(!this->_contiguous){
253 std::vector<cytnx_uint64> oldshape(this->_shape.size());
254 for(cytnx_uint64 i=0;i<this->_shape.size();i++){
255 oldshape[i] = this->_shape[this->_invmapper[i]];
258 this->_storage._impl = this->_storage._impl->Move_memory(oldshape,this->_mapper, this->_invmapper);
259 this->_mapper = vec_range(this->_invmapper.size());
260 this->_invmapper = this->_mapper;
261 this->_contiguous =
true;
266 void reshape_(
const std::vector<cytnx_int64> &new_shape){
267 if(!this->_contiguous){
270 std::vector<cytnx_uint64> result_shape(new_shape.size());
272 bool has_undetermine =
false;
273 unsigned int Udet_id = 0;
274 for(
int i=0;i<new_shape.size();i++){
276 if(new_shape[i]!=-1)
cytnx_error_msg(new_shape[i]!=-1,
"%s",
"[ERROR] reshape can only have dimension > 0 and one undetermine rank specify as -1");
277 if(has_undetermine)
cytnx_error_msg(new_shape[i]!=-1,
"%s",
"[ERROR] reshape can only have dimension > 0 and one undetermine rank specify as -1");
279 has_undetermine =
true;
281 new_N *= new_shape[i];
282 result_shape[i] = new_shape[i];
288 cytnx_error_msg(new_N > this->_storage.size(),
"%s",
"[ERROR] new shape exceed the total number of elements.");
289 cytnx_error_msg(this->_storage.size()%new_N,
"%s",
"[ERROR] unmatch size when reshape with undetermine dimension");
290 result_shape[Udet_id] = this->_storage.size()/new_N;
292 cytnx_error_msg(new_N != this->_storage.size(),
"%s",
"[ERROR] new shape does not match the number of elements.");
295 this->_shape = result_shape;
296 this->_mapper = vec_range(result_shape.size());
297 this->_invmapper = this->_mapper;
302 boost::intrusive_ptr<Tensor_impl> reshape(
const std::vector<cytnx_int64> &new_shape){
303 boost::intrusive_ptr<Tensor_impl> out(
new Tensor_impl());
304 if(this->is_contiguous()){
305 out = this->_clone_meta_only();
306 out->_storage = this->_storage;
308 out = this->contiguous();
312 out->reshape_(new_shape);
318 boost::intrusive_ptr<Tensor_impl> astype(
const int& new_type){
321 if(this->dtype() == new_type){
324 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
325 out->_storage = this->_storage.astype(new_type);
337 template<
class T> Tensor
operator+(
const Tensor &lhs,
const T &rc);
338 template<
class T> Tensor
operator-(
const Tensor &lhs,
const T &rhs);
339 template<
class T> Tensor
operator*(
const Tensor &lhs,
const T &rhs);
340 template<
class T> Tensor
operator/(
const Tensor &lhs,
const T &rhs);
352 boost::intrusive_ptr<Tensor_impl> _insimpl;
353 std::vector<cytnx::Accessor> _accs;
354 Tproxy(boost::intrusive_ptr<Tensor_impl> _ptr,
const std::vector<cytnx::Accessor> &accs) : _insimpl(std::move(_ptr)), _accs(accs){}
358 this->_insimpl->
set(_accs,rhs._impl);
363 const T& operator=(
const T &rc){
364 this->_insimpl->
set(_accs,rc);
367 const Tproxy& operator=(
const Tproxy &rc){
369 this->_insimpl->set(_accs,tmp._impl);
375 Tensor operator+=(
const T &rc){
377 self._impl = _insimpl->
get(_accs);
379 _insimpl->
set(_accs,self._impl);
380 self._impl = this->_insimpl;
383 Tensor operator+=(
const Tproxy &rc);
386 Tensor operator-=(
const T &rc){
388 self._impl = _insimpl->
get(_accs);
390 _insimpl->
set(_accs,self._impl);
391 self._impl = this->_insimpl;
394 Tensor operator-=(
const Tproxy &rc);
397 Tensor operator/=(
const T &rc){
399 self._impl = _insimpl->
get(_accs);
401 _insimpl->
set(_accs,self._impl);
402 self._impl = this->_insimpl;
405 Tensor operator/=(
const Tproxy &rc);
408 Tensor operator*=(
const T &rc){
410 self._impl = _insimpl->
get(_accs);
412 _insimpl->
set(_accs,self._impl);
413 self._impl = this->_insimpl;
416 Tensor operator*=(
const Tproxy &rc);
509 out._impl = _insimpl->
get(_accs);
510 return out.
item<T>();
513 Scalar::Sproxy item()
const{
515 out._impl = _insimpl->
get(_accs);
522 out._impl = _insimpl->
get(_accs);
529 out._impl = _insimpl->
get(_accs);
540 template<
class ... Ts>
541 Tproxy operator()(
const std::string &e1,
const Ts&...elems){
543 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
546 template<
class ... Ts>
547 Tproxy operator()(
const cytnx_int64 &e1,
const Ts&...elems){
549 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
552 template<
class ... Ts>
555 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
558 template<
class ... Ts>
559 const Tproxy operator()(
const std::string &e1,
const Ts&...elems)
const{
561 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
564 template<
class ... Ts>
565 const Tproxy operator()(
const cytnx_int64 &e1,
const Ts&...elems)
const{
566 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
569 template<
class ... Ts>
570 const Tproxy operator()(
const cytnx::Accessor &e1,
const Ts&...elems)
const{
571 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1,elems...);
578 Tproxy operator[](
const std::initializer_list<cytnx::Accessor> &accs){
579 std::vector<cytnx::Accessor> tmp = accs;
582 Tproxy operator[](
const std::vector<cytnx::Accessor> &accs){
583 return Tproxy(this->_impl,accs);
587 const Tproxy operator[](
const std::vector<cytnx::Accessor> &accs)
const{
588 return Tproxy(this->_impl,accs);
590 const Tproxy operator[](
const std::initializer_list<cytnx::Accessor> &accs)
const{
591 std::vector<cytnx::Accessor> tmp = accs;
595 Tproxy operator[](
const std::initializer_list<cytnx_int64> &accs){
596 std::vector<cytnx_int64> tmp = accs;
599 Tproxy operator[](
const std::vector<cytnx_int64> &accs){
600 std::vector<cytnx::Accessor> acc_in;
601 for(
int i=0;i<accs.size();i++){
604 return Tproxy(this->_impl,acc_in);
606 const Tproxy operator[](
const std::initializer_list<cytnx_int64> &accs)
const{
607 std::vector<cytnx_int64> tmp = accs;
610 const Tproxy operator[](
const std::vector<cytnx_int64> &accs)
const{
611 std::vector<cytnx::Accessor> acc_in;
612 for(
int i=0;i<accs.size();i++){
615 return Tproxy(this->_impl,acc_in);
622 void _Save(std::fstream &f)
const;
623 void _Load(std::fstream &f);
634 void Save(
const std::string &fname)
const;
635 void Save(
const char* fname)
const;
636 void Tofile(
const std::string &fname)
const;
637 void Tofile(
const char* fname)
const;
657 boost::intrusive_ptr<Tensor_impl> _impl;
658 Tensor(): _impl(new Tensor_impl()){};
673 Tensor& operator=(
const Tensor &rhs){
678 void operator=(
const Tproxy &rhsp){
679 this->_impl = rhsp._insimpl->get(rhsp._accs);
706 boost::intrusive_ptr<Tensor_impl> tmp(
new Tensor_impl());
717 boost::intrusive_ptr<Tensor_impl> tmp(
new Tensor_impl());
729 unsigned int dtype()
const {
return this->_impl->dtype();}
736 int device()
const {
return this->_impl->device();}
743 std::string
dtype_str()
const {
return this->_impl->dtype_str();}
750 std::string
device_str()
const{
return this->_impl->device_str();}
757 const std::vector<cytnx_uint64>&
shape()
const{
758 return this->_impl->shape();
766 return this->_impl->shape().size();
789 out._impl = this->_impl->
clone();
815 out._impl = this->_impl->
to(
device);
841 return this->_impl->is_contiguous();
849 template<
class ... Ts>
851 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1,elems...);
852 this->_impl->permute_(argv);
874 out._impl = this->_impl->
permute(rnks);
878 template<
class ... Ts>
880 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1,elems...);
944 void reshape_(
const std::vector<cytnx_int64> &new_shape){
945 this->_impl->reshape_(new_shape);
948 void reshape_(
const std::vector<cytnx_uint64> &new_shape){
949 std::vector<cytnx_int64>
shape(new_shape.begin(),new_shape.end());
950 this->_impl->reshape_(
shape);
952 void reshape_(
const std::initializer_list<cytnx_int64> &new_shape){
953 std::vector<cytnx_int64>
shape = new_shape;
954 this->_impl->reshape_(
shape);
956 template<
class ...Ts>
958 std::vector<cytnx_int64>
shape = dynamic_arg_int64_resolver(e1,elems...);
960 this->_impl->reshape_(
shape);
983 out._impl = this->_impl->
reshape(new_shape);
988 std::vector<cytnx_int64> tmp(new_shape.size());
989 memcpy(&tmp[0],&new_shape[0],
sizeof(
cytnx_uint64)*new_shape.size());
991 out._impl = this->_impl->
reshape(tmp);
996 return this->
reshape(std::vector<cytnx_int64>(new_shape));
1000 template<
class ... Ts>
1002 std::vector<cytnx_int64> argv = dynamic_arg_int64_resolver(e1,elems...);
1027 out._impl = this->_impl->
astype(new_type);
1057 T&
at(
const std::vector<cytnx_uint64> &locator){
1058 return this->_impl->at<T>(locator);
1061 const T&
at(
const std::vector<cytnx_uint64> &locator)
const{
1062 return this->_impl->at<T>(locator);
1065 template<
class T,
class...Ts>
1067 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1,elems...);
1068 return this->at<T>(argv);
1070 template<
class T,
class...Ts>
1072 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1,elems...);
1073 return this->at<T>(argv);
1076 const Scalar::Sproxy
at(
const std::vector<cytnx_uint64> &locator)
const{
1077 return this->_impl->at(locator);
1080 Scalar::Sproxy
at(
const std::vector<cytnx_uint64> &locator){
1081 return this->_impl->at(locator);
1106 cytnx_error_msg(this->_impl->storage().size()!=1,
"[ERROR][Tensor.item<T>]%s",
"item can only be called from a Tensor with only one element\n");
1107 return this->_impl->storage().at<T>(0);
1112 const T&
item()
const{
1113 cytnx_error_msg(this->_impl->storage().size()!=1,
"[ERROR][Tensor.item<T>]%s",
"item can only be called from a Tensor with only one element\n");
1114 return this->_impl->storage().at<T>(0);
1117 const Scalar::Sproxy
item()
const{
1118 Scalar::Sproxy out(this->
storage()._impl,0);
1122 Scalar::Sproxy
item(){
1123 Scalar::Sproxy out(this->
storage()._impl,0);
1152 Tensor get(
const std::vector<cytnx::Accessor> &accessors)
const {
1154 out._impl = this->_impl->
get(accessors);
1185 void set(
const std::vector<cytnx::Accessor> &accessors,
const Tensor &rhs){
1186 this->_impl->set(accessors,rhs._impl);
1209 void set(
const std::vector<cytnx::Accessor> &accessors,
const T &rc){
1210 this->_impl->set(accessors,rc);
1214 void set(
const std::initializer_list<cytnx::Accessor> &accessors,
const T &rc){
1215 std::vector<cytnx::Accessor> args = accessors;
1229 return this->_impl->storage();
1249 this->_impl->fill(val);
1254 if(this->
shape() != rhs.
shape())
return false;
1299 return *
this += rhs;
1308 return *
this -= rhs;
1317 return *
this *= rhs;
1326 return *
this /= rhs;
1331 return *
this == rhs;
1346 return this->
Mul(-1.);
1369 cytnx_error_msg(rhs.
shape().size()==0 || this->shape().size()==0,
"[ERROR] try to append a null Tensor.%s",
"\n");
1370 cytnx_error_msg(rhs.
shape().size()!=(this->shape().size()-1),
"[ERROR] try to append a Tensor with rank not match.%s",
"\n");
1372 for(
unsigned int i=0;i<rhs.
shape().size();i++){
1373 cytnx_error_msg(rhs.
shape()[i]!=this->shape()[i+1],
"[ERROR] dimension mismatch @ rhs.rank: [%d] this: [%d] rhs: [%d]\n",i,this->shape()[i+1],rhs.
shape()[i]);
1374 Nelem*=rhs.
shape()[i];
1379 if(rhs.
dtype() != this->dtype()){
1389 this->_impl->_shape[0]+=1;
1391 this->_impl->_storage.resize(oldsize+Nelem);
1392 memcpy(((
char*)this->_impl->_storage.data()) + oldsize*
Type.typeSize(this->dtype())/
sizeof(
char),
1393 in._impl->_storage.data(),
1402 cytnx_error_msg(srhs.
size()==0 || this->shape().size()==0,
"[ERROR] try to append a null Tensor.%s",
"\n");
1403 cytnx_error_msg((this->
shape().size()-1)!=1,
"[ERROR] append a storage to Tensor can only accept rank-2 Tensor.%s",
"\n");
1409 if(srhs.
dtype() != this->dtype()){
1414 this->_impl->_shape[0]+=1;
1416 this->_impl->_storage.resize(oldsize+in.
size());
1417 memcpy(((
char*)this->_impl->_storage.data()) + oldsize*
Type.typeSize(this->dtype())/
sizeof(
char),
1448 cytnx_error_msg(this->
shape().size()!=1,
"[ERROR] trying to append a scalar into multidimentional Tensor is not allow.\n Only rank-1 Tensor can accept scalar append.%s",
"\n");
1449 cytnx_error_msg(!this->
is_contiguous(),
"[ERROR] append require the Tensor to be contiguous. suggestion: call contiguous() or contiguous_() first.",
"\n");
1450 this->_impl->_shape[0]+=1;
1451 this->_impl->_storage.append(rhs);
1457 std::vector<Tensor>
Svd(
const bool &is_U=
true,
const bool &is_vT=
true)
const;
1458 std::vector<Tensor>
Eigh(
const bool &is_V=
true,
const bool &row_v=
false)
const;
1479 Tensor
operator+(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1480 Tensor
operator-(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1481 Tensor
operator*(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1482 Tensor
operator/(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1484 Tensor
operator+(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1485 Tensor
operator-(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1486 Tensor
operator*(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1487 Tensor
operator/(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1489 std::ostream&
operator<<(std::ostream& os,
const Tensor &in);
1490 std::ostream&
operator<<(std::ostream& os,
const Tensor::Tproxy &in);
object that mimic the python slice to access elements in C++ [this is for c++ API only].
Definition Accessor.hpp:16
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:934
const unsigned int & dtype() const
the dtype-id of current Storage
Definition Storage.hpp:1061
Storage astype(const unsigned int &new_type) const
cast the type of current Storage
Definition Storage.hpp:1052
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1201
an tensor (multi-dimensional array)
Definition Tensor.hpp:344
void append(const Storage &srhs)
Definition Tensor.hpp:1397
Tensor & operator*=(const T &rc)
Tensor & Inv_(const double &clip)
Definition Tensor.cpp:1171
Tensor & operator/=(const T &rc)
Tensor operator-()
Definition Tensor.hpp:1345
void fill(const T &val)
fill all the element of current Tensor with the value.
Definition Tensor.hpp:1248
Tensor InvM() const
Definition Tensor.cpp:1168
bool same_data(const Tensor &rhs) const
Definition Tensor.cpp:1227
void to_(const int &device)
move the current Tensor to the device.
Definition Tensor.hpp:836
Tensor reshape(const std::vector< cytnx_uint64 > &new_shape) const
Definition Tensor.hpp:987
void append(const T &rhs)
Definition Tensor.hpp:1447
Tensor & operator-=(const T &rc)
Tensor & Add_(const T &rhs)
Definition Tensor.hpp:1298
Tensor Abs() const
Definition Tensor.cpp:1212
Tensor reshape(const std::initializer_list< cytnx_int64 > &new_shape) const
Definition Tensor.hpp:995
std::string device_str() const
the device (in string) of the Tensor
Definition Tensor.hpp:750
void reshape_(const std::vector< cytnx_int64 > &new_shape)
reshape the Tensor, inplacely
Definition Tensor.hpp:944
Tensor contiguous_()
Make the Tensor contiguous by coalescing the memory (storage), inplacely.
Definition Tensor.hpp:923
static Tensor Load(const std::string &fname)
Load current Tensor to file.
Definition Tensor.cpp:847
Tensor permute_(const std::vector< cytnx_uint64 > &rnks)
Definition Tensor.hpp:844
Tensor Mul(const T &rhs)
Definition Tensor.hpp:1312
unsigned int dtype() const
the dtype-id of the Tensor
Definition Tensor.hpp:729
Tensor Sub(const T &rhs)
Definition Tensor.hpp:1303
Tensor Inv(const double &clip) const
Definition Tensor.cpp:1175
Tensor contiguous() const
Make the Tensor contiguous by coalescing the memory (storage).
Definition Tensor.hpp:902
void Tofile(const std::string &fname) const
Definition Tensor.cpp:772
T & at(const std::vector< cytnx_uint64 > &locator)
[C++ only] get an element at specific location.
Definition Tensor.hpp:1057
Tensor reshape(const std::vector< cytnx_int64 > &new_shape) const
return a new Tensor that is reshaped.
Definition Tensor.hpp:981
T & item()
get an from a rank-0 Tensor
Definition Tensor.hpp:1105
Tensor clone() const
return a clone of the current Tensor.
Definition Tensor.hpp:787
std::vector< Tensor > Eigh(const bool &is_V=true, const bool &row_v=false) const
Definition Tensor.cpp:1159
void append(const Tensor &rhs)
Definition Tensor.hpp:1363
void set(const std::vector< cytnx::Accessor > &accessors, const Tensor &rhs)
set elements with the input Tensor using Accessor (C++ API) / slices (python API)
Definition Tensor.hpp:1185
Tensor Norm() const
Definition Tensor.cpp:1195
Tensor astype(const int &new_type) const
return a new Tensor that cast to different dtype.
Definition Tensor.hpp:1025
Tensor & Div_(const T &rhs)
Definition Tensor.hpp:1325
Tensor & operator+=(const T &rc)
Tensor Conj() const
Definition Tensor.cpp:1184
Tensor Trace(const cytnx_uint64 &a=0, const cytnx_uint64 &b=1) const
Definition Tensor.cpp:1222
Tensor & Pow_(const cytnx_double &p)
Definition Tensor.cpp:1203
std::string dtype_str() const
the dtype (in string) of the Tensor
Definition Tensor.hpp:743
Tensor & Mul_(const T &rhs)
Definition Tensor.hpp:1316
cytnx_uint64 rank() const
the rank of the Tensor
Definition Tensor.hpp:765
const bool & is_contiguous() const
Definition Tensor.hpp:840
Tensor Exp() const
Definition Tensor.cpp:1192
Tensor & Abs_()
Definition Tensor.cpp:1208
Tensor Add(const T &rhs)
Definition Tensor.hpp:1294
void flatten_()
Definition Tensor.hpp:1356
void Save(const std::string &fname) const
Save current Tensor to file.
Definition Tensor.cpp:798
Tensor flatten() const
Definition Tensor.hpp:1349
Tensor & Conj_()
Definition Tensor.cpp:1180
Tensor Pow(const cytnx_double &p) const
Definition Tensor.cpp:1199
int device() const
the device-id of the Tensor
Definition Tensor.hpp:736
Tensor real()
Definition Tensor.cpp:898
Tensor imag()
Definition Tensor.cpp:905
Tensor to(const int &device) const
copy a tensor to new device
Definition Tensor.hpp:813
void Tofile(std::fstream &f) const
Tensor get(const std::vector< cytnx::Accessor > &accessors) const
get elements using Accessor (C++ API) / slices (python API)
Definition Tensor.hpp:1152
void set(const std::vector< cytnx::Accessor > &accessors, const T &rc)
set elements with the input constant using Accessor (C++ API) / slices (python API)
Definition Tensor.hpp:1209
Tensor Max() const
Definition Tensor.cpp:1215
Tensor permute(const std::vector< cytnx_uint64 > &rnks) const
perform tensor permute on the cytnx::Tensor and return a new instance.
Definition Tensor.hpp:872
Tensor Div(const T &rhs)
Definition Tensor.hpp:1321
Tensor Mod(const T &rhs)
Definition Tensor.hpp:1341
bool equiv(const Tensor &rhs)
Definition Tensor.hpp:1253
Tensor Cpr(const T &rhs)
Definition Tensor.hpp:1330
Tensor & Exp_()
Definition Tensor.cpp:1188
Tensor & InvM_()
Definition Tensor.cpp:1164
std::vector< Tensor > Svd(const bool &is_U=true, const bool &is_vT=true) const
Definition Tensor.cpp:1156
const std::vector< cytnx_uint64 > & shape() const
the shape of the Tensor
Definition Tensor.hpp:757
Tensor Min() const
Definition Tensor.cpp:1218
const T & at(const std::vector< cytnx_uint64 > &locator) const
Definition Tensor.hpp:1061
Storage & storage() const
return the storage of current Tensor.
Definition Tensor.hpp:1228
static Tensor from_storage(const Storage &in)
Definition Tensor.hpp:715
static Tensor Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
Definition Tensor.cpp:841
void Init(const std::vector< cytnx_uint64 > &shape, const unsigned int &dtype=Type.Double, const int &device=-1)
initialize a Tensor
Definition Tensor.hpp:705
Tensor(const std::vector< cytnx_uint64 > &shape, const unsigned int &dtype=Type.Double, const int &device=-1)
Definition Tensor.hpp:710
Tensor & Sub_(const T &rhs)
Definition Tensor.hpp:1307
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
Device_class Device
Definition Device.cpp:105
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
double cytnx_double
Definition Type.hpp:20
uint32_t cytnx_uint32
Definition Type.hpp:23
bool cytnx_bool
Definition Type.hpp:31
std::complex< double > cytnx_complex128
Definition Type.hpp:30
float cytnx_float
Definition Type.hpp:21
std::ostream & operator<<(std::ostream &os, const Scalar &in)
Definition Scalar.cpp:14
int16_t cytnx_int16
Definition Type.hpp:27
std::complex< float > cytnx_complex64
Definition Type.hpp:29
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
int32_t cytnx_int32
Definition Type.hpp:26
uint16_t cytnx_uint16
Definition Type.hpp:24
uint64_t cytnx_uint64
Definition Type.hpp:22
int64_t cytnx_int64
Definition Type.hpp:25
Storage_init_interface __SII
Definition Storage.cpp:13
Type_class Type
Definition Type.cpp:143
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)