Dense Layer, Add

added the dense layer with a forward functions. I also made the add functions for most cases.
This commit is contained in:
2026-06-25 19:43:07 +02:00
parent 9b20278395
commit 189d605bfa
27 changed files with 1657 additions and 902 deletions
+9 -9
View File
@@ -52,40 +52,40 @@
namespace panic {
namespace constants{
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::pi
// Type Name : panic::constants::pi
//
// Description:
// Default difinition of pi (3.14159265358979323846) used inside PANIC.
// static_cast makes sure the right number of decimals are used when defining the constant.
//
// Underlying Type:
// panic::real_t
// panic::types::real_t
//---------------------------------------------------------------------------------------------------------------------------
static const panic::real_t pi = static_cast<panic::real_t>(3.14159265358979323846);
static const panic::types::real_t pi = static_cast<panic::types::real_t>(3.14159265358979323846);
//---------------------------------------------------------------------------------------------------------------------------
//
// Type Name : panic::tau
// Type Name : panic::constants::tau
//
// Description:
// Default difinition of tau (6.28318530717958647692) used inside PANIC.
// static_cast makes sure the right number of decimals are used when defining the constant.
//
// Underlying Type:
// panic::real_t
// panic::types::real_t
//---------------------------------------------------------------------------------------------------------------------------
static const panic::real_t tau = static_cast<panic::real_t>(6.28318530717958647692);
static const panic::types::real_t tau = static_cast<panic::types::real_t>(6.28318530717958647692);
//---------------------------------------------------------------------------------------------------------------------------
//
// Type Name : panic::e
// Type Name : panic::constants::e
//
// Description:
// Default difinition of eulers number, e (2.71828182845904523536) used inside PANIC.
// static_cast makes sure the right number of decimals are used when defining the constant.
//
// Underlying Type:
// panic::real_t
// panic::types::real_t
//---------------------------------------------------------------------------------------------------------------------------
static const panic::real_t e = static_cast<panic::real_t>(2.71828182845904523536);
static const panic::types::real_t e = static_cast<panic::types::real_t>(2.71828182845904523536);
} // namespace constants
} // namespace panic
+5 -4
View File
@@ -45,7 +45,7 @@
//---------------------------------------------------------------------------------------------------------------------------
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::uint_t
// Type Name : panic::types::uint_t
//
// Description:
// Default unsigned integer type used inside PANIC.
@@ -54,7 +54,7 @@
// uint32_t
//---------------------------------------------------------------------------------------------------------------------------
//
// Type Name : panic::int_t
// Type Name : panic::types::int_t
//
// Description:
// Default signed integer type used inside PANIC.
@@ -63,7 +63,7 @@
// int32_t
//---------------------------------------------------------------------------------------------------------------------------
//
// Type Name : panic::real_t
// Type Name : panic::types::real_t
//
// Description:
// Default floating-point type used inside PANIC.
@@ -73,11 +73,12 @@
//---------------------------------------------------------------------------------------------------------------------------
namespace panic {
namespace types{
typedef uint32_t uint_t;
typedef int32_t int_t;
typedef float real_t;
} // namespace types
} // namespace panic
+364
View File
@@ -0,0 +1,364 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: add.hpp
* Revision: 0.1.0
* Date: 25-06-2026
* Author: Michelle Bausager
*
* Description:
* Functions to add panic::tensor togther;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma one
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <tensor/vector.hpp> // for panic::real_vector (uint_vector, int_vector)
#include <tensor/matrix.hpp> // for panic::real_matrix (uint_matrix, int_matrix)
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace math{
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds a scaler to a panic::tensor::vector
// c(2) = a(2) + k
//
// Inputs:
//
// a const panic::tensor::vector<T>&
//
// k const <T>
//
// Outputs:
// c panic::tensor::vector<T>&
//
// Returns:
// bool
//
// Notes:
// The c vector is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add(const panic::tensor::vector<T>& a, const T k, panic::tensor::vector<T>& c);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds a scaler to a panic::tensor::vector
// c(2) = a(2) + k
//
// Inputs:
//
// a const panic::tensor::vector<T>&
//
// k const <T>
//
// Outputs:
// None.
//
// Returns:
// c panic::tensor::vector<T>
//
// Notes:
// Makes new vector and returns the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const T k);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds two panic::tensor::vector
// c(2) = a(2) + b(2)
//
// Inputs:
//
// a const panic::tensor::vector<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// c panic::tensor::vector<T>&
//
// Returns:
// bool
//
// Notes:
// If input vector dimentions are not correct, output is a empty vector and returns false.
// The c vector is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b, panic::tensor::vector<T>& c);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds two panic::tensor::vector
// c(2) = a(2) + b(2)
//
// Inputs:
//
// a const panic::tensor::vector<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// None.
//
// Returns:
// c panic::tensor::vector<T>
//
// Notes:
// If input vector dimentions are not correct, return is an empty vector.
// Makes new vector and returns the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::vector<T> add(const panic::tensor::vector<T>& a, const panic::tensor::vector<T>& b);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds a scaler to a panic::tensor::matrix
// C(2,2) = A(2,2) + k
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// k const T
//
// Outputs:
// C panic::tensor::matrix<T>&
//
// Returns:
// bool
//
// Notes:
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add(const panic::tensor::matrix<T>& A, const T k, panic::tensor::matrix<T>& C);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds a scaler to a panic::tensor::matrix
// C(2,2) = A(2,2) + k
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// k const T
//
// Outputs:
// None.
//
// Returns:
// C panic::tensor::matrix<T>
//
// Notes:
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const T k);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds two panic::tensor::matrix
// C(2,2) = A(2,2) + B(2,2)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// B const panic::tensor::matrix<T>&
//
// Outputs:
// C panic::tensor::matrix<T>&
//
// Returns:
// bool
//
// Notes:
// If input matrix dimentions are not correct, outputs an a empty matrix and returns false.
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add
//
// Description:
// Adds two panic::tensor::matrix
// C(2,2) = A(2,2) + B(2,2)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// B const panic::tensor::matrix<T>&
//
// Outputs:
// None.
//
// Returns:
// C panic::tensor::matrix<T>
//
// Notes:
// If input matrix dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> add(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add_rowwise
//
// Description:
// Adds two panic::tensor::matrix
// C(2,3) = A(2,3) + b(2)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// C panic::tensor::matrix&
//
// Returns:
// bool
//
// Notes:
// If input vector dimentions are not correct, outputs an a empty matrix and returns false.
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add_rowwise
//
// Description:
// Adds two panic::tensor::matrix
// C(2,3) = A(2,3) + b(2)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// None.
//
// Returns:
// C panic::tensor::matrix<T>&
//
// Notes:
// If input vector dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> add_rowwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add_colwise
//
// Description:
// Adds two panic::tensor::matrix
// C(2,3) = A(2,3) + b(3)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// C panic::tensor::matrix&
//
// Returns:
// bool
//
// Notes:
// If input vector dimentions are not correct, outputs an a empty matrix and returns false.
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b, panic::tensor::matrix<T>& C);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::add_colwise
//
// Description:
// Adds two panic::tensor::matrix
// C(2,3) = A(2,3) + b(3)
//
// Inputs:
//
// A const panic::tensor::matrix<T>&
//
// b const panic::tensor::vector<T>&
//
// Outputs:
// None.
//
// Returns:
// C panic::tensor::matrix<T>&
//
// Notes:
// If input vector dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> add_colwise(const panic::tensor::matrix<T>& A, const panic::tensor::vector<T>& b);
} // namespace math
} // namespace panic
+107
View File
@@ -0,0 +1,107 @@
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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: matmul.hpp
* Revision: 0.1.0
* Date: 24-06-2026
* Author: Michelle Bausager
*
* Description:
* Functions to print out tensors with std::cout << x std::endl;
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma one
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//-----------------------------------------------------------------------------------------------------
#include <tensor/matrix.hpp> // for panic::real_matrix
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace math{
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul
//
// Description:
// Multiplies to panic::tensor::real_matrix
// C(2,4) = A(2,3) * B(3,4)
//
// Inputs:
//
// A const panic::tensor::real_matrix&
//
// B const panic::tensor::real_matrix&
//
// Outputs:
// C panic::tensor::real_matrix&
//
// Returns:
// bool
//
// Notes:
// If input matrix dimentions are not correct, output is a empty matrix and returns false.
// The C matrix is resized if nessessary.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
bool matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B, panic::tensor::matrix<T>& C);
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::math::matmul
//
// Description:
// Multiplies to panic::tensor::real_matrix
// C(2,4) = A(2,3) * B(3,4)
//
// Inputs:
//
// A const panic::tensor::real_matrix&
//
// B const panic::tensor::real_matrix&
//
// Outputs:
// None.
//
// Returns:
// C panic::tensor::real_matrix&
//
// Notes:
// If input matrix dimentions are not correct, returns an a empty matrix.
// Creates new matrix, C, for the result.
//--------------------------------------------------------------------------------------------------------------------------
template <typename T>
panic::tensor::matrix<T> matmul(const panic::tensor::matrix<T>& A, const panic::tensor::matrix<T>& B);
} // namespace math
} // namespace panic
+16 -75
View File
@@ -22,13 +22,13 @@
*
* Project Name: PANIC
* Module Name: neural_network
* File Name: layer_dense.hpp
* File Name: layer.hpp
* Revision: 0.1.0
* Date: 23-06-2026
* Author: Michelle Bausager
*
* Description:
* Defines the dense layers used in neural network
* Defines the base layers struct used in pther layers in neural network
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
@@ -36,6 +36,7 @@
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <tensor/matrix.hpp> // panic::tensor::real_matrix (uint_matrix, int_matrix)
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
@@ -46,94 +47,34 @@
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::neural_network::layer_dense
// Type Name : panic::neural_network::layer
//
// Description:
// A dense layer to use in neural networks
// A base layer to use in neural networks
//
// Member Variables:
// length panic::uint_t
// Number of elements in the vector.
//
// data panic::real_t*
// Pointer to the allocated vector data.
// None.
//
// Notes:
// This vector uses dynamic allocation with new[] and delete[].
// Copying performs a deep copy.
// This base layer should be used in all layers/activations that have a forward and backward function
// This is done so it's easy to make a list of layers in the model to loop over.
// The virtual means it should use derived object's version when called with a pointer.
// The =0 means the derviced object NEEDS to have these functions to work.
//
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace tensor{
namespace neural_network{
template <typename T>
struct vector{
panic::uint_t length;
T* data;
struct layer{
// empty contructor
vector();
virtual ~layer() = default;
// contructor with size allocation
vector(panic::uint_t size);
// contructor with size allocation and sets it all to a value
vector(panic::uint_t size, T value);
// copy-contructor
// vector a(3);
// vector b = a;
vector(const vector& other);
// de-contructor, releases memory
~vector();
// copy-assignment
//vector a(5);
//vector b(3);
//b = a;
vector& operator=(const vector& other);
// function returns size.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t size() const;
// function to resize data vector (I need a new that don't save the vlaues)
bool resize(panic::uint_t new_size);
// fill data with value
bool fill(T value);
// lets you read and write v[index]
T& operator[](panic::uint_t index);
// lets you read v[index] from a const vector
const T& operator[](panic::uint_t index) const;
// lets you read and write v.at(index)
T& at(panic::uint_t index);
// lets you read v.at(index) from a const vector
const T& at(panic::uint_t index) const;
virtual bool forward(const panic::tensor::real_matrix& inputs) = 0;
virtual bool backward(const panic::tensor::real_matrix& dinputs) = 0;
};
//---------------------------------------------------------------------------------------------------------------------------
// TYPE ALIASES
//---------------------------------------------------------------------------------------------------------------------------
typedef vector<panic::real_t> real_vector;
typedef vector<panic::int_t> int_vector;
typedef vector<panic::uint_t> uint_vector;
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION
//---------------------------------------------------------------------------------------------------------------------------
extern template struct vector<panic::real_t>;
extern template struct vector<panic::int_t>;
extern template struct vector<panic::uint_t>;
} // namespace tensor
} // namespace panic
+36 -74
View File
@@ -32,10 +32,14 @@
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
//---------------------------------------------------------------------------------------------------------------------------
// INCLUDE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
#include <neural_network/layer/layer.hpp> // for base layer struct
#include <tensor/vector.hpp>
#include <tensor/matrix.hpp>
//---------------------------------------------------------------------------------------------------------------------------
// DEFINE DESCRIPTION
@@ -45,96 +49,54 @@
// TYPE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// Type Name : panic::neural_network::layer_dense
//--------------------------------------------------------------------------------------------------------------------------
// Function Name : panic::neural_network::layer_dense
//
// Description:
// A dense layer to use in neural networks
// Dense/fully-connected neural network layer.
//
// Member Variables:
// length panic::uint_t
// Number of elements in the vector.
// Inputs:
// Samples x input size const panic::tensor::real_matrix&
//
// data panic::real_t*
// Pointer to the allocated vector data.
// Weight shape:
// input_size x neuron_count
//
// Bias shape:
// 1 x neuron_count
//
// Output shape:
// samples x neuron_count panic::tensor::real_matrix
//
// Notes:
// This vector uses dynamic allocation with new[] and delete[].
// Copying performs a deep copy.
//---------------------------------------------------------------------------------------------------------------------------
// forward(input) calculates:
//
// outputs = inputs * weights + biases
//--------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace tensor{
namespace neural_network{
template <typename T>
struct vector{
panic::uint_t length;
T* data;
struct layer_dense : public layer{
// empty contructor
vector();
panic::tensor::real_matrix weights;
panic::tensor::real_vector biases;
panic::tensor::real_matrix outputs;
// contructor with size allocation
vector(panic::uint_t size);
// Empthy contructor
layer_dense();
// contructor with size allocation and sets it all to a value
vector(panic::uint_t size, T value);
// Contructor with layer size
layer_dense(panic::types::uint_t input_size, panic::types::uint_t neurons);
// copy-contructor
// vector a(3);
// vector b = a;
vector(const vector& other);
// Decontructor (All internal variables has decontructors, so we can just use default)
~layer_dense() = default;
// de-contructor, releases memory
~vector();
// copy-assignment
//vector a(5);
//vector b(3);
//b = a;
vector& operator=(const vector& other);
// function returns size.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t size() const;
// function to resize data vector (I need a new that don't save the vlaues)
bool resize(panic::uint_t new_size);
// fill data with value
bool fill(T value);
// lets you read and write v[index]
T& operator[](panic::uint_t index);
// lets you read v[index] from a const vector
const T& operator[](panic::uint_t index) const;
// lets you read and write v.at(index)
T& at(panic::uint_t index);
// lets you read v.at(index) from a const vector
const T& at(panic::uint_t index) const;
// Forward function for forward pass
bool forward(const panic::tensor::real_matrix& inputs);
// Backward pass
bool backward(const panic::tensor::real_matrix& dinpus);
};
//---------------------------------------------------------------------------------------------------------------------------
// TYPE ALIASES
//---------------------------------------------------------------------------------------------------------------------------
typedef vector<panic::real_t> real_vector;
typedef vector<panic::int_t> int_vector;
typedef vector<panic::uint_t> uint_vector;
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION
//---------------------------------------------------------------------------------------------------------------------------
extern template struct vector<panic::real_t>;
extern template struct vector<panic::int_t>;
extern template struct vector<panic::uint_t>;
} // namespace tensor
} // namespace panic
+16 -16
View File
@@ -70,19 +70,19 @@ namespace panic{
template <typename T>
struct matrix{
panic::uint_t n;
panic::uint_t m;
panic::uint_t length;
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::uint_t rows, panic::uint_t cols);
matrix(panic::types::uint_t rows, panic::types::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);
matrix(panic::types::uint_t rows, panic::types::uint_t cols, T value);
// copy-contructor
// matrix A(3,3);
@@ -100,14 +100,14 @@ struct matrix{
// function returns rows.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t rows() const;
panic::types::uint_t rows() const;
// function returns columns.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t cols() const;
panic::types::uint_t cols() const;
// function to resize data vector
bool resize(panic::uint_t new_n, panic::uint_t new_m);
bool resize(panic::types::uint_t new_n, panic::types::uint_t new_m);
// fill data with value
bool fill(T value);
@@ -116,10 +116,10 @@ struct matrix{
// Example:
// A(1, 2)
// This is unchecked and fast.
T& operator()(panic::uint_t index_n, panic::uint_t index_m);
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::uint_t index_n, panic::uint_t index_m) const;
const T& operator()(panic::types::uint_t index_n, panic::types::uint_t index_m) const;
};
@@ -128,17 +128,17 @@ struct matrix{
// TYPE ALIASES
//---------------------------------------------------------------------------------------------------------------------------
typedef matrix<panic::real_t> real_matrix;
typedef matrix<panic::int_t> int_matrix;
typedef matrix<panic::uint_t> uint_matrix;
typedef matrix<panic::types::real_t> real_matrix;
typedef matrix<panic::types::int_t> int_matrix;
typedef matrix<panic::types::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>;
extern template struct matrix<panic::types::real_t>;
extern template struct matrix<panic::types::int_t>;
extern template struct matrix<panic::types::uint_t>;
} // namespace tensor
+15 -15
View File
@@ -68,17 +68,17 @@ namespace panic{
template <typename T>
struct vector{
panic::uint_t length;
panic::types::uint_t length;
T* data;
// empty contructor
vector();
// contructor with size allocation
vector(panic::uint_t size);
vector(panic::types::uint_t size);
// contructor with size allocation and sets it all to a value
vector(panic::uint_t size, T value);
vector(panic::types::uint_t size, T value);
// copy-contructor
// vector a(3);
@@ -96,25 +96,25 @@ struct vector{
// function returns size.
// const tells compiler that the fuction don't edit the objert.
panic::uint_t size() const;
panic::types::uint_t size() const;
// function to resize data vector (I need a new that don't save the vlaues)
bool resize(panic::uint_t new_size);
bool resize(panic::types::uint_t new_size);
// fill data with value
bool fill(T value);
// lets you read and write v[index]
T& operator[](panic::uint_t index);
T& operator[](panic::types::uint_t index);
// lets you read v[index] from a const vector
const T& operator[](panic::uint_t index) const;
const T& operator[](panic::types::uint_t index) const;
// lets you read and write v.at(index)
T& at(panic::uint_t index);
T& at(panic::types::uint_t index);
// lets you read v.at(index) from a const vector
const T& at(panic::uint_t index) const;
const T& at(panic::types::uint_t index) const;
};
@@ -123,17 +123,17 @@ struct vector{
// TYPE ALIASES
//---------------------------------------------------------------------------------------------------------------------------
typedef vector<panic::real_t> real_vector;
typedef vector<panic::int_t> int_vector;
typedef vector<panic::uint_t> uint_vector;
typedef vector<panic::types::real_t> real_vector;
typedef vector<panic::types::int_t> int_vector;
typedef vector<panic::types::uint_t> uint_vector;
//---------------------------------------------------------------------------------------------------------------------------
// EXPLICIT TEMPLATE DECLARATION
//---------------------------------------------------------------------------------------------------------------------------
extern template struct vector<panic::real_t>;
extern template struct vector<panic::int_t>;
extern template struct vector<panic::uint_t>;
extern template struct vector<panic::types::real_t>;
extern template struct vector<panic::types::int_t>;
extern template struct vector<panic::types::uint_t>;
} // namespace tensor