I made seed and uniform functions, but they are not omp friendly. They are runnning omp themself, but is not safe for threading/parallizing. Uniform is aproximated and is NOT validaded up against a real uniform distribution.
143 lines
5.4 KiB
C++
143 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: io
|
|
* File Name: print_tensor.cpp
|
|
* Revision: 0.1.0
|
|
* Date: 21-06-2026
|
|
* Author: Michelle Bausager
|
|
*
|
|
* Description:
|
|
* Functions to print out tensors with std::cout << x std::endl;
|
|
*
|
|
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// INCLUDE DESCRIPTION
|
|
//-----------------------------------------------------------------------------------------------------
|
|
#include <io/print_tensor.hpp>
|
|
#include <iostream> // for std::cout, std::endl
|
|
|
|
#include <tensor/vector.hpp> // for panic::vector
|
|
#include <tensor/matrix.hpp> // for panic::matrix
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// DEFINE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// VARIABLE DESCRIPTION
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
// FUNCTION PROTOTYPE
|
|
//---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace panic {
|
|
namespace io {
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
// Function Name : panic::io::print_vector
|
|
//
|
|
// Description:
|
|
// The vector is printed out in square brackets.
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
template <typename T>
|
|
bool print_vector(const panic::tensor::vector<T>& v){
|
|
std::cout << "[";
|
|
for (panic::types::uint_t i = 0; i < v.size()-1; ++i){
|
|
std::cout << v[i] << ", ";
|
|
}
|
|
std::cout << v[v.size()-1]<< "]" << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
// EXPLICIT TEMPLATE INSTANTIATION
|
|
//
|
|
// The implementation is in this .cpp file.
|
|
// Build the overload for the official PANIC numeric types.
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
template bool print_vector<panic::types::uint_t>(const panic::tensor::vector<panic::types::uint_t>& v
|
|
);
|
|
template bool print_vector<panic::types::int_t>(const panic::tensor::vector<panic::types::int_t>& v
|
|
);
|
|
template bool print_vector<panic::types::real_t>(const panic::tensor::vector<panic::types::real_t>& v
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
// Function Name : panic::io::print_matrix
|
|
//
|
|
// Description:
|
|
// The matrix is printed out in square brackets.
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
template <typename T>
|
|
bool print_matrix(const panic::tensor::matrix<T>& A){
|
|
|
|
std::cout << "[";
|
|
for (panic::types::uint_t i = 0; i < A.rows(); ++i){
|
|
std::cout << "[";
|
|
|
|
for (panic::types::uint_t j = 0; j < A.cols(); ++j){
|
|
std::cout << A(i, j);
|
|
|
|
if (j + 1 < A.cols()){
|
|
std::cout << ", ";
|
|
}
|
|
}
|
|
|
|
std::cout << "]";
|
|
|
|
if (i + 1 < A.rows())
|
|
std::cout << "," << std::endl;
|
|
}
|
|
|
|
std::cout << "]" << std::endl;
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
// EXPLICIT TEMPLATE INSTANTIATION
|
|
//
|
|
// The implementation is in this .cpp file.
|
|
// Build the overload for the official PANIC numeric types.
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
template bool print_matrix<panic::types::uint_t>(const panic::tensor::matrix<panic::types::uint_t>& A
|
|
);
|
|
template bool print_matrix<panic::types::int_t>(const panic::tensor::matrix<panic::types::int_t>& A
|
|
);
|
|
template bool print_matrix<panic::types::real_t>(const panic::tensor::matrix<panic::types::real_t>& A
|
|
);
|
|
|
|
|
|
|
|
|
|
} // namespace io
|
|
}// namespace panic
|