/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * * 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 // panic::uint_t, panic::int_t, and panic::real_t namespace panic{ namespace tensor{ /** * @brief struct for vector object * * The struct is used for all PANIC libraries * It uses dynamic allocation with new[] nad delete[]. * Copying performs a deep copy. */ template struct vector{ // Variable to store the length of the data array panic::types::uint_t length; // Pointer to the data array T* data; /** * @brief Empthy constructor * */ vector(); /** * @brief Contructor with size allocation. * * @param size Number of elemets in the vector */ vector(panic::types::uint_t size); /** * @brief Contructor with size allocation and sets it all to a value. * * @param size Number of elemets in the vector * @param value all the values in the vactor. */ vector(panic::types::uint_t size, T value); /** * @brief Copy-contructor. * * Computes: * @code * vector a(3); * vector b = a; * @endcode * */ vector(const vector& other); /** * @brief De-contructor, releases memory. * * @note Releases memory. */ ~vector(); /** * @brief Copy-assignment. * * Computes: * @code * vector a(3); * vector b(5); * b = a; * @endcode * */ vector& operator=(const vector& other); /** * @brief Returns number of elements/size. * * Computes: * @code * m = a.size(); * @endcode * * @note The const tells compiler that the fuction don't edit the objert. */ panic::types::uint_t size() const; /** * @brief Function to resize data vactor. * * Computes: * @code * a.resize(6); * @endcode * * @note It hold all the privious functions if avaliable. */ bool resize(panic::types::uint_t new_size); /** * @brief Fill data with value. * * Computes: * @code * a.fill(3.1415); * @endcode * * @note Sets all values in the vactor. */ bool fill(T value); /** * @brief Read and write vactor data using index * * Computes: * @code * n = a[3]; * @endcode * * @note This is unchecked and fast. */ T& operator[](panic::types::uint_t index); /** * @brief Read from const vector data using index * * Computes: * @code * n = const a[3]; * @endcode * * @note This is unchecked and fast. */ const T& operator[](panic::types::uint_t index) const; /** * @brief Read and write vactor data using index * * Computes: * @code * n = a.at(3); * @endcode * * @note This is checked and not fast. */ T& at(panic::types::uint_t index); /** * @brief Read from const vector data using index * * Computes: * @code * n = const a.at(3); * @endcode * * @note This is checked and not fast. */ const T& at(panic::types::uint_t index) const; }; //--------------------------------------------------------------------------------------------------------------------------- // TYPE ALIASES //--------------------------------------------------------------------------------------------------------------------------- typedef vector real_vector; typedef vector int_vector; typedef vector uint_vector; //--------------------------------------------------------------------------------------------------------------------------- // EXPLICIT TEMPLATE DECLARATION //--------------------------------------------------------------------------------------------------------------------------- extern template struct vector; extern template struct vector; extern template struct vector; } // namespace tensor } // namespace panic