/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * 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 // 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 struct matrix{ panic::types::uint_t n; panic::types::uint_t m; panic::types::uint_t length; T* data; // empty contructor matrix(); // contructor with size allocation matrix(panic::types::uint_t rows, panic::types::uint_t cols); // contructor with size allocation and sets it all to a value matrix(panic::types::uint_t rows, panic::types::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::types::uint_t rows() const; // function returns columns. // const tells compiler that the fuction don't edit the objert. panic::types::uint_t cols() const; // function to resize data vector bool resize(panic::types::uint_t new_n, panic::types::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::types::uint_t index_n, panic::types::uint_t index_m); // lets you read matrix data using row and column from a const matrix const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const; }; //--------------------------------------------------------------------------------------------------------------------------- // TYPE ALIASES //--------------------------------------------------------------------------------------------------------------------------- typedef matrix real_matrix; typedef matrix int_matrix; typedef matrix uint_matrix; //--------------------------------------------------------------------------------------------------------------------------- // EXPLICIT TEMPLATE DECLARATION //--------------------------------------------------------------------------------------------------------------------------- extern template struct matrix; extern template struct matrix; extern template struct matrix; } // namespace tensor } // namespace panic //--------------------------------------------------------------------------------------------------------------------------- // VARIABLE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- // FUNCTION PROTOTYPE //---------------------------------------------------------------------------------------------------------------------------