IOLink 1.11.0
Loading...
Searching...
No Matches
Matrix.h
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <initializer_list>
6#include <ostream>
7#include <string>
8
9#include <iolink/IOLinkAPI.h>
10#include <iolink/Vector.h>
11
12namespace iolink
13{
14
20template <typename ValueType, size_t N>
21class Matrix
22{
23public:
27 static Matrix identity();
28
34 static Matrix uniform(ValueType value);
35
41
57 explicit Matrix(const ValueType* values);
58
76 Matrix(const ValueType* values, bool isRowMajor);
77
95 explicit Matrix(std::initializer_list<ValueType> init);
96
97 bool operator==(const Matrix& other) const;
98 bool operator!=(const Matrix& other) const;
99
106 ValueType at(size_t row, size_t column) const;
107
114 ValueType operator()(size_t row, size_t column) const;
115
123 void setAt(size_t row, size_t column, ValueType value);
124
129
134
142
161 ValueType* data();
162
166 const ValueType* data() const;
167
171 std::string toString() const;
172
173 // ==================== //
174 // Arithmetic operators //
175 // ==================== //
176
177 Matrix operator-() const;
178
179 Matrix& operator+=(const Matrix& m);
180 Matrix& operator-=(const Matrix& m);
181
182 inline Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
183 inline Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
184
185 Matrix& operator*=(ValueType value);
186 Matrix& operator/=(ValueType value);
187
188 inline Matrix operator*(ValueType v) const { return Matrix(*this) *= v; }
189 inline Matrix operator/(ValueType v) const { return Matrix(*this) /= v; }
190
191 Vector<ValueType, N> operator*(const Vector<ValueType, N>& v) const;
192 Matrix operator*(const Matrix& m) const;
193
194private:
195 std::array<ValueType, N * N> m_data;
196};
197
201template <typename T, size_t N>
202inline std::ostream&
203operator<<(std::ostream& os, const Matrix<T, N>& m)
204{
205 os << m.toString();
206 return os;
207}
208
209//=======================//
210// Template declarations //
211//=======================//
212
213extern template class IOLINK_API_IMPORT Matrix<float, 3>;
214extern template class IOLINK_API_IMPORT Matrix<double, 3>;
215
216extern template class IOLINK_API_IMPORT Matrix<float, 4>;
217extern template class IOLINK_API_IMPORT Matrix<double, 4>;
218
219//======================//
220// Aliases declarations //
221//======================//
222
225
228
229} // end namespace iolink