sisi4s
Loading...
Searching...
No Matches
DryTensor.hpp
Go to the documentation of this file.
1#ifndef DRY_TENSOR_DEFINED
2#define DRY_TENSOR_DEFINED
3
5#include <util/Log.hpp>
6#include <cstdint>
7#include <vector>
8#include <string>
9
10namespace sisi4s {
11class DryMemory {
12public:
13 typedef std::pair<int64_t, SourceLocation> ExtendingResource;
14
15 static void allocate(int64_t size, SourceLocation const &location) {
16 currentTotalSize += size;
20 /*
21 LOG(2, "DryMemory") << "extending size=" << size << " at "
22 << location << std::endl;
23 } else {
24
25 LOG(2, "DryMemory") << "non-extending size=" << size << " at "
26 << location << std::endl;
27 */
28 }
29 }
30 static void free(int64_t size) { currentTotalSize -= size; }
32 static std::vector<ExtendingResource> extendingResources;
33};
34
35template <typename F = double>
36class DryTensor {
37public:
46 DryTensor(int order_,
47 int const *lens_,
48 int const *syms_,
49 SourceLocation const &location_ = SourceLocation())
50 : order(order_)
51 , lens(order_)
52 , syms(order_)
53 , location(location_) {
54 for (int i(0); i < order_; ++i) {
55 lens[i] = lens_[i];
56 syms[i] = syms_[i];
57 }
58 allocate();
59 }
61 SourceLocation const &location_ = SourceLocation())
62 : order(A.order)
63 , lens(A.lens)
64 , syms(A.syms)
65 , location(location_)
66 , name(A.name) {
67 allocate();
68 }
69 virtual ~DryTensor() { free(); }
70 virtual void use() {}
71
72 int64_t getElementsCount() const {
73 int64_t elementsCount(1);
74 for (int i(0); i < order; ++i) { elementsCount *= lens[i]; }
75 return elementsCount;
76 }
77
78 void set_name(std::string const &name_) { name = name_; }
79 std::string const &get_name() const { return name; }
80
81 int order;
82 std::vector<int> lens, syms;
84 std::string name;
85
86protected:
87 void allocate() {
88 size = sizeof(F) * getElementsCount();
90 }
92 int64_t size;
93};
94
95template <typename F = double>
96class DryMatrix : public DryTensor<F> {
97public:
98 DryMatrix(int rowCount,
99 int columnCount,
100 int sym,
102};
103
104template <typename F = double>
105class DryVector : public DryTensor<F> {
106public:
107 DryVector(int elementsCount,
109};
110
111template <typename F = double>
112class DryScalar : public DryTensor<F> {
113public:
115 DryScalar(F const value, SourceLocation const &location = SourceLocation());
116};
117} // namespace sisi4s
118
119#endif
Definition DryTensor.hpp:96
DryMatrix(int rowCount, int columnCount, int sym, SourceLocation const &location=SourceLocation())
Definition DryTensor.hpp:11
std::pair< int64_t, SourceLocation > ExtendingResource
Definition DryTensor.hpp:13
static void free(int64_t size)
Definition DryTensor.hpp:30
static int64_t currentTotalSize
Definition DryTensor.hpp:31
static void allocate(int64_t size, SourceLocation const &location)
Definition DryTensor.hpp:15
static std::vector< ExtendingResource > extendingResources
Definition DryTensor.hpp:32
static int64_t maxTotalSize
Definition DryTensor.hpp:31
Definition DryTensor.hpp:112
Definition DryTensor.hpp:36
virtual void use()
Definition DryTensor.hpp:70
int64_t getElementsCount() const
Definition DryTensor.hpp:72
SourceLocation location
Definition DryTensor.hpp:83
DryTensor(int order_, int const *lens_, int const *syms_, SourceLocation const &location_=SourceLocation())
Creates a dry tensor for resource consumption estimation without actually allocating its data....
Definition DryTensor.hpp:46
std::vector< int > syms
Definition DryTensor.hpp:82
void allocate()
Definition DryTensor.hpp:87
DryTensor(DryTensor const &A, SourceLocation const &location_=SourceLocation())
Definition DryTensor.hpp:60
std::string const & get_name() const
Definition DryTensor.hpp:79
std::vector< int > lens
Definition DryTensor.hpp:82
void set_name(std::string const &name_)
Definition DryTensor.hpp:78
int order
Definition DryTensor.hpp:81
void free()
Definition DryTensor.hpp:91
virtual ~DryTensor()
Definition DryTensor.hpp:69
int64_t size
Definition DryTensor.hpp:92
std::string name
Definition DryTensor.hpp:84
Definition DryTensor.hpp:105
Definition SourceLocation.hpp:12
Definition Algorithm.hpp:10