11#include "utils/vec_range.hpp"
12#include "utils/vec_cast.hpp"
13#include "utils/dynamic_arg_resolver.hpp"
18#include <initializer_list>
26 class Tensor_impl :
public intrusive_ptr_base<Tensor_impl> {
29 Storage_init_interface
__SII;
35 std::vector<cytnx_uint64> _shape;
38 std::vector<cytnx_uint64> _mapper;
39 std::vector<cytnx_uint64> _invmapper;
44 boost::intrusive_ptr<Tensor_impl> _clone_meta_only()
const {
45 boost::intrusive_ptr<Tensor_impl> out(
new Tensor_impl());
46 out->_mapper = this->_mapper;
47 out->_invmapper = this->_invmapper;
48 out->_shape = this->_shape;
49 out->_contiguous = this->_contiguous;
52 Tensor_impl() : _contiguous(true){};
54 void Init(
const std::vector<cytnx_uint64> &shape,
const unsigned int &dtype =
Type.Double,
55 int device = -1,
const bool &init_zero =
true);
56 void Init(
const Storage &in);
71 Tensor_impl(
const Tensor_impl &rhs);
72 Tensor_impl &operator=(
const Tensor_impl &rhs);
74 unsigned int dtype()
const {
return this->_storage.dtype(); }
75 int device()
const {
return this->_storage.device(); }
77 std::string dtype_str()
const {
return Type.getname(this->_storage.dtype()); }
78 std::string device_str()
const {
return Device.getname(this->_storage.device()); }
80 const std::vector<cytnx_uint64> &shape()
const {
return _shape; }
82 const bool &is_contiguous()
const {
return this->_contiguous; }
84 const std::vector<cytnx_uint64> &mapper()
const {
return this->_mapper; }
85 const std::vector<cytnx_uint64> &invmapper()
const {
return this->_invmapper; }
86 Storage &storage() {
return _storage; }
88 const Storage &storage()
const {
return _storage; }
90 boost::intrusive_ptr<Tensor_impl> clone()
const {
91 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
92 out->_storage = this->_storage.clone();
96 void to_(
const int &device) { this->_storage.to_(device); }
97 boost::intrusive_ptr<Tensor_impl> to(
const int &device) {
98 if (this->device() == device) {
102 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
103 out->_storage = this->_storage.to(device);
108 void permute_(
const std::vector<cytnx_uint64> &rnks);
110 boost::intrusive_ptr<Tensor_impl> permute(
const std::vector<cytnx_uint64> &rnks);
113 T &at(
const std::vector<cytnx_uint64> &locator)
const {
115 "The input index does not match Tensor's rank.");
125 for (cytnx_int64 i = this->_shape.size() - 1; i >= 0; i--) {
126 if (locator[i] >= this->_shape[i]) {
127 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
131 c_shape = this->_shape[this->_invmapper[i]];
132 c_loc = locator[this->_invmapper[i]];
133 RealRank += mtplyr * c_loc;
136 return this->_storage.at<T>(RealRank);
139 const Scalar::Sproxy at(
const std::vector<cytnx_uint64> &locator)
const {
141 "The input index does not match Tensor's rank.");
151 for (cytnx_int64 i = this->_shape.size() - 1; i >= 0; i--) {
152 if (locator[i] >= this->_shape[i]) {
153 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
157 c_shape = this->_shape[this->_invmapper[i]];
158 c_loc = locator[this->_invmapper[i]];
159 RealRank += mtplyr * c_loc;
162 return this->_storage.at(RealRank);
165 Scalar::Sproxy at(
const std::vector<cytnx_uint64> &locator) {
167 "The input index does not match Tensor's rank.");
177 for (cytnx_int64 i = this->_shape.size() - 1; i >= 0; i--) {
178 if (locator[i] >= this->_shape[i]) {
179 cytnx_error_msg(
true,
"%s",
"Attempting to access out-of-bound index in Tensor.");
183 c_shape = this->_shape[this->_invmapper[i]];
184 c_loc = locator[this->_invmapper[i]];
185 RealRank += mtplyr * c_loc;
188 return this->_storage.at(RealRank);
191 boost::intrusive_ptr<Tensor_impl> get(
const std::vector<cytnx::Accessor> &accessors);
192 boost::intrusive_ptr<Tensor_impl> get_deprecated(
const std::vector<cytnx::Accessor> &accessors);
193 void set(
const std::vector<cytnx::Accessor> &accessors,
194 const boost::intrusive_ptr<Tensor_impl> &rhs);
197 void set(
const std::vector<cytnx::Accessor> &accessors,
const T &rc);
199 void set(
const std::vector<cytnx::Accessor> &accessors,
const Scalar::Sproxy &rc);
202 void fill(
const Tx &val) {
203 this->storage().fill(val);
206 boost::intrusive_ptr<Tensor_impl> contiguous() {
209 if (this->_contiguous) {
210 boost::intrusive_ptr<Tensor_impl> out(
this);
214 boost::intrusive_ptr<Tensor_impl> out(
new Tensor_impl());
215 std::vector<cytnx_uint64> oldshape(this->_shape.size());
216 for (cytnx_uint64 i = 0; i < this->_shape.size(); i++) {
217 oldshape[i] = this->_shape[this->_invmapper[i]];
220 out->_storage._impl =
221 this->_storage._impl->Move_memory(oldshape, this->_mapper, this->_invmapper);
225 out->_invmapper = vec_range(this->_invmapper.size());
226 out->_mapper = out->_invmapper;
227 out->_shape = this->_shape;
228 out->_contiguous =
true;
236 if (!this->_contiguous) {
237 std::vector<cytnx_uint64> oldshape(this->_shape.size());
238 for (cytnx_uint64 i = 0; i < this->_shape.size(); i++) {
239 oldshape[i] = this->_shape[this->_invmapper[i]];
242 this->_storage._impl =
243 this->_storage._impl->Move_memory(oldshape, this->_mapper, this->_invmapper);
246 vec_range_(this->_mapper, this->invmapper().size());
247 this->_invmapper = this->_mapper;
248 this->_contiguous =
true;
252 void reshape_(
const std::vector<cytnx_int64> &new_shape) {
253 if (!this->_contiguous) {
258 bool has_undetermine =
false;
259 unsigned int Udet_id = 0;
261 this->_shape.resize(new_shape.size());
262 for(cytnx_uint64 i=0;i<new_shape.size();i++){
263 this->_shape[i] = new_shape[i];
265 for (
int i = 0; i < new_shape.size(); i++) {
266 if (new_shape[i] < 0) {
267 if (new_shape[i] != -1)
269 new_shape[i] != -1,
"%s",
270 "[ERROR] reshape can only have dimension > 0 and one undetermine rank specify as -1");
273 new_shape[i] != -1,
"%s",
274 "[ERROR] reshape can only have dimension > 0 and one undetermine rank specify as -1");
276 has_undetermine =
true;
278 new_N *= new_shape[i];
283 if (has_undetermine) {
285 "[ERROR] new shape exceed the total number of elements.");
287 "[ERROR] unmatch size when reshape with undetermine dimension");
289 this->_shape[Udet_id] = this->_storage.size() / new_N;
292 "[ERROR] new shape does not match the number of elements.");
297 this->_mapper.resize(new_shape.size());
298 vec_range_(this->_mapper, new_shape.size());
299 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);
316 boost::intrusive_ptr<Tensor_impl> astype(
const int &new_type) {
319 if (this->dtype() == new_type) {
322 boost::intrusive_ptr<Tensor_impl> out = this->_clone_meta_only();
323 out->_storage = this->_storage.astype(new_type);
335 Tensor
operator+(
const Tensor &lhs,
const T &rc);
337 Tensor
operator-(
const Tensor &lhs,
const T &rhs);
339 Tensor
operator*(
const Tensor &lhs,
const T &rhs);
341 Tensor
operator/(
const Tensor &lhs,
const T &rhs);
351 boost::intrusive_ptr<Tensor_impl> _insimpl;
352 std::vector<cytnx::Accessor> _accs;
353 Tproxy(boost::intrusive_ptr<Tensor_impl> _ptr,
const std::vector<cytnx::Accessor> &accs)
354 : _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);
374 Tensor operator+=(
const T &rc) {
376 self._impl = _insimpl->
get(_accs);
378 _insimpl->
set(_accs, self._impl);
379 self._impl = this->_insimpl;
382 Tensor operator+=(
const Tproxy &rc);
385 Tensor operator-=(
const T &rc) {
387 self._impl = _insimpl->
get(_accs);
389 _insimpl->
set(_accs, self._impl);
390 self._impl = this->_insimpl;
393 Tensor operator-=(
const Tproxy &rc);
396 Tensor operator/=(
const T &rc) {
398 self._impl = _insimpl->
get(_accs);
400 _insimpl->
set(_accs, self._impl);
401 self._impl = this->_insimpl;
404 Tensor operator/=(
const Tproxy &rc);
407 Tensor operator*=(
const T &rc) {
409 self._impl = _insimpl->
get(_accs);
411 _insimpl->
set(_accs, self._impl);
412 self._impl = this->_insimpl;
415 Tensor operator*=(
const Tproxy &rc);
507 out._impl = _insimpl->
get(_accs);
508 return out.
item<T>();
511 Scalar::Sproxy item()
const {
513 out._impl = _insimpl->
get(_accs);
520 out._impl = _insimpl->
get(_accs);
526 out._impl = _insimpl->
get(_accs);
537 template <
class... Ts>
538 Tproxy operator()(
const std::string &e1,
const Ts &...elems) {
540 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
543 template <
class... Ts>
544 Tproxy operator()(
const cytnx_int64 &e1,
const Ts &...elems) {
546 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
549 template <
class... Ts>
552 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
555 template <
class... Ts>
556 const Tproxy operator()(
const std::string &e1,
const Ts &...elems)
const {
558 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
561 template <
class... Ts>
562 const Tproxy operator()(
const cytnx_int64 &e1,
const Ts &...elems)
const {
563 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
566 template <
class... Ts>
567 const Tproxy operator()(
const cytnx::Accessor &e1,
const Ts &...elems)
const {
568 std::vector<cytnx::Accessor> tmp = Indices_resolver(e1, elems...);
574 Tproxy operator[](
const std::initializer_list<cytnx::Accessor> &accs) {
575 std::vector<cytnx::Accessor> tmp = accs;
578 Tproxy operator[](
const std::vector<cytnx::Accessor> &accs) {
579 return Tproxy(this->_impl, accs);
582 const Tproxy operator[](
const std::vector<cytnx::Accessor> &accs)
const {
583 return Tproxy(this->_impl, accs);
585 const Tproxy operator[](
const std::initializer_list<cytnx::Accessor> &accs)
const {
586 std::vector<cytnx::Accessor> tmp = accs;
590 Tproxy operator[](
const std::initializer_list<cytnx_int64> &accs) {
591 std::vector<cytnx_int64> tmp = accs;
594 Tproxy operator[](
const std::vector<cytnx_int64> &accs) {
595 std::vector<cytnx::Accessor> acc_in;
596 for (
int i = 0; i < accs.size(); i++) {
599 return Tproxy(this->_impl, acc_in);
601 const Tproxy operator[](
const std::initializer_list<cytnx_int64> &accs)
const {
602 std::vector<cytnx_int64> tmp = accs;
605 const Tproxy operator[](
const std::vector<cytnx_int64> &accs)
const {
606 std::vector<cytnx::Accessor> acc_in;
607 for (
int i = 0; i < accs.size(); i++) {
610 return Tproxy(this->_impl, acc_in);
616 void _Save(std::fstream &f)
const;
617 void _Load(std::fstream &f);
630 void Save(
const std::string &fname)
const;
634 void Save(
const char *fname)
const;
635 void Tofile(
const std::string &fname)
const;
636 void Tofile(
const char *fname)
const;
659 boost::intrusive_ptr<Tensor_impl> _impl;
660 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);
710 const int &
device = -1,
const bool &init_zero =
true) {
711 boost::intrusive_ptr<Tensor_impl> tmp(
new Tensor_impl());
740 const int &
device = -1,
const bool &init_zero = 1)
741 : _impl(new Tensor_impl()) {
757 boost::intrusive_ptr<Tensor_impl> tmp(
new Tensor_impl());
768 unsigned int dtype()
const {
return this->_impl->dtype(); }
775 int device()
const {
return this->_impl->device(); }
782 std::string
dtype_str()
const {
return this->_impl->dtype_str(); }
789 std::string
device_str()
const {
return this->_impl->device_str(); }
795 const std::vector<cytnx_uint64> &
shape()
const {
return this->_impl->shape(); }
822 out._impl = this->_impl->
clone();
848 out._impl = this->_impl->
to(
device);
878 template <
class... Ts>
880 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1, elems...);
881 this->_impl->permute_(argv);
906 out._impl = this->_impl->
permute(rnks);
910 template <
class... Ts>
912 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1, elems...);
978 void reshape_(
const std::vector<cytnx_int64> &new_shape) { this->_impl->reshape_(new_shape); }
980 void reshape_(
const std::vector<cytnx_uint64> &new_shape) {
981 std::vector<cytnx_int64>
shape(new_shape.begin(), new_shape.end());
982 this->_impl->reshape_(
shape);
984 void reshape_(
const std::initializer_list<cytnx_int64> &new_shape) {
985 std::vector<cytnx_int64>
shape = new_shape;
986 this->_impl->reshape_(
shape);
988 template <
class... Ts>
990 std::vector<cytnx_int64>
shape = dynamic_arg_int64_resolver(e1, elems...);
992 this->_impl->reshape_(
shape);
1021 out._impl = this->_impl->
reshape(new_shape);
1029 std::vector<cytnx_int64> tmp(new_shape.size());
1030 memcpy(&tmp[0], &new_shape[0],
sizeof(
cytnx_uint64) * new_shape.size());
1032 out._impl = this->_impl->
reshape(tmp);
1040 return this->
reshape(std::vector<cytnx_int64>(new_shape));
1044 template <
class... Ts>
1046 std::vector<cytnx_int64> argv = dynamic_arg_int64_resolver(e1, elems...);
1070 out._impl = this->_impl->
astype(new_type);
1101 T &
at(
const std::vector<cytnx_uint64> &locator) {
1102 return this->_impl->at<T>(locator);
1109 const T &
at(
const std::vector<cytnx_uint64> &locator)
const {
1110 return this->_impl->at<T>(locator);
1113 template <
class T,
class... Ts>
1115 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1, elems...);
1116 return this->at<T>(argv);
1118 template <
class T,
class... Ts>
1120 std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1, elems...);
1121 return this->at<T>(argv);
1124 const Scalar::Sproxy
at(
const std::vector<cytnx_uint64> &locator)
const {
1125 return this->_impl->at(locator);
1128 Scalar::Sproxy
at(
const std::vector<cytnx_uint64> &locator) {
return this->_impl->at(locator); }
1156 cytnx_error_msg(this->_impl->storage().size() != 1,
"[ERROR][Tensor.item<T>]%s",
1157 "item can only be called from a Tensor with only one element\n");
1158 return this->_impl->storage().at<T>(0);
1163 const T &
item()
const {
1164 cytnx_error_msg(this->_impl->storage().size() != 1,
"[ERROR][Tensor.item<T>]%s",
1165 "item can only be called from a Tensor with only one element\n");
1166 return this->_impl->storage().at<T>(0);
1169 const Scalar::Sproxy
item()
const {
1170 Scalar::Sproxy out(this->
storage()._impl, 0);
1174 Scalar::Sproxy
item() {
1175 Scalar::Sproxy out(this->
storage()._impl, 0);
1202 Tensor get(
const std::vector<cytnx::Accessor> &accessors)
const {
1204 out._impl = this->_impl->
get(accessors);
1234 void set(
const std::vector<cytnx::Accessor> &accessors,
const Tensor &rhs) {
1235 this->_impl->set(accessors, rhs._impl);
1257 void set(
const std::vector<cytnx::Accessor> &accessors,
const T &rc) {
1258 this->_impl->set(accessors, rc);
1262 void set(
const std::initializer_list<cytnx::Accessor> &accessors,
const T &rc) {
1263 std::vector<cytnx::Accessor> args = accessors;
1264 this->
set(args, rc);
1295 this->_impl->fill(val);
1303 if (this->
shape() != rhs.
shape())
return false;
1438 return *
this += rhs;
1458 return *
this -= rhs;
1478 return *
this *= rhs;
1500 return *
this /= rhs;
1511 return *
this == rhs;
1590 "[ERROR] try to append a null Tensor.%s",
"\n");
1592 "[ERROR] try to append a Tensor with rank not match.%s",
"\n");
1594 for (
unsigned int i = 0; i < rhs.
shape().size(); i++) {
1596 "[ERROR] dimension mismatch @ rhs.rank: [%d] this: [%d] rhs: [%d]\n", i,
1597 this->shape()[i + 1], rhs.
shape()[i]);
1598 Nelem *= rhs.
shape()[i];
1603 if (rhs.
dtype() != this->dtype()) {
1612 this->_impl->_shape[0] += 1;
1614 this->_impl->_storage.resize(oldsize + Nelem);
1615 memcpy(((
char *)this->_impl->_storage.data()) +
1616 oldsize *
Type.typeSize(this->dtype()) /
sizeof(
char),
1617 in._impl->_storage.data(),
Type.typeSize(in.
dtype()) * Nelem);
1633 "[ERROR] try to append a null Tensor.%s",
"\n");
1635 "[ERROR] append a storage to Tensor can only accept rank-2 Tensor.%s",
"\n");
1641 if (srhs.
dtype() != this->dtype()) {
1646 this->_impl->_shape[0] += 1;
1648 this->_impl->_storage.resize(oldsize + in.
size());
1649 memcpy(((
char *)this->_impl->_storage.data()) +
1650 oldsize *
Type.typeSize(this->dtype()) /
sizeof(
char),
1693 "[ERROR] trying to append a scalar into multidimentional Tensor is not "
1694 "allow.\n Only rank-1 Tensor can accept scalar append.%s",
1697 "[ERROR] append require the Tensor to be contiguous. suggestion: call "
1698 "contiguous() or contiguous_() first.",
1700 this->_impl->_shape[0] += 1;
1701 this->_impl->_storage.append(rhs);
1712 std::vector<Tensor>
Svd(
const bool &is_UvT =
true)
const;
1719 std::vector<Tensor>
Eigh(
const bool &is_V =
true,
const bool &row_v =
false)
const;
1819 Tensor
operator+(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1820 Tensor
operator-(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1821 Tensor
operator*(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1822 Tensor
operator/(
const Tensor &lhs,
const Tensor::Tproxy &rhs);
1824 Tensor
operator+(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1825 Tensor
operator-(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1826 Tensor
operator*(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1827 Tensor
operator/(
const Tensor &lhs,
const Scalar::Sproxy &rhs);
1829 std::ostream &
operator<<(std::ostream &os,
const Tensor &in);
1830 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:1039
const unsigned int & dtype() const
the dtype-id of current Storage, see cytnx::Type for more details.
Definition Storage.hpp:1191
Storage astype(const unsigned int &new_type) const
cast the type of current Storage
Definition Storage.hpp:1185
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1307
an tensor (multi-dimensional array)
Definition Tensor.hpp:345
void append(const Storage &srhs)
the append function of the Storage.
Definition Tensor.hpp:1628
Tensor & operator*=(const T &rc)
multiplication assignment operator with a Tensor or a scalar.
Tensor & Inv_(const double &clip)
the Inv_ member function. Same as cytnx::linalg::Inv_(Tensor &Tin, const double &clip)
Definition Tensor.cpp:1319
Tensor & operator/=(const T &rc)
division assignment operator with a Tensor or a scalar.
Tensor operator-()
The negation function.
Definition Tensor.hpp:1531
void fill(const T &val)
fill all the element of current Tensor with the value.
Definition Tensor.hpp:1294
Tensor InvM() const
the InvM member function. Same as cytnx::linalg::InvM(const Tensor &Tin), where Tin is the current Te...
Definition Tensor.cpp:1318
bool same_data(const Tensor &rhs) const
Definition Tensor.cpp:1358
void to_(const int &device)
move the current Tensor to the device.
Definition Tensor.hpp:869
Tensor reshape(const std::vector< cytnx_uint64 > &new_shape) const
Definition Tensor.hpp:1028
Tensor(const std::vector< cytnx_uint64 > &shape, const unsigned int &dtype=Type.Double, const int &device=-1, const bool &init_zero=1)
Construct a new Tensor object.
Definition Tensor.hpp:739
void append(const T &rhs)
the append function of the scalar.
Definition Tensor.hpp:1691
Tensor & operator-=(const T &rc)
subtraction assignment operator with a Tensor or a scalar.
Tensor & Add_(const T &rhs)
Addition function with a Tensor or a scalar, inplacely. Same as operator+=(const T &rhs).
Definition Tensor.hpp:1437
Tensor Abs() const
the Abs member function. Same as linalg::Abs(const Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1349
Tensor reshape(const std::initializer_list< cytnx_int64 > &new_shape) const
Definition Tensor.hpp:1039
std::string device_str() const
the device (in string) of the Tensor
Definition Tensor.hpp:789
void reshape_(const std::vector< cytnx_int64 > &new_shape)
reshape the Tensor, inplacely
Definition Tensor.hpp:978
Tensor contiguous_()
Make the Tensor contiguous by coalescing the memory (storage), inplacely.
Definition Tensor.hpp:952
static Tensor Load(const std::string &fname)
Load current Tensor from file.
Definition Tensor.cpp:937
Tensor permute_(const std::vector< cytnx_uint64 > &rnks)
Definition Tensor.hpp:873
Tensor Mul(const T &rhs)
Multiplication function with a Tensor or a scalar. Same as cytnx::operator*(const Tensor &self,...
Definition Tensor.hpp:1467
unsigned int dtype() const
the dtype-id of the Tensor
Definition Tensor.hpp:768
Tensor Sub(const T &rhs)
Subtraction function with a Tensor or a scalar. Same as cytnx::operator-(const Tensor &self,...
Definition Tensor.hpp:1447
Tensor Inv(const double &clip) const
the Inv member function. Same as cytnx::linalg::Inv(const Tensor &Tin, const double &clip)
Definition Tensor.cpp:1323
Tensor contiguous() const
Make the Tensor contiguous by coalescing the memory (storage).
Definition Tensor.hpp:932
void Tofile(const std::string &fname) const
Definition Tensor.cpp:867
T & at(const std::vector< cytnx_uint64 > &locator)
[C++ only] get an element at specific location.
Definition Tensor.hpp:1101
Tensor reshape(const std::vector< cytnx_int64 > &new_shape) const
return a new Tensor that is reshaped.
Definition Tensor.hpp:1019
T & item()
get an from a rank-0 Tensor
Definition Tensor.hpp:1155
Tensor clone() const
return a clone of the current Tensor.
Definition Tensor.hpp:820
std::vector< Tensor > Eigh(const bool &is_V=true, const bool &row_v=false) const
the Eigh member function. Same as cytnx::linalg::Eigh(const Tensor &Tin, const bool &is_V,...
Definition Tensor.cpp:1310
void append(const Tensor &rhs)
the append function.
Definition Tensor.hpp:1584
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:1234
Tensor Norm() const
the Norm member function. Same as linalg::Norm(const Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1336
Tensor astype(const int &new_type) const
return a new Tensor that cast to different dtype.
Definition Tensor.hpp:1068
Tensor & Div_(const T &rhs)
Division function with a Tensor or a scalar, inplacely. Same as operator/=(const T &rhs).
Definition Tensor.hpp:1499
Tensor & operator+=(const T &rc)
addition assignment operator with a Tensor or a scalar.
Tensor Conj() const
the Conj member function. Same as cytnx::linalg::Conj(const Tensor &Tin), where Tin is the current Te...
Definition Tensor.cpp:1329
Tensor Trace(const cytnx_uint64 &a=0, const cytnx_uint64 &b=1) const
the Trace member function. Same as linalg::Trace(const Tensor &Tin, const cytnx_uint64 &a,...
Definition Tensor.cpp:1353
Tensor & Pow_(const cytnx_double &p)
the Pow_ member function. Same as linalg::Pow_(Tensor &Tin, const cytnx_double &p),...
Definition Tensor.cpp:1340
std::vector< Tensor > Svd(const bool &is_UvT=true) const
the SVD member function. Same as cytnx::linalg::Svd(const Tensor &Tin, const bool &is_UvT) ,...
Definition Tensor.cpp:1307
std::string dtype_str() const
the dtype (in string) of the Tensor
Definition Tensor.hpp:782
Tensor & Mul_(const T &rhs)
Multiplication function with a Tensor or a scalar, inplacely. Same as operator*=(const T &rhs).
Definition Tensor.hpp:1477
cytnx_uint64 rank() const
the rank of the Tensor
Definition Tensor.hpp:801
const bool & is_contiguous() const
Definition Tensor.hpp:871
Tensor Exp() const
the Exp member function. Same as linalg::Exp(const Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1335
Tensor & Abs_()
the Abs_ member function. Same as linalg::Abs_(Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1345
Tensor Add(const T &rhs)
Addition function with a Tensor or a scalar. Same as cytnx::operator+(const Tensor &self,...
Definition Tensor.hpp:1427
void flatten_()
The flatten function, inplacely.
Definition Tensor.hpp:1554
void Save(const std::string &fname) const
Save current Tensor to file.
Definition Tensor.cpp:891
Tensor flatten() const
The flatten function.
Definition Tensor.hpp:1540
Tensor & Conj_()
the Conj_ member function. Same as cytnx::linalg::Conj_(Tensor &Tin), where Tin is the current Tensor...
Definition Tensor.cpp:1325
Tensor Pow(const cytnx_double &p) const
the Pow member function. Same as linalg::Pow(const Tensor &Tin, const cytnx_double &p),...
Definition Tensor.cpp:1338
int device() const
the device-id of the Tensor
Definition Tensor.hpp:775
Tensor real()
return the real part of the tensor.
Definition Tensor.cpp:985
Tensor imag()
return the imaginary part of the tensor.
Definition Tensor.cpp:992
Tensor to(const int &device) const
copy a tensor to new device
Definition Tensor.hpp:846
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:1202
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:1257
Tensor Max() const
the Max member function. Same as linalg::Max(const Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1350
Tensor permute(const std::vector< cytnx_uint64 > &rnks) const
perform tensor permute on the cytnx::Tensor and return a new instance.
Definition Tensor.hpp:904
Tensor Div(const T &rhs)
Division function with a Tensor or a scalar. Same as cytnx::operator/(const Tensor &self,...
Definition Tensor.hpp:1488
Tensor Mod(const T &rhs)
Definition Tensor.hpp:1521
bool equiv(const Tensor &rhs)
compare the shape of two tensors.
Definition Tensor.hpp:1302
void Init(const std::vector< cytnx_uint64 > &shape, const unsigned int &dtype=Type.Double, const int &device=-1, const bool &init_zero=true)
initialize a Tensor
Definition Tensor.hpp:709
Tensor Cpr(const T &rhs)
The comparison function.
Definition Tensor.hpp:1510
Tensor & Exp_()
the Exp_ member function. Same as linalg::Exp_(Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1331
Tensor & InvM_()
the InvM_ member function. Same as cytnx::linalg::InvM_(Tensor &Tin), where Tin is the current Tensor...
Definition Tensor.cpp:1314
const std::vector< cytnx_uint64 > & shape() const
the shape of the Tensor
Definition Tensor.hpp:795
Tensor Min() const
the Min member function. Same as linalg::Min(const Tensor &Tin), where Tin is the current Tensor.
Definition Tensor.cpp:1351
const T & at(const std::vector< cytnx_uint64 > &locator) const
Definition Tensor.hpp:1109
Storage & storage() const
return the storage of current Tensor.
Definition Tensor.hpp:1277
static Tensor from_storage(const Storage &in)
Definition Tensor.hpp:755
static Tensor Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
Definition Tensor.cpp:930
Tensor & Sub_(const T &rhs)
Subtraction function with a Tensor or a scalar, inplacely. Same as operator-=(const T &rhs).
Definition Tensor.hpp:1457
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
Definition Accessor.hpp:12
Device_class Device
data on which devices.
Definition Device.cpp:140
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication operator between two UniTensor.
double cytnx_double
Definition Type.hpp:43
uint32_t cytnx_uint32
Definition Type.hpp:46
bool cytnx_bool
Definition Type.hpp:54
std::complex< double > cytnx_complex128
Definition Type.hpp:53
float cytnx_float
Definition Type.hpp:44
std::ostream & operator<<(std::ostream &os, const Scalar &in)
The stream operator for Scalar objects.
Definition Scalar.cpp:10
int16_t cytnx_int16
Definition Type.hpp:50
std::complex< float > cytnx_complex64
Definition Type.hpp:52
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction operator between two UniTensor.
int32_t cytnx_int32
Definition Type.hpp:49
uint16_t cytnx_uint16
Definition Type.hpp:47
uint64_t cytnx_uint64
Definition Type.hpp:45
int64_t cytnx_int64
Definition Type.hpp:48
Storage_init_interface __SII
Definition Storage.cpp:12
Type_class Type
data type
Definition Type.cpp:23
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addtion operator between two UniTensor.
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division operator between two UniTensor.