Files
panic/include/tensor/vector.hpp
T
Bausager a791201f3a Matrix
First matrix implementation with print_matrix in io
2026-06-23 20:28:11 +02:00

151 lines
5.4 KiB
C++

/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* 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.hpp
* Revision: 0.1.0
* Date: 23-06-2026
* Author: Michelle Bausager
*
* Description:
* Defines the vector 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::vector
//
// Description:
// Dynamic vector storing panic::real_t values.
// The vector owns its memory and releases it in the destructor.
//
// Member Variables:
// length panic::uint_t
// Number of elements in the vector.
//
// data panic::real_t*
// Pointer to the allocated vector data.
//
// Notes:
// This vector uses dynamic allocation with new[] and delete[].
// Copying performs a deep copy.
//---------------------------------------------------------------------------------------------------------------------------
namespace panic{
namespace tensor{
template <typename T>
struct vector{
panic::uint_t length;
T* data;
// empty contructor
vector();
// 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;
};
//---------------------------------------------------------------------------------------------------------------------------
// 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
//---------------------------------------------------------------------------------------------------------------------------
// VARIABLE DESCRIPTION
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPE
//---------------------------------------------------------------------------------------------------------------------------