Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Matrix.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Math_LinearAlgebra_Matrix_h_
5#define _Stroika_Foundation_Math_LinearAlgebra_Matrix_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Sequence.h"
11
12#include "Vector.h"
13
14/**
15 * \file
16 *
17 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
18 *
19 * TODO
20 * o Look into integrating with popular C++ matrix libraries, blas, eigen, etc...
21 */
22
23namespace Stroika::Foundation::Math::LinearAlgebra {
24
25 /**
26 */
27 template <typename T>
28 class Matrix {
29 public:
30 struct DimensionType {
31 size_t fRows;
32 size_t fColumns;
33 };
34
35 public:
36 /**
37 * All constructors require dimensions of the matrix (rows/columns).
38 *
39 * The one with no other arguments, initializes to zeros.
40 *
41 * The last 2 fill, but either with a hardwired value, or with a computed value (function called foreach row and within a row each column)
42 */
43 Matrix (const DimensionType& dimensions);
44 Matrix (size_t rows, size_t columns);
45 Matrix (const DimensionType& dimensions, Common::ArgByValueType<T> fillValue);
46 Matrix (size_t rows, size_t columns, Common::ArgByValueType<T> fillValue);
47 Matrix (const DimensionType& dimensions, const function<T ()>& filler);
48
49 public:
50 static Matrix<T> Identity (const DimensionType& dimensions);
51
52 public:
53 nonvirtual DimensionType GetDimensions () const;
54
55 public:
56 nonvirtual Containers::Sequence<Vector<T>> GetRows () const;
57
58 public:
59 nonvirtual Containers::Sequence<Vector<T>> GetColumns () const;
60
61 public:
62 nonvirtual T GetAt (size_t r, size_t c) const;
63
64 public:
65 nonvirtual void SetAt (size_t r, size_t c, T v);
66
67 private:
68 struct ReadOnlyTemporaryRowReference_ {
69 const Matrix<T>& fMatrix;
70 size_t fRow;
71 T operator[] (size_t column) const
72 {
73 return fMatrix.GetAt (fRow, column);
74 }
75 };
76
77 public:
78 /**
79 * EXAMPLE USAGE:
80 * Matrix<double> m (2,2);
81 * Assert (m[1][1] == 0);
82 */
83 nonvirtual const ReadOnlyTemporaryRowReference_ operator[] (size_t row) const;
84
85 public:
86 nonvirtual Characters::String ToString () const;
87
88 private:
89 class Rep_;
90
91 private:
92 Memory::SharedByValue<Rep_> fRep_;
93 };
94
95}
96
97/*
98 ********************************************************************************
99 ***************************** Implementation Details ***************************
100 ********************************************************************************
101 */
102#include "Matrix.inl"
103
104#endif /*_Stroika_Foundation_Math_LinearAlgebra_Matrix_h_*/
STRING_TYPE ToString(FLOAT_TYPE f, const ToStringOptions &options={})