First matrix implementation with print_matrix in io
This commit is contained in:
2026-06-23 20:28:11 +02:00
parent 77d2dad320
commit a791201f3a
34 changed files with 824 additions and 1907 deletions
+155
View File
@@ -0,0 +1,155 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* PANIC
* Portable Algorithms and Numerics In C++
*
* Scientific computing from scratch, with feeling.
*
* Copyright (c) 2026 Michelle Bausager
*
* This file is part of PANIC.
*
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
* You may redistribute and/or modify it under the terms of the GPL.
*
* PANIC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the LICENSE file for the full license text.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Project Name: PANIC
* Module Name: tensor
* File Name: matrix.hpp
* Revision: 0.1.0
* Date: 23-06-2026
* Author: Michelle Bausager
*
* Description:
* Defines the matrix object that will be used in the rest of the libraries.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::tensor::matrix
//
// Description:
// Dynamic matrix storing T values.
// The matrix owns its memory and releases it in the destructor.
//
// Member Variables:
// n panic::uint_t
// Number of rows in the matrix.
// m panic::uint_t
// Number of columns in the matrix.
//
// data T*
// Pointer to the allocated matrix data.
//
// Notes:
// This matrix uses dynamic allocation with new[] and delete[].
// Copying performs a deep copy.
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace tensor{
template <typename T>
struct matrix{
panic::uint_t n;
panic::uint_t m;
panic::uint_t length;
T* data;
// empty contructor
matrix();
// contructor with size allocation
matrix(panic::uint_t rows, panic::uint_t cols);
// contructor with size allocation and sets it all to a value
matrix(panic::uint_t rows, panic::uint_t cols, T value);
// copy-contructor
// matrix A(3,3);
// matrix B = A;
matrix(const matrix& other);
// de-contructor, releases memory
~matrix();
// copy-assignment
//matrix A(5);
//matrix B(3);
//B = A;
matrix& operator=(const matrix& other);
// function returns rows.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t rows() const;
// function returns columns.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t cols() const;
// function to resize data vector
bool resize(panic::uint_t new_n, panic::uint_t new_m);
// fill data with value
bool fill(T value);
// lets you read and write matrix data using row and column
// Example:
// A(1, 2)
// This is unchecked and fast.
T& operator()(panic::uint_t index_n, panic::uint_t index_m);
// lets you read matrix data using row and column from a const matrix
const T& operator()(panic::uint_t index_n, panic::uint_t index_m) const;
};
//---------------------------------------------------------------------------------------------------------------------------
// TYPE ALIASES
//---------------------------------------------------------------------------------------------------------------------------
typedef matrix<panic::real_t> real_matrix;
typedef matrix<panic::int_t> int_matrix;
typedef matrix<panic::uint_t> uint_matrix;
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION
//---------------------------------------------------------------------------------------------------------------------------
extern template struct matrix<panic::real_t>;
extern template struct matrix<panic::int_t>;
extern template struct matrix<panic::uint_t>;
} // namespace tensor
} // namespace panic
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
View File
+1 -1
View File
@@ -24,7 +24,7 @@
* Module Name: tensor
* File Name: vector.hpp
* Revision: 0.1.0
* Date: 21-06-2026
* Date: 23-06-2026
* Author: Michelle Bausager
*
* Description: