From 3824f1abf382cc6b22b84aadb97e6e9fa564225f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 7 Feb 2019 17:52:29 +0100 Subject: Add initial implementation for mmmatrix and update to build.ninja --- build.ninja | 5 +++-- include/mm/mmmatrix.hpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ mmmatrix.cpp | 1 + 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 include/mm/mmmatrix.hpp create mode 100644 mmmatrix.cpp diff --git a/build.ninja b/build.ninja index 9f51a13..f5051b4 100644 --- a/build.ninja +++ b/build.ninja @@ -2,9 +2,10 @@ include ninja/rules.ninja # libmm build build/mmvec.o: cpp mmvec.cpp +build build/mmmatrix.o: cpp mmmatrix.cpp -build build/libmm.a: link-static build/mmvec.o -build build/libmm.so: link-shared build/mmvec.o +build build/libmm.a: link-static build/mmvec.o build/mmmatrix.o +build build/libmm.so: link-shared build/mmvec.o build/mmmatrix.o # examples build build/example.o: cpp example.cpp diff --git a/include/mm/mmmatrix.hpp b/include/mm/mmmatrix.hpp new file mode 100644 index 0000000..7934d87 --- /dev/null +++ b/include/mm/mmmatrix.hpp @@ -0,0 +1,59 @@ +/* mmmatrix.hpp + * Part of Mathematical library built (ab)using Modern C++ 17 abstractions. + * + * This library is not intended to be _performant_, it does not contain + * hand written SMID / SSE / AVX optimizations. It is instead an example + * of highly abstracted code, where matrices can contain any data type. + * + * As a challenge, the matrix data structure has been built on a container + * of static capacity. But if a dynamic base container is needed, the code + * should be easily modifiable to add further abstraction, by templating + * the container and possibly the allocator. + * + * Naoki Pross + * 2018 ~ 2019 + */ +#pragma once + +#include +#include + +namespace mm { + template + class basic_matrix; +} + +template +class mm::basic_matrix { +public: + using type = T; + + static constexpr std::size_t rows = Rows; + static constexpr std::size_t cols = Cols; + + basic_matrix() {} + + template + basic_matrix(const basic_matrix& other); + + const T& at(std::size_t row, std::size_t col); + +private: + std::array data; +}; + + + +template +template +mm::basic_matrix::basic_matrix(const basic_matrix& other) { + static_assert((ORows <= Rows), + "cannot copy a taller matrix into a smaller one" + ); + + static_assert((OCols <= Cols), + "cannot copy a larger matrix into a smaller one" + ); + + std::copy(std::begin(other.data), std::end(other.data), data.begin()); +} diff --git a/mmmatrix.cpp b/mmmatrix.cpp new file mode 100644 index 0000000..a352413 --- /dev/null +++ b/mmmatrix.cpp @@ -0,0 +1 @@ +#include "mmmatrix.hpp" -- cgit v1.2.1