KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Tensor.h
Go to the documentation of this file.
1
27#ifndef KIDS_TENSOR_H
28#define KIDS_TENSOR_H
29
30#include <memory>
31
32#include "kids/Node.h"
33#include "kids/Shape.h"
34#include "kids/Types.h"
35#include "kids/fmt.h"
36
37namespace PROJECT_NS {
38
42template <typename T>
43class Tensor final : public Node {
44 public:
45 using SizeType = std::size_t;
46 using DataType = T;
47
48 Tensor(Shape S, const std::string& info = "") : _shape{S}, _doc_info{info} {
49 _type = as_enum<T>();
50 _size = _shape.size();
51 _data = std::shared_ptr<std::vector<T>>(new std::vector<T>(_size, 0));
52 }
53
54 virtual std::string repr() {
55 std::ostringstream os;
56 T* ptr = _data->data();
57 os << as_str<T>();
58 os << FMT(0) << _size;
59 os << "\n";
60 for (int i = 0; i < _size; ++i) os << FMT(8) << ptr[i];
61 return os.str();
62 }
63
64 virtual std::string help(const std::string& name) { return _doc_info; }
65
66 inline T* data() { return _data->data(); }
67
68 inline std::size_t size() { return _size; }
69
70 inline Shape& shape() { return _shape; }
71
72 private:
73 std::size_t _size;
75 std::string _doc_info;
76 std::shared_ptr<std::vector<T>> _data;
77};
78
79}; // namespace PROJECT_NS
80
81#endif // KIDS_TENSOR_H
Declaration of the Node class used for DataSet.
Declaration of the Shape class.
definition of types in the project and some utiles for types
Node class is an abstract interface.
Definition Node.h:39
kids_dtype _type
Definition Node.h:50
Shape class provide information about of a Tensor's shape.
Definition Shape.h:50
Tensor class is the container for array-like data.
Definition Tensor.h:43
Tensor(Shape S, const std::string &info="")
Definition Tensor.h:48
virtual std::string repr()
Definition Tensor.h:54
std::size_t _size
Definition Tensor.h:73
std::size_t SizeType
Definition Tensor.h:45
std::shared_ptr< std::vector< T > > _data
Definition Tensor.h:76
std::string _doc_info
Definition Tensor.h:75
virtual std::string help(const std::string &name)
Definition Tensor.h:64
Shape & shape()
Definition Tensor.h:70
std::size_t size()
Definition Tensor.h:68
utils for formating
#define FMT(X)
Definition fmt.h:40
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39