gpu.cpp 0.1.0
 
Loading...
Searching...
No Matches
array_utils.h File Reference
#include <algorithm>
#include <array>
#include <cmath>
#include <random>
#include <stdexcept>
#include <string>
#include <utility>
#include "utils/logging.h"

Go to the source code of this file.

Namespaces

namespace  gpu
 

Functions

template<typename numtype >
std::string gpu::show (const numtype *a, size_t rows, size_t cols, const std::string &name="")
 Show a 2D array as a string, base implementation.
 
template<typename numtype , size_t rows, size_t cols>
std::string gpu::show (const std::array< numtype, rows *cols > &a, const std::string &name="")
 Overload of show() for std::array.
 
template<size_t rows, size_t cols>
std::string gpu::show (const std::array< float, rows *cols > &a, const std::string &name="")
 Overload of show() for float std::array.
 
void gpu::range (float *input, size_t N, float start=0.0, float step=1.0)
 Populate the array with a range of values. This is mostly for testing purposes.
 
template<size_t N>
void gpu::range (std::array< float, N > &input, float start=0.0, float step=1.0)
 Overload of range() for std::array.
 
void gpu::randint (float *a, size_t N, std::mt19937 &gen, int min=-1, int max=1)
 Populate the array with random integers.
 
template<typename numtype , size_t size>
void gpu::randint (std::array< numtype, size > &a, std::mt19937 &gen, int min=-1, int max=1)
 Overload of randint() for std::array.
 
void gpu::randn (float *a, size_t N, std::mt19937 &gen, float mean=0.0, float std=1.0)
 Populate the array with random floats, generated from a Gaussian distribution.
 
template<size_t size>
void gpu::randn (std::array< float, size > &a, std::mt19937 &gen, float mean=0.0, float std=1.0)
 Overload of randn() for std::array.
 
void gpu::eye (float *a, size_t N)
 Populate a square matrix with the identity matrix.
 
void gpu::transpose (float *input, float *output, size_t M, size_t N)
 Transpose a matrix.
 
void gpu::flip (float *a, size_t R, size_t C, bool horizontal=true)
 Flip a matrix horizontally or vertically.
 
bool gpu::isclose (float *a, float *b, size_t n, float tol=1e-3)
 Determine if the values of two arrays are close to each other.
 

Variables

static constexpr int gpu::kShowMaxRows = 8
 
static constexpr int gpu::kShowMaxCols = 8