Matrix
First matrix implementation with print_matrix in io
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
// VARIABLE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
namespace panic {
|
||||
|
||||
namespace constants{
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Type Name : panic::pi
|
||||
//
|
||||
@@ -87,6 +87,7 @@ namespace panic {
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
static const panic::real_t e = static_cast<panic::real_t>(2.71828182845904523536);
|
||||
|
||||
} // namespace constants
|
||||
} // namespace panic
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Module Name: config
|
||||
* File Name: omp.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 20-06-2026
|
||||
* Date: 23-06-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
@@ -68,6 +68,14 @@
|
||||
#define PANIC_OMP_NUM_THREADS 0
|
||||
#endif
|
||||
|
||||
// If CMake did not define PANIC_OMP_ALLOW_NESTED, define it as 0.
|
||||
//
|
||||
// Meaning:
|
||||
// Not allow any nested parallel operations.
|
||||
#ifndef PANIC_OMP_ALLOW_NESTED
|
||||
#define PANIC_OMP_ALLOW_NESTED 0
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// OPENMP AVAILABILITY CHECK
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -181,8 +189,3 @@
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// None.
|
||||
|
||||
//PANIC_OMP_PARALLEL_FOR
|
||||
//for (panic::uint_t i = 0; i < length; ++i) {
|
||||
// data[i] = value;
|
||||
//}
|
||||
@@ -23,8 +23,8 @@
|
||||
* Project Name: PANIC
|
||||
* Module Name: io
|
||||
* File Name: print_tensor.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 21-06-2026
|
||||
* Revision: 0.1.1
|
||||
* Date: 23-06-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
@@ -51,7 +51,7 @@ namespace panic{
|
||||
namespace io{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Function Name : panic::io::print
|
||||
// Function Name : panic::io::print_vector
|
||||
//
|
||||
// Description:
|
||||
// Prints a vector out in the terminal
|
||||
@@ -71,11 +71,34 @@ namespace io{
|
||||
// Notes:
|
||||
// The vector is printed out in square brackets.
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void print(const panic::tensor::uint_vector& v);
|
||||
void print(const panic::tensor::int_vector& v);
|
||||
void print(const panic::tensor::real_vector& v);
|
||||
|
||||
void print_vector(const panic::tensor::uint_vector& v);
|
||||
void print_vector(const panic::tensor::int_vector& v);
|
||||
void print_vector(const panic::tensor::real_vector& v);
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Function Name : panic::io::print_matrix
|
||||
//
|
||||
// Description:
|
||||
// Prints a matrix out in the terminal
|
||||
//
|
||||
// Inputs:
|
||||
// v const panic::tensor::uint_matrix&
|
||||
// const panic::tensor::int_matrix&
|
||||
// const panic::tensor::real_matrix&
|
||||
// matrix to print
|
||||
//
|
||||
// Outputs:
|
||||
// None.
|
||||
//
|
||||
// Returns:
|
||||
// void
|
||||
//
|
||||
// Notes:
|
||||
// The matrix is printed out in square brackets.
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void print_matrix(const panic::tensor::uint_matrix& v);
|
||||
void print_matrix(const panic::tensor::int_matrix& v);
|
||||
void print_matrix(const panic::tensor::real_matrix& v);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: math
|
||||
* File Name: sqrt_serial.c
|
||||
* Revision: 0.1.0
|
||||
* Date: <yyyy-mm-dd>
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* <short description of what this file/module does>
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#ifndef __SQRT_SERIAL_H_
|
||||
#define __SQRT_SERIAL_H_
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INCLUDE FILE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// includes like:
|
||||
// #include <stdint.h>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// DEFINE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// difinitions like:
|
||||
// #define TEST_FALG 1
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// ENUM DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// LIKE
|
||||
//typedef enum
|
||||
//{
|
||||
// eConfDac0 = 0x00,
|
||||
// eConfDac1 = 0x01,
|
||||
// eConfDac2 = 0x02
|
||||
//} enDebugBoardDacType_t;
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// VARIABLE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Variable difinition like:
|
||||
// static uint32_t AmountOfCool = 0;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// FUNCTION PROTOTYPE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Function prototypes like:
|
||||
T sqrt(T c);
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// End of module
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: math
|
||||
* File Name: sqrt_serial.c
|
||||
* Revision: 0.1.0
|
||||
* Date: <yyyy-mm-dd>
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* <short description of what this file/module does>
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#ifndef __SQRT_SERIAL_H_
|
||||
#define __SQRT_SERIAL_H_
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INCLUDE FILE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// includes like:
|
||||
// #include <stdint.h>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// DEFINE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// difinitions like:
|
||||
// #define TEST_FALG 1
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// ENUM DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// LIKE
|
||||
//typedef enum
|
||||
//{
|
||||
// eConfDac0 = 0x00,
|
||||
// eConfDac1 = 0x01,
|
||||
// eConfDac2 = 0x02
|
||||
//} enDebugBoardDacType_t;
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// VARIABLE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Variable difinition like:
|
||||
// static uint32_t AmountOfCool = 0;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// FUNCTION PROTOTYPE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Function prototypes like:
|
||||
T sqrt(T c);
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// End of module
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* 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: math
|
||||
* File Name: sqrt_serial.c
|
||||
* Revision: 0.1.0
|
||||
* Date: <yyyy-mm-dd>
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* <short description of what this file/module does>
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#ifndef __SQRT_SERIAL_H_
|
||||
#define __SQRT_SERIAL_H_
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INCLUDE FILE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// includes like:
|
||||
// #include <stdint.h>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// DEFINE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// difinitions like:
|
||||
// #define TEST_FALG 1
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// ENUM DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// LIKE
|
||||
//typedef enum
|
||||
//{
|
||||
// eConfDac0 = 0x00,
|
||||
// eConfDac1 = 0x01,
|
||||
// eConfDac2 = 0x02
|
||||
//} enDebugBoardDacType_t;
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// VARIABLE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Variable difinition like:
|
||||
// static uint32_t AmountOfCool = 0;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// FUNCTION PROTOTYPE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// Function prototypes like:
|
||||
T sqrt(T c);
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// End of module
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user