Skip to content

Commit

Permalink
wip: Adds functions to produce gradient and random data in 1D.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliakatas committed Jan 1, 2025
1 parent 9057c3a commit 5a937f6
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions include/maths_geometry/data_producers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

// #include <cmath>
// #include <algorithm>
#include <type_traits>
#include <cstdlib>

#ifdef __NVCC__
#include <device_launch_parameters.h>
#define HOSTDEVDECOR __host__ __device__
#else
#define HOSTDEVDECOR
#endif

namespace dataprod
{
/**
* @brief
*
* @tparam T
* @tparam num_t
*
*/
template <typename T, typename num_t>
HOSTDEVDECOR
typename std::enable_if<std::is_floating_point<T>::value &&
std::is_integral<num_t>::value, void>::type
gradient_1D(T* data, num_t n, T start, T finish)
{
T dd = (finish - start) / (n - 1);
for (auto i = 0; i < n; ++i)
data[i] = start + i * dd;
}

/**
* @brief
*
* @tparam T
* @tparam num_t
*
*/
template <typename T, typename num_t>
HOSTDEVDECOR
typename std::enable_if<std::is_floating_point<T>::value &&
std::is_integral<num_t>::value, void>::type
random_1D(T* data, num_t n, T minval, T maxval)
{
T dd = (finish - start) / (n - 1);
for (auto i = 0; i < n; ++i)
data[i] = minval + (static_cast<T>(std::rand()) / stati_cast<T>(RAND_MAX)) * (maxval - minval);
}

// TODO:
// - gradient 2D
// - random 2D
// - waves 1D
// - waves 2D
// - modify 1D domain with features (using set values)
// - modify 2D domain with features (using set values)


}

0 comments on commit 5a937f6

Please sign in to comment.