40 template<
typename ElementType>
46 Matrix (
size_t numRows,
size_t numColumns)
47 : rows (numRows), columns (numColumns)
56 Matrix (
size_t numRows,
size_t numColumns,
const ElementType* dataPointer)
57 : rows (numRows), columns (numColumns)
60 memcpy (data.getRawDataPointer(), dataPointer, rows * columns * sizeof (ElementType));
104 void clear() noexcept { zeromem (data.begin(), (
size_t) data.size() * sizeof (ElementType)); }
115 inline ElementType
operator() (
size_t row,
size_t column)
const noexcept
117 jassert (row < rows && column < columns);
118 return data.getReference (
static_cast<int> (dataAcceleration.
getReference (
static_cast<int> (row))) +
static_cast<int> (column));
122 inline ElementType&
operator() (
size_t row,
size_t column) noexcept
124 jassert (row < rows && column < columns);
125 return data.getReference (
static_cast<int> (dataAcceleration.
getReference (
static_cast<int> (row))) +
static_cast<int> (column));
140 inline Matrix&
operator+= (
const Matrix& other) noexcept {
return apply (other, [] (ElementType a, ElementType b) {
return a + b; } ); }
143 inline Matrix&
operator-= (
const Matrix& other) noexcept {
return apply (other, [] (ElementType a, ElementType b) {
return a - b; } ); }
148 std::for_each (begin(), end(), [scalar] (ElementType& x) { x *= scalar; });
165 inline Matrix&
hadarmard (
const Matrix& other) noexcept {
return apply (other, [] (ElementType a, ElementType b) {
return a * b; } ); }
172 static bool compare (
const Matrix& a,
const Matrix& b, ElementType tolerance = 0) noexcept;
175 inline
bool operator== (const
Matrix& other) const noexcept {
return compare (*
this, other); }
179 bool isSquare() const noexcept {
return rows == columns; }
191 bool isNullMatrix() const noexcept {
return rows == 0 || columns == 0; }
210 ElementType* begin() noexcept {
return data.begin(); }
211 ElementType* end() noexcept {
return data.end(); }
213 const ElementType* begin() const noexcept {
return &data.getReference (0); }
214 const ElementType* end() const noexcept {
return begin() + data.size(); }
221 data.resize (
static_cast<int> (columns * rows));
222 dataAcceleration.
resize (
static_cast<int> (rows));
224 for (
size_t i = 0; i < rows; ++i)
225 dataAcceleration.
setUnchecked (
static_cast<int> (i), i * columns);
228 template <
typename BinaryOperation>
229 Matrix& apply (
const Matrix& other, BinaryOperation binaryOp)
231 jassert (rows == other.rows && columns == other.columns);
235 for (
auto src : other)
237 *dst = binaryOp (*dst, src);
245 Array<ElementType> data;
246 Array<size_t> dataAcceleration;
248 size_t rows, columns;
251 JUCE_LEAK_DETECTOR (
Matrix)
void setUnchecked(int indexToChange, ParameterType newValue)
ElementType & getReference(int index) noexcept
void resize(int targetNumItems)
Matrix operator-(const Matrix &other) const
Matrix & hadarmard(const Matrix &other) noexcept
Matrix & swapRows(size_t rowOne, size_t rowTwo) noexcept
Matrix & operator+=(const Matrix &other) noexcept
size_t getNumRows() const noexcept
Matrix(Matrix &&) noexcept=default
static Matrix hadarmard(const Matrix &a, const Matrix &b)
static bool compare(const Matrix &a, const Matrix &b, ElementType tolerance=0) noexcept
ElementType * getRawDataPointer() noexcept
Matrix(const Matrix &)=default
bool isOneColumnVector() const noexcept
bool isVector() const noexcept
bool isNullMatrix() const noexcept
Matrix & swapColumns(size_t columnOne, size_t columnTwo) noexcept
Matrix(size_t numRows, size_t numColumns)
static Matrix hankel(const Matrix &vector, size_t size, size_t offset=0)
Array< size_t > getSize() const noexcept
Matrix operator*(ElementType scalar) const
ElementType operator()(size_t row, size_t column) const noexcept
Matrix & operator-=(const Matrix &other) noexcept
Matrix operator+(const Matrix &other) const
static Matrix identity(size_t size)
bool solve(Matrix &b) const noexcept
static Matrix toeplitz(const Matrix &vector, size_t size)
Matrix(size_t numRows, size_t numColumns, const ElementType *dataPointer)
Matrix & operator*=(ElementType scalar) noexcept
size_t getNumColumns() const noexcept
bool isSquare() const noexcept
bool isOneRowVector() const noexcept
const ElementType * getRawDataPointer() const noexcept