Skip to content

Instantly share code, notes, and snippets.

@facontidavide
Last active February 28, 2018 15:16
Show Gist options
  • Save facontidavide/75267468b8a0327efd028fcb2a559297 to your computer and use it in GitHub Desktop.
Save facontidavide/75267468b8a0327efd028fcb2a559297 to your computer and use it in GitHub Desktop.
Used for a programming exercise...
#pragma once
template <typename T>
class Vector
{
public:
Vector(size_t order); // constructor for squared-matrix
Vector(const Vector& other); // copy constructor
~Vector(); //destructor
Vector& operator=(const Vector& other); // copy operator
size_t size() const;
//mutable reference to matrux element
T& operator()(size_t index);
//unmutable reference to matrux element
const T& operator()(size_t index) const;
};
// some methods might throw exception
template <typename T>
class Matrix // Note: store data in a single dynamic allocated vector, column-wise
{
public:
Matrix(size_t order); // constructor for squared-matrix
Matrix(size_t rows, size_t columns); // constructor for rectangular matrix
Matrix(const Matrix& other); // copy constructor
~Matrix(); //destructor
Matrix& operator=(const Matrix& other); // copy operator
size_t numRows() const;
size_t numCols() const;
Matrix getTranspose() const;
Matrix getInverted() const;
Matrix getMinor() const;
Vector<T> getRow(size_t row_index);
Vector<T> getColumn(size_t column_index);
T calculateDeterminant() const;
//mutable reference to matrux element
T& operator()(size_t row, size_t col);
//unmutable reference to matrux element
const T& operator()(size_t row, size_t col) const;
// calculate multiplication R = (*this) * other
Matrix operator* (const Matrix& other) const;
// matrix vector multiplication
Vector<T> operator* (const Vector<T>& other) const;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment