Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Tensor_Base class definition file -*- C++ -*-
/* Copyright 2008 Mike Williams (mwill@jlab.org)
*
* This file is part of qft++.
*
* qft++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qft++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qft++. If not, see <http://www.gnu.org/licenses/>.
*/
// Author: Mike Williams
#ifndef _Tensor_Base_H
#define _Tensor_Base_H
#include "qft++/c++-template-utils/Conversion.hh"
#include <cassert>
//_____________________________________________________________________________
/** @file Tensor_Base.h
* @brief Tensor_Base class definition file.
*/
//_____________________________________________________________________________
using namespace std;
//_____________________________________________________________________________
/** @class Tensor_Base
* @author Mike Williams
*
* @brief Base class for all Tensor template classes.
*
* This is the base class for all Tensor instantiations. It is thru inheritance
* from this class that the Tensor template classes are able to correctly
* implement multiplication/contraction.
*/
//_____________________________________________________________________________
class Tensor_Base {
protected:
int _rank; ///< Rank of the Tensor
// protected functions:
/// Copy @a tbase data members
void _Copy(const Tensor_Base &__tbase){
_rank = __tbase._rank;
}
/// Assert that @a tbase and @a this have the same rank
inline bool RankAssert(const Tensor_Base &__tbase) {
assert(this->_rank == __tbase._rank);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
}
public:
// create/copy/destroy:
/** Default Constructor */
Tensor_Base(){_rank = 0;}
/** Constructor */
Tensor_Base(int __rank){_rank = __rank;}
/**Copy Ctor*/
Tensor_Base(const Tensor_Base &__tbase){this->_Copy(__tbase);}
/** Destructor */
virtual ~Tensor_Base(){}
// Getters:
/** Returns the rank of the Tensor */
inline int Rank() const {return _rank;}
/// Is @a tbase the same rank as @a this?
inline bool RankCheck(const Tensor_Base &__tbase) const {
return (this->_rank == __tbase._rank);
}
};
//_____________________________________________________________________________
/// Is T a Tensor? (does it inherit from Tensor_Base?)
#define IsTensor(__T) IsDerived(__T,Tensor_Base)
#include "qft++/matrix/Matrix_Base.hh"
/// Is T a scalar? (is it NOT a Tensor or Matrix)
#define IsScalar(__T) (!IsMatrix(__T) && !IsTensor(__T))
/// Is T a scalar that should be passed by value?
#define IsScalarValType(__T) (IsScalar(__T) && PassByValue(__T))
/// Is T a scalar that should be passed by reference?
#define IsScalarRefType(__T) (IsScalar(__T) && !PassByValue(__T))
//_____________________________________________________________________________
#endif /* _Tensor_Base_H */