geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
TensorTwoD.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef TENSORTWOD_HPP_INCLUDE
7 #define TENSORTWOD_HPP_INCLUDE
8 
9 #include <cstdint>
10 #include <memory>
11 #include <vector>
12 
13 #include "TensorOneD.hpp"
14 
15 namespace geopm
16 {
17  class TensorMath;
18 
21  class TensorTwoD
22  {
23  public:
24  TensorTwoD();
26  TensorTwoD(size_t rows, size_t cols);
28  TensorTwoD(size_t rows, size_t cols, std::shared_ptr<TensorMath> math);
32  TensorTwoD(const TensorTwoD &other);
33 
34  TensorTwoD(TensorTwoD &&other);
41  TensorTwoD(const std::vector<std::vector<double> > &input);
49  TensorTwoD(const std::vector<std::vector<double> > &input,
50  std::shared_ptr<TensorMath> math);
57  TensorTwoD(const std::vector<TensorOneD> &input);
65  TensorTwoD(const std::vector<TensorOneD> &input, std::shared_ptr<TensorMath> math);
69  size_t get_rows() const;
73  size_t get_cols() const;
86  void set_dim(size_t rows, size_t cols);
93  TensorOneD operator*(const TensorOneD &) const;
99  TensorOneD &operator[](size_t idx);
105  TensorOneD operator[](size_t idx) const;
109  TensorTwoD& operator=(const TensorTwoD &other);
110 
111  TensorTwoD& operator=(TensorTwoD &&other);
113  // data
116  bool operator==(const TensorTwoD &other) const;
117 
121  const std::vector<TensorOneD> &get_data() const;
122 
124  void set_data(const std::vector<TensorOneD> &);
125 
126  virtual ~TensorTwoD() = default;
127  private:
128  std::vector<TensorOneD> m_mat;
129  std::shared_ptr<TensorMath> m_math;
130  };
131 }
132 #endif
Class to store and perform operations on 1D Tensors, aka vectors, suitable for use in feed-forward ne...
Definition: TensorOneD.hpp:21
Class to manage data and operations related to 2D Tensors required for neural net inference.
Definition: TensorTwoD.hpp:22
size_t get_rows() const
Get number of rows in the 2D tensor.
Definition: TensorTwoD.cpp:80
TensorTwoD()
Definition: TensorTwoD.cpp:16
void set_data(const std::vector< TensorOneD > &)
Set the contents as a vector of tensors.
Definition: TensorTwoD.cpp:150
void set_dim(size_t rows, size_t cols)
Set dimensions of 2D tensor.
Definition: TensorTwoD.cpp:93
bool operator==(const TensorTwoD &other) const
Overload == operator to do comparison of the underlying.
Definition: TensorTwoD.cpp:140
TensorOneD & operator[](size_t idx)
Reference indexing of 1D Tensor at idx of the 2D Tensor.
Definition: TensorTwoD.cpp:112
virtual ~TensorTwoD()=default
TensorTwoD & operator=(const TensorTwoD &other)
Oerload = operator with an in-place deep copy.
Definition: TensorTwoD.cpp:122
TensorOneD operator*(const TensorOneD &) const
Multiply a 2D tensor by a 1D tensor.
Definition: TensorTwoD.cpp:107
const std::vector< TensorOneD > & get_data() const
Return the tensor as a vector of tensors.
Definition: TensorTwoD.cpp:145
size_t get_cols() const
get number of columns in 2D tensor
Definition: TensorTwoD.cpp:85
Definition: Accumulator.cpp:12