Skip to content

Commit

Permalink
templatized the type of Tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Jul 3, 2024
1 parent eb9eab4 commit 0e3a8d9
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 231 deletions.
1 change: 1 addition & 0 deletions regtest/basic/rt-make-0/config
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
type=make
#should we rename this to something meaningful? like "rt-VectorTensor"?
4 changes: 3 additions & 1 deletion regtest/basic/rt-make-4/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ int main () {
PLMD::TensorGeneric<4,4> mat;
PLMD::TensorGeneric<1,4> evec;
PLMD::VectorGeneric<4> eval_underlying;


//The both of the two following lines are scary, but on my machine are equivalent
//PLMD::Vector1d* eval=reinterpret_cast<PLMD::Vector1d*>(eval_underlying.data());
auto eval = new(&eval_underlying[0]) PLMD::VectorGeneric<1>;

mat[1][0]=mat[0][1]=3.0;
Expand Down
12 changes: 6 additions & 6 deletions src/tools/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ class Communicator {
template <typename T, unsigned n> explicit Data(VectorTyped<T,n> *p,int s): pointer(p), size(n*s), nbytes(sizeof(T)), type(getMPIType<T>()) {}
/// Init from reference to VectorGeneric
template <typename T, unsigned n> explicit Data(VectorTyped<T,n> &p): pointer(&p), size(n), nbytes(sizeof(T)), type(getMPIType<T>()) {}
/// Init from pointer to TensorGeneric
template <unsigned n,unsigned m> explicit Data(TensorGeneric<n,m> *p,int s): pointer(p), size(n*m*s), nbytes(sizeof(double)), type(getMPIType<double>()) {}
/// Init from reference to TensorGeneric
template <unsigned n,unsigned m> explicit Data(TensorGeneric<n,m> &p): pointer(&p), size(n*m), nbytes(sizeof(double)), type(getMPIType<double>()) {}
/// Init from pointer to TensorTyped
template <typename T, unsigned n,unsigned m> explicit Data(TensorTyped<T,n,m> *p,int s): pointer(p), size(n*m*s), nbytes(sizeof(T)), type(getMPIType<T>()) {}
/// Init from reference to TensorTyped
template <typename T, unsigned n,unsigned m> explicit Data(TensorTyped<T,n,m> &p): pointer(&p), size(n*m), nbytes(sizeof(T)), type(getMPIType<T>()) {}
/// Init from reference to std::vector
template <typename T> explicit Data(std::vector<T>&v) {
Data d(v.data(),v.size()); pointer=d.pointer; size=d.size; type=d.type;
Expand All @@ -106,8 +106,8 @@ class Communicator {
template <typename T> explicit ConstData(const T&p): pointer(&p), size(1), nbytes(sizeof(T)), type(getMPIType<T>()) {}
template <typename T,unsigned n> explicit ConstData(const VectorTyped<T,n> *p,int s): pointer(p), size(n*s), nbytes(sizeof(T)), type(getMPIType<T>()) {}
template <typename T,unsigned n> explicit ConstData(const VectorTyped<T,n> &p): pointer(&p), size(n), nbytes(sizeof(T)), type(getMPIType<T>()) {}
template <unsigned n,unsigned m> explicit ConstData(const TensorGeneric<n,m> *p,int s): pointer(p), size(n*m*s), nbytes(sizeof(double)), type(getMPIType<double>()) {}
template <unsigned n,unsigned m> explicit ConstData(const TensorGeneric<n,m> &p): pointer(&p), size(n*m), nbytes(sizeof(double)), type(getMPIType<double>()) {}
template <typename T, unsigned n,unsigned m> explicit ConstData(const TensorTyped<T,n,m> *p,int s): pointer(p), size(n*m*s), nbytes(sizeof(T)), type(getMPIType<T>()) {}
template <typename T, unsigned n,unsigned m> explicit ConstData(const TensorTyped<T,n,m> &p): pointer(&p), size(n*m), nbytes(sizeof(T)), type(getMPIType<T>()) {}
template <typename T> explicit ConstData(const std::vector<T>&v) {
ConstData d(v.data(),v.size()); pointer=d.pointer; size=d.size; type=d.type;
}
Expand Down
Loading

0 comments on commit 0e3a8d9

Please sign in to comment.