First batch of rotgen implementation: constructors, basic infrastructure

This commit is contained in:
Karen Kaspar 2025-05-16 16:01:17 +02:00 committed by Joel Falcou
parent 2554a83890
commit afd504d679
9 changed files with 428 additions and 10 deletions

View file

@ -9,6 +9,7 @@
#include <memory>
#include <cstddef>
#include <initializer_list>
namespace rotgen
{
@ -16,10 +17,14 @@ namespace rotgen
{
public:
matrix_impl64(std::size_t rows = 0, std::size_t cols = 0);
matrix_impl64(std::size_t rows, std::size_t cols,std::initializer_list<double> init);
matrix_impl64(std::initializer_list<std::initializer_list<double>> init);
matrix_impl64(matrix_impl64 const& other);
matrix_impl64& operator=(matrix_impl64 const& other);
matrix_impl64(matrix_impl64&&) noexcept;
matrix_impl64& operator=(matrix_impl64 const& other);
matrix_impl64& operator=(matrix_impl64&&) noexcept;
~matrix_impl64();
@ -27,9 +32,16 @@ namespace rotgen
std::size_t rows() const;
std::size_t cols() const;
std::size_t size() const;
void resize(std::size_t new_rows, std::size_t new_cols);
void conservativeResize(std::size_t new_rows, std::size_t new_cols);
double& operator()(std::size_t i, std::size_t j);
double const& operator()(std::size_t i, std::size_t j) const;
double& operator()(std::size_t index);
double const& operator()(std::size_t index) const;
matrix_impl64& operator+=(matrix_impl64 const& rhs);
matrix_impl64& operator*=(matrix_impl64 const& rhs);
matrix_impl64& operator*=(double d);
@ -37,7 +49,9 @@ namespace rotgen
friend std::ostream& operator<<(std::ostream&,matrix_impl64 const&);
friend bool operator==(matrix_impl64 const& lhs, matrix_impl64 const& rhs);
private:
const double* data() const;
private:
struct payload;
std::unique_ptr<payload> storage_;
};

View file

@ -8,6 +8,8 @@
#pragma once
#include <rotgen/impl/matrix_impl64.hpp>
#include <initializer_list>
#include <cassert>
namespace rotgen
{
@ -20,7 +22,41 @@ namespace rotgen
public:
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
matrix(std::size_t r, std::size_t c) : parent(r,c) {}
matrix(int r, int c) : parent(r, c)
{
if constexpr(Rows != -1) assert(r == Rows && "Mismatched between dynamic and static row size");
if constexpr(Cols != -1) assert(c == Cols && "Mismatched between dynamic and static column size");
}
matrix(std::initializer_list<std::initializer_list<Scalar>> init) : parent(init)
{
if constexpr(Rows != -1) assert(init.size() == Rows && "Mismatched between dynamic and static row size");
if constexpr(Cols != -1)
{
std::size_t c = 0;
if(init.size()) c = init.begin()->size();
assert(c == Cols && "Mismatched between dynamic and static column size");
}
}
template<std::convertible_to<Scalar>... S>
matrix(Scalar s0,S... init)
requires((Rows == 1 && Cols == (1+sizeof...(S))) || (Cols == 1 && Rows == (1+sizeof...(S))))
: parent(Rows, Cols, {s0,static_cast<Scalar>(init)...})
{}
void resize(int new_rows, int new_cols)
requires(Rows == -1 && Cols == -1)
{
parent::resize(new_rows, new_cols);
}
void conservativeResize(int new_rows, int new_cols)
requires(Rows == -1 && Cols == -1)
{
parent::conservativeResize(new_rows, new_cols);
}
friend bool operator==(matrix const& lhs, matrix const& rhs)
{