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);
248 size_t rows, columns;
251 JUCE_LEAK_DETECTOR (
Matrix)
Matrix & swapRows(size_t rowOne, size_t rowTwo) noexcept
Matrix operator+(const Matrix &other) const
Matrix operator*(ElementType scalar) const
size_t getNumColumns() const noexcept
ElementType * end() noexcept
bool isOneColumnVector() const noexcept
static Matrix identity(size_t size)
Matrix & hadarmard(const Matrix &other) noexcept
Matrix & swapColumns(size_t columnOne, size_t columnTwo) noexcept
bool isOneRowVector() const noexcept
static Matrix hadarmard(const Matrix &a, const Matrix &b)
void resize(int targetNumItems)
static Matrix hankel(const Matrix &vector, size_t size, size_t offset=0)
Matrix(size_t numRows, size_t numColumns)
ElementType * begin() noexcept
size_t getNumRows() const noexcept
Matrix operator-(const Matrix &other) const
void setUnchecked(int indexToChange, ParameterType newValue)
ElementType * getRawDataPointer() noexcept
bool solve(Matrix &b) const noexcept
bool isSquare() const noexcept
Matrix & operator=(const Matrix &)=default
Array< size_t > getSize() const noexcept
int size() const noexcept
Matrix & operator+=(const Matrix &other) noexcept
ElementType * getRawDataPointer() noexcept
Matrix & operator*=(ElementType scalar) noexcept
ElementType & getReference(int index) noexcept
Matrix(size_t numRows, size_t numColumns, const ElementType *dataPointer)
static Matrix toeplitz(const Matrix &vector, size_t size)
const ElementType * getRawDataPointer() const noexcept
static bool compare(const Matrix &a, const Matrix &b, ElementType tolerance=0) noexcept
ElementType operator()(size_t row, size_t column) const noexcept
bool isNullMatrix() const noexcept
bool isVector() const noexcept
Matrix & operator-=(const Matrix &other) noexcept