-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Adds functions to produce gradient and random data in 1D.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
} |