geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
TensorOneD.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 TENSORONED_HPP_INCLUDE
7 #define TENSORONED_HPP_INCLUDE
8 
9 #include <cstdio>
10 #include <memory>
11 #include <vector>
12 
13 namespace geopm
14 {
15  class TensorMath;
16 
20  class TensorOneD
21  {
22  public:
23  TensorOneD();
27  TensorOneD(size_t n);
31  TensorOneD(const TensorOneD &other);
32 
33  TensorOneD(TensorOneD &&other);
39  TensorOneD(const std::vector<double> &input);
40 
47  TensorOneD(const std::vector<double> &input, std::shared_ptr<TensorMath> math);
48 
56  void set_dim(size_t dim);
60  size_t get_dim() const;
61 
62  TensorOneD operator+(const TensorOneD &other) const;
63  TensorOneD operator-(const TensorOneD &other) const;
64  double operator*(const TensorOneD &other) const;
68  TensorOneD& operator=(const TensorOneD &other);
69 
71 
73  // data
76  bool operator==(const TensorOneD &other) const;
77 
83  double &operator[](size_t idx);
89  double operator[](size_t idx) const;
90 
91  TensorOneD sigmoid() const;
92 
96  const std::vector<double> &get_data() const;
97 
98  virtual ~TensorOneD() = default;
99  private:
100  std::vector<double> m_vec;
101  std::shared_ptr<TensorMath> m_math;
102  };
103 }
104 #endif /* TENSORONED_HPP_INCLUDE */
Class to store and perform operations on 1D Tensors, aka vectors, suitable for use in feed-forward ne...
Definition: TensorOneD.hpp:21
double & operator[](size_t idx)
Reference indexing of 1D tensor value at idx.
Definition: TensorOneD.cpp:78
bool operator==(const TensorOneD &other) const
Overload == operator to do comparison of the underlying.
Definition: TensorOneD.cpp:73
const std::vector< double > & get_data() const
Return the tensor as a vector of doubles.
Definition: TensorOneD.cpp:88
TensorOneD operator+(const TensorOneD &other) const
Definition: TensorOneD.cpp:93
virtual ~TensorOneD()=default
void set_dim(size_t dim)
Set length of 1D tensor.
Definition: TensorOneD.cpp:47
size_t get_dim() const
Get the length of the 1D tensor.
Definition: TensorOneD.cpp:52
double operator*(const TensorOneD &other) const
Definition: TensorOneD.cpp:103
TensorOneD sigmoid() const
Definition: TensorOneD.cpp:108
TensorOneD()
Definition: TensorOneD.cpp:15
TensorOneD operator-(const TensorOneD &other) const
Definition: TensorOneD.cpp:98
TensorOneD & operator=(const TensorOneD &other)
Overload = operator with an in-place deep copy.
Definition: TensorOneD.cpp:57
Definition: Accumulator.cpp:12