AFLOW
 
Loading...
Searching...
No Matches
aurostd_xtensor.h
Go to the documentation of this file.
1//****************************************************************************
2// * *
3// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
4// * Aflow MARCO ESTERS - Duke University 2018-2021 *
5// * *
6//****************************************************************************
7
8#ifndef _AUROSTD_XTENSOR_H_
9#define _AUROSTD_XTENSOR_H_
10
11#include <vector>
12
13#include <sys/types.h>
14
15#include "aurostd_defs.h"
16#include "aurostd_xmatrix.h"
17#include "aurostd_xvector.h"
18
19namespace aurostd {
20 template <class utype> class xtensor; // Forward declaration of xtensor for _subtensor
21 template <class utype> class _subtensor {
22 public:
23 _subtensor(const int&, utype*, const xtensor<utype>&);
24 _subtensor(const std::vector<int>&, utype*, const xtensor<utype>&);
25 _subtensor(const aurostd::xvector<int>&, utype*, const xtensor<utype>&);
27
30 int shift;
31
32 _subtensor<utype>& operator[](const int&);
33 _subtensor<utype>& operator()(const std::vector<int>&);
35 _subtensor<utype>& operator+=(utype scalar);
36 _subtensor<utype>& operator-=(utype scalar);
37 _subtensor<utype>& operator*=(utype scalar);
38 _subtensor<utype>& operator/=(utype scalar);
43
44 _subtensor<utype>& operator=(const utype&);
47 _subtensor<utype>& operator=(const std::vector<utype>&);
50 operator utype() const;
51
52 [[nodiscard]] int getNumElements() const;
53 [[nodiscard]] utype get(const int&) const;
54 void set(const utype&);
55 void set(const utype&, const int&);
56
57 private:
58 bool sameShape(const _subtensor<utype>&);
59 bool sameShape(const xtensor<utype>&);
60 utype* corpus;
61 };
62} // namespace aurostd
63
64namespace aurostd {
65 template <class utype> class xtensor {
66 public:
67 xtensor(); // Default constructor
68 xtensor(const std::vector<int>&); // Constructor using vectors
69 xtensor(const std::vector<int>&, const std::vector<int>&); // Constructor using vectors
70 xtensor(const aurostd::xvector<int>&); // Constructor using xvectors
71 xtensor(const aurostd::xvector<int>&, const aurostd::xvector<int>&); // Constructor using xvectors
72 xtensor(const int&, const int& li = 1); // Constructor for a tensor with n dimensions of size n
73 xtensor(const _subtensor<utype>&); // Constructor from _subtensor
74 xtensor(const xtensor<utype>&); // Copy Constructor
75 xtensor<utype> operator=(const xtensor<utype>&); // Copy constructor
76 xtensor<utype> operator=(const _subtensor<utype>&); // Copy constructor
77 ~xtensor(); // Destructor
78 void buildTensor(const std::vector<int>&, const std::vector<int>&);
79
80 int* shape; // The shape of the tensor
81 bool is_cubic; // True when all dimensions have the same size
82 int nelements; // Number of elements in the tensor
83 uint ndim; // Number of dimensions of the tensor
84 int* uindex; // The upper indices of each tensor dimension
85 int* lindex; // The lower indices of each tensor dimension
86 int* shifts; // Number of values to skip when incrementing an index in each dimension
87
88 // Indexing operators
89 _subtensor<utype> operator()(std::vector<int>) const;
92
93 // Unary operators
99
105
106 // Functions
107 void set(const utype&);
108 void set(const utype&, const int&);
109 void reset();
110 void clear();
111 [[nodiscard]] bool sameShape(const xtensor<utype>&) const;
112 [[nodiscard]] bool sameShape(const _subtensor<utype>&) const;
113
114 [[nodiscard]] utype get(const int&) const;
115 void abs();
116 void ceil();
117 void floor();
118 void nint();
119 void round(const utype&);
120 void sign();
121 utype max();
122 utype min();
123 utype sum();
124
125 private:
126 utype* corpus; // Tensor values
127 bool checkInit(const std::vector<int>&, const std::vector<int>&);
128 char size; // Size of the data type used for the tensor
129 long int tsize; // Memory to allocate
130 };
131} // namespace aurostd
132
133// Unary operators
134namespace aurostd {
135 template <class utype> xtensor<utype> operator+(const xtensor<utype>&) __xprototype;
136 template <class utype> xtensor<utype> operator-(xtensor<utype>) __xprototype;
137 template <class utype> xtensor<utype> operator+(const _subtensor<utype>&) __xprototype;
138 template <class utype> xtensor<utype> operator-(const _subtensor<utype>&) __xprototype;
139} // namespace aurostd
140
141// Binary operators
142namespace aurostd {
143 // with scalars
144 template <class utype> xtensor<utype> operator*(xtensor<utype>, const utype&) __xprototype;
145 template <class utype> xtensor<utype> operator*(const utype&, const xtensor<utype>&) __xprototype;
146 template <class utype> xtensor<utype> operator/(xtensor<utype>, const utype&) __xprototype;
147 // with xtensors
148 template <class utype> xtensor<utype> operator+(xtensor<utype>, const xtensor<utype>&) __xprototype;
149 template <class utype> xtensor<utype> operator-(xtensor<utype>, const xtensor<utype>&) __xprototype;
150 // with subtensors
151 template <class utype> xtensor<utype> operator+(const xtensor<utype>&, const _subtensor<utype>&) __xprototype;
152 template <class utype> xtensor<utype> operator+(const _subtensor<utype>&, const xtensor<utype>&) __xprototype;
153 template <class utype> xtensor<utype> operator+(const _subtensor<utype>&, const _subtensor<utype>&) __xprototype;
154 template <class utype> xtensor<utype> operator-(const xtensor<utype>&, const _subtensor<utype>&) __xprototype;
155 template <class utype> xtensor<utype> operator-(const _subtensor<utype>&, const xtensor<utype>&) __xprototype;
156 template <class utype> xtensor<utype> operator-(const _subtensor<utype>&, const _subtensor<utype>&) __xprototype;
157} // namespace aurostd
158
159// Functions
160namespace aurostd {
161 template <class utype> std::vector<utype> xtensor2vector(xtensor<utype>&) __xprototype;
162 template <class utype> std::vector<utype> xtensor2vector(const _subtensor<utype>&) __xprototype;
163 template <class utype> aurostd::xvector<utype> xtensor2xvector(xtensor<utype>&) __xprototype;
164 template <class utype> aurostd::xvector<utype> xtensor2xvector(const _subtensor<utype>&) __xprototype;
165 template <class utype> aurostd::xmatrix<utype> xtensor2xmatrix(xtensor<utype>&) __xprototype;
166 template <class utype> aurostd::xmatrix<utype> xtensor2xmatrix(const _subtensor<utype>&) __xprototype;
167 template <class utype> xtensor<utype> vector2xtensor(const std::vector<utype>&) __xprototype;
168 template <class utype> xtensor<utype> xvector2xtensor(const aurostd::xvector<utype>&) __xprototype;
169 template <class utype> xtensor<utype> xmatrix2xtensor(const aurostd::xmatrix<utype>&) __xprototype;
170 template <class utype> xtensor<utype> abs(xtensor<utype>) __xprototype;
171 template <class utype> xtensor<utype> abs(const _subtensor<utype>&) __xprototype;
172 template <class utype> xtensor<utype> ceil(xtensor<utype>) __xprototype;
173 template <class utype> xtensor<utype> ceil(const _subtensor<utype>&) __xprototype;
174 template <class utype> xtensor<utype> floor(xtensor<utype>) __xprototype;
175 template <class utype> xtensor<utype> floor(const _subtensor<utype>&) __xprototype;
176 template <class utype> xtensor<utype> nint(xtensor<utype>) __xprototype;
177 template <class utype> xtensor<utype> nint(const _subtensor<utype>&) __xprototype;
178 template <class utype> xtensor<utype> round(xtensor<utype>, const utype& tol = (utype) AUROSTD_ROUNDOFF_TOL) __xprototype;
179 template <class utype> xtensor<utype> round(const _subtensor<utype>&, const utype& tol = (utype) AUROSTD_ROUNDOFF_TOL) __xprototype;
180 template <class utype> xtensor<utype> sign(xtensor<utype>) __xprototype;
181 template <class utype> xtensor<utype> sign(const _subtensor<utype>&) __xprototype;
182 template <class utype> utype max(xtensor<utype>) __xprototype;
183 template <class utype> utype max(const _subtensor<utype>&) __xprototype;
184 template <class utype> utype min(xtensor<utype>) __xprototype;
185 template <class utype> utype min(const _subtensor<utype>&) __xprototype;
186 template <class utype> utype sum(xtensor<utype>) __xprototype;
187 template <class utype> utype sum(const _subtensor<utype>&) __xprototype;
188 template <class utype> utype trace(const xtensor<utype>&) __xprototype;
189 template <class utype> utype trace(const _subtensor<utype>&) __xprototype;
190 template <class utype> xtensor<utype> identity_tensor(const utype&, int) __xprototype;
191} // namespace aurostd
192
193// Ricci Tensor functions from old xtensor
194namespace aurostd {
195 int eijk(int, int, int);
196 int eijk(aurostd::xvector<int>);
197 int estarijk(int, int, int);
198 int estarijk(aurostd::xvector<int>);
199} // namespace aurostd
200
201#endif
202//****************************************************************************
203// * *
204// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
205// * Aflow MARCO ESTERS - Duke University 2018-2021 *
206// * *
207//****************************************************************************
unsigned uint
Definition aurostd.h:39
#define __xprototype
#define AUROSTD_ROUNDOFF_TOL
_subtensor< utype > & operator[](const int &)
const xtensor< utype > & _tensor
_subtensor< utype > & operator*=(utype scalar)
_subtensor< utype > & operator()(const std::vector< int > &)
bool sameShape(const _subtensor< utype > &)
_subtensor(const int &, utype *, const xtensor< utype > &)
void set(const utype &)
utype get(const int &) const
_subtensor< utype > & operator-=(utype scalar)
_subtensor< utype > & operator+=(utype scalar)
_subtensor< utype > & operator=(const utype &)
_subtensor< utype > & operator/=(utype scalar)
_subtensor< utype > operator[](int) const
xtensor< utype > & operator-=(utype)
xtensor< utype > & operator+=(utype)
xtensor< utype > & operator/=(utype)
void set(const utype &)
xtensor< utype > & operator*=(utype)
bool checkInit(const std::vector< int > &, const std::vector< int > &)
void buildTensor(const std::vector< int > &, const std::vector< int > &)
utype get(const int &) const
xtensor< utype > operator=(const xtensor< utype > &)
_subtensor< utype > operator()(std::vector< int >) const
void round(const utype &)
bool sameShape(const xtensor< utype > &) const
xmatrix< utype > xtensor2xmatrix(xtensor< utype > &tensor)
xvector< utype > xtensor2xvector(xtensor< utype > &tensor)
int estarijk(int i, int j, int k)
xmatrix< utype > sign(const xmatrix< utype > &a)
xtensor< utype > xmatrix2xtensor(const aurostd::xmatrix< utype > &xmat)
utype abs(const xcomplex< utype > &x)
xtensor< utype > identity_tensor(const utype &_type, int n)
xcomplex< utype > operator+(const xcomplex< utype > &x, const xcomplex< utype > &y)
std::vector< utype > xtensor2vector(xtensor< utype > &tensor)
__xprototype
Definition aurostd.h:175
xmatrix< utype > ceil(const xmatrix< utype > &a)
xmatrix< utype > floor(const xmatrix< utype > &a)
utype max(const vector< utype > vec)
xcomplex< utype > operator*(const xcomplex< utype > &x, const xcomplex< utype > &y)
xtensor< utype > xvector2xtensor(const aurostd::xvector< utype > &xvec)
int eijk(int i, int j, int k)
utype trace(const xmatrix< utype > &a)
utype min(const vector< utype > vec)
utype sum(const vector< utype > vec)
xmatrix< utype > nint(const xmatrix< utype > &a)
xcomplex< utype > operator-(const xcomplex< utype > &x, const xcomplex< utype > &y)
xcomplex< utype > operator/(const xcomplex< utype > &x, const xcomplex< utype > &y)
xtensor< utype > vector2xtensor(const std::vector< utype > &vec)
xmatrix< utype > round(const xmatrix< utype > &a)