Files
2026-07-29 17:34:22 +02:00

100 lines
2.8 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: linspace.hpp
* Revision: 0.1.0
* Date: 29-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to generate linspace tensors
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp> // for panic::vector
#include <config/types.hpp>
namespace panic{
namespace tensor{
/**
* @brief Outputs a linear line in a vector
*
* Computes:
* @code
* c[i] = linspace(-5, 5, 10, true);
* @endcode
*
* @tparam T Numeric element type.
* @param start Start of the line.
* @param stop End of the line.
* @param num Number of points in the array.
* @param endpoint If the endpint should be the same as @p stop.
* @param c Output vector.
*
* @return true if @p c was resized and filled successfully.
* @return false if resizing @p c failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool linspace(const T start,
const T stop,
const panic::types::uint_t num,
panic::tensor::vector<T>& c,
const bool endpoint=true);
/**
* @brief Returns a vector with linear line.
*
* Computes:
* @code
* result[i] = linspace(-5, 5, 10, true);
* @endcode
*
* @param T Numeric element type.
* @param start Start of the line.
* @param stop End of the line.
* @param num Number of points in the array.
* @param endpoint If the endpint should be the same as @p stop.
*
* @return A new vector containing the result.
* @return An empty vector if the operation fails.
*
* @note This overload is convenient, but may allocate a new vector.
*/
template <typename T>
panic::tensor::vector<T> linspace(const T start,
const T stop,
const panic::types::uint_t num,
const bool endpoint=true);
} // namespace tensor
} // namespace panic