openGPMP
Open Source Mathematics Package
tensor.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
34 #ifndef TENSOR_HPP
35 #define TENSOR_HPP
36 
37 #include <iostream>
38 #include <vector>
39 
40 namespace gpmp {
41 
42 namespace linalg {
43 
51 class Tensor {
52  public:
56  Tensor();
57 
65  explicit Tensor(const std::vector<size_t> &dimensions);
66 
75  Tensor(const std::vector<std::vector<std::vector<double>>> &data);
76 
83  Tensor add(const Tensor &other) const;
84 
90  Tensor multiply(double scalar) const;
91 
98  Tensor multiply(const Tensor &other) const;
99 
107  double get(const std::vector<size_t> &indices) const;
108 
116  void set(const std::vector<size_t> &indices, double value);
117 
121  void display() const;
122 
123  private:
125  std::vector<std::vector<std::vector<double>>> data_;
127  size_t dimensions_[3];
128 };
129 
130 } // namespace linalg
131 } // namespace gpmp
132 
133 #endif
Represents a 3D tensor with basic operations.
Definition: tensor.hpp:51
void set(const std::vector< size_t > &indices, double value)
Sets the value at the specified indices.
Definition: tensor.cpp:159
size_t dimensions_[3]
Definition: tensor.hpp:127
Tensor add(const Tensor &other) const
Adds another tensor to the current tensor.
Definition: tensor.cpp:75
double get(const std::vector< size_t > &indices) const
Gets the value at the specified indices.
Definition: tensor.cpp:143
void display() const
Displays the tensor.
Definition: tensor.cpp:176
Tensor multiply(double scalar) const
Multiplies the tensor by a scalar value.
Definition: tensor.cpp:97
Tensor()
Default constructor Creates an empty tensor.
Definition: tensor.cpp:38
std::vector< std::vector< std::vector< double > > > data_
< 3D vector representing the tensor data
Definition: tensor.hpp:125
The source C++ openGPMP namespace.