Files
panic/include/tensor/generators/one_hot.hpp
T

91 lines
2.5 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: one_hot.hpp
* Revision: 0.1.0
* Date: 31-07-2026
* Author: Michelle Bausager
*
* Description:
* Functions to one_hot matrices
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma once
#include <tensor/vector.hpp>
#include <tensor/matrix.hpp> // for panic::vector
#include <config/types.hpp>
namespace panic{
namespace tensor{
/**
* @brief Outputs an one_hot matrix
*
* Computes:
* @code
* @endcode
*
* @tparam T Numeric element type.
* @param size Number of columns.
* @param a Input vector that contains here 1 should be
* @param B Output matrix
*
* @return true if @p B was resized and filled successfully.
* @return false if resizing @p B failed.
*
* @note This overload writes the result into an existing vector to avoid
* unnecessary temporary allocations.
*/
template <typename T>
bool one_hot(const panic::types::uint_t size, const panic::tensor::uint_vector& a, panic::tensor::matrix<T>& B);
/**
* @brief Returns a one_hot matrix
*
* Computes:
* @code
* @endcode
*
* @param T Numeric element type.
* @param size Number of columns.
* @param a Input vector that contains here 1 should be
*
* @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::matrix<T> one_hot(const panic::types::uint_t size, const panic::tensor::vector<T>& a);
} // namespace tensor
} // namespace panic