initial push

This commit is contained in:
2026-06-23 09:35:43 +02:00
parent 683a33967d
commit b842990cd4
44 changed files with 4738 additions and 92 deletions
+67
View File
@@ -0,0 +1,67 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: io
* File Name: print_tensor.hpp
* Revision: 0.1.0
* Date: 21-06-2026
* Author: Michelle Bausager
*
* Description:
* Functions to print out tensors with std::cout << x std::endl;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//-----------------------------------------------------------------------------------------------------
#include <iostream> // for std::cout, std::endl
#include <tensor/vector.hpp> // for panic::tensor::vector
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic {
namespace io {
void print(const panic::tensor::vector& v){
std::cout << "[";
for (panic::uint_t i = 0; i < v.size()-1; ++i){
std::cout << v[i] << ", ";
}
std::cout << v[v.size()-1]<< "]" << std::endl;
}
} // namespace io
}// namespace panic
+80
View File
@@ -0,0 +1,80 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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
+80
View File
@@ -0,0 +1,80 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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
+80
View File
@@ -0,0 +1,80 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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
+117
View File
@@ -0,0 +1,117 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: <module-name>
* File Name: <file-name>
* Revision: 0.1.0
* Date: <yyyy-mm-dd>
* Author: Michelle Bausager
*
* Description:
* <short description of what this file/module does>
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// includes like:
// #include <stdint.h>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
// difinitions like:
// #define TEST_FALG 1
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
// Variable difinition like:
// static uint32_t AmountOfCool = 0;
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
// Function prototypes like:
// static void TestLeds(void);
// Function description like:
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul_serial
//
// Description:
// Performs serial matrix multiplication:
//
// out = a * b
//
// Inputs:
// a const panic::Matrix&
// Left-hand input matrix.
//
// b const panic::Matrix&
// Right-hand input matrix.
//
// Outputs:
// out panic::Matrix&
// Output matrix. Must be allocated before calling this function.
// The function writes the result into this matrix.
//
// Returns:
// panic::Status
// panic::Status::Ok Matrix multiplication completed successfully.
// panic::Status::SizeError Matrix dimensions are incompatible.
// panic::Status::NullError One or more internal data pointers are null.
//
// Notes:
// This function does not allocate memory.
// The output matrix must have dimensions
//--------------------------------------------------------------------------------------------------------------------------
// or
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::sqrt
//
// Description:
// Computes an approximation of the square root of a scalar value.
//
// Inputs:
// x panic::float_t
// Input value.
//
// Outputs:
// None.
//
// Returns:
// panic::float_t
// Approximate square root of x.
//
// Notes:
// This implementation is written from scratch and is intended to be readable
// and portable rather than maximally optimized.
//--------------------------------------------------------------------------------------------------------------------------
+297
View File
@@ -0,0 +1,297 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: vector.cpp
* Revision: 0.1.0
* Date: 21-06-2026
* Author: Michelle Bausager
*
* Description:
* Defines the vector object that will be used in the rest of the libraries.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <tensor/vector.hpp>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace tensor{
//--------------------------------------------------------------------------------------------------------------------------
// Constructor Name : panic::tensor::vector::vector
//
// Description:
// Creates an empty vector.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector() {
length = 0;
data = 0;
}
//--------------------------------------------------------------------------------------------------------------------------
// Constructor Name : panic::tensor::vector::vector
//
// Description:
// Creates a vector with size allocation and initializes all values to zero.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(panic::uint_t size){
length = size;
if (length == 0){
data = 0;
return;
}
data = new panic::real_t[length];
for (panic::uint_t i = 0; i < size; ++i){
data[i] = static_cast<panic::real_t>(0);
}
}
//--------------------------------------------------------------------------------------------------------------------------
// Constructor Name : panic::tensor::vector::vector
//
// Description:
// Creates a vector with size allocation and initializes all values.
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(panic::uint_t size, panic::real_t value){
length = size;
if (size == 0){
data = 0;
return;
}
data = new panic::real_t[size];
for (panic::uint_t i = 0; i < size; ++i){
data[i] = value;
}
}
//--------------------------------------------------------------------------------------------------------------------------
// Constructor Name : panic::tensor::vector::vector
//
// Description:
// Copy-contructor, makes a deep copy of another vector like this:
// vector a(3);
// vector b = a;
//--------------------------------------------------------------------------------------------------------------------------
vector::vector(const vector& other){
length = other.length;
if (length == 0){
data = 0;
return;
}
data = new panic::real_t[length];
for (panic::uint_t i = 0; i < length; ++i){
data[i] = other.data[i];
}
}
//--------------------------------------------------------------------------------------------------------------------------
// Deconstructor Name : panic::tensor::vector::~vector
//
// Description:
// Deletes the data and releases the memory.
//--------------------------------------------------------------------------------------------------------------------------
vector::~vector(){
delete[] data;
data = 0;
length = 0;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::operator=
//
// Description:
// Copy-assignment. Copies from another vector like this:
// vector a(5);
// vector b(3);
// b = a;
//--------------------------------------------------------------------------------------------------------------------------
vector& vector::operator=(const vector& other){
if (this == &other){
return *this;
}
panic::real_t* new_data = 0;
if (other.length > 0){
new_data = new panic::real_t[other.length];
for (panic::uint_t i = 0; i < other.length; ++i){
new_data[i] = other.data[i];
}
}
delete[] data;
data = new_data;
length = other.length;
return *this;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::resize
//
// Description:
// Returns the length/size of the vector
//--------------------------------------------------------------------------------------------------------------------------
panic::uint_t vector::size() const{
return length;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::resize
//
// Description:
// Resizes the vector to new length and keeps old values
//--------------------------------------------------------------------------------------------------------------------------
bool vector::resize(panic::uint_t new_size){
if (new_size == length){
return true;
}
if (new_size == 0){
data = 0;
length = 0;
return true;
}
panic::real_t* new_data = new panic::real_t[new_size];
panic::uint_t copy_size = length;
if (new_size < length){
copy_size = new_size;
}
for (panic::uint_t i = 0; i < copy_size; ++i){
new_data[i] = data[i];
}
for (panic::uint_t i = copy_size; i < new_size; ++i){
new_data[i] = static_cast<panic::real_t>(0);
}
delete[] data;
data = new_data;
length = new_size;
return true;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::fill
//
// Description:
// Fills te vector with a value
//--------------------------------------------------------------------------------------------------------------------------
bool vector::fill(panic::real_t value){
for (panic::uint_t i = 0; i < length; ++i){
data[i] = value;
}
return true;
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::operator[]
//
// Description:
// Lets you read and write v[index]
//--------------------------------------------------------------------------------------------------------------------------
panic::real_t& vector::operator[](panic::uint_t index){
return data[index];
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::operator[]
//
// Description:
// Lets you read v[index] from a const vector
//--------------------------------------------------------------------------------------------------------------------------
const panic::real_t& vector::operator[](panic::uint_t index) const{
return data[index];
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::at
//
// Description:
// Lets you read and write v.at(index) with index bounse
//--------------------------------------------------------------------------------------------------------------------------
panic::real_t& vector::at(panic::uint_t index){
if (index >= length){
return data[length-1];
}
return data[index];
}
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::tensor::vector::at
//
// Description:
// Lets you read v[index] from a const vector with index bounse
//--------------------------------------------------------------------------------------------------------------------------
const panic::real_t& vector::at(panic::uint_t index) const{
if (index >= length){
return data[length-1];
}
return data[index];
}
} // namespace tensor
} // namespace panic