Skip to content

Commit 806fa2d

Browse files
refactor!(core): Move everything into the gprat namespace
1 parent 5976c4d commit 806fa2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+644
-448
lines changed

bindings/gprat_py.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "gprat/gprat_c.hpp"
2+
23
#include <pybind11/pybind11.h>
34
#include <pybind11/stl.h>
45

@@ -31,19 +32,19 @@ void init_gprat(py::module &m)
3132
// Set hyperparameters to default values in `AdamParams` class, unless
3233
// specified. Python object has full access to each hyperparameter and a
3334
// string representation `__repr__`.
34-
py::class_<gprat_hyper::AdamParams>(m, "AdamParams")
35+
py::class_<gprat::AdamParams>(m, "AdamParams")
3536
.def(py::init<double, double, double, double, int>(),
3637
py::arg("learning_rate") = 0.001,
3738
py::arg("beta1") = 0.9,
3839
py::arg("beta2") = 0.999,
3940
py::arg("epsilon") = 1e-8,
4041
py::arg("opt_iter") = 0)
41-
.def_readwrite("learning_rate", &gprat_hyper::AdamParams::learning_rate)
42-
.def_readwrite("beta1", &gprat_hyper::AdamParams::beta1)
43-
.def_readwrite("beta2", &gprat_hyper::AdamParams::beta2)
44-
.def_readwrite("epsilon", &gprat_hyper::AdamParams::epsilon)
45-
.def_readwrite("opt_iter", &gprat_hyper::AdamParams::opt_iter)
46-
.def("__repr__", &gprat_hyper::AdamParams::repr);
42+
.def_readwrite("learning_rate", &gprat::AdamParams::learning_rate)
43+
.def_readwrite("beta1", &gprat::AdamParams::beta1)
44+
.def_readwrite("beta2", &gprat::AdamParams::beta2)
45+
.def_readwrite("epsilon", &gprat::AdamParams::epsilon)
46+
.def_readwrite("opt_iter", &gprat::AdamParams::opt_iter)
47+
.def("__repr__", &gprat::AdamParams::repr);
4748

4849
// Initializes Gaussian Process with `GP` class. Sets default parameters for
4950
// squared exponential kernel, number of regressors and trainable, unless

bindings/utils_py.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gprat/target.hpp"
22
#include "gprat/utils_c.hpp"
3+
34
#include <pybind11/pybind11.h>
45
#include <pybind11/stl.h>
56

@@ -32,7 +33,7 @@ void start_hpx_wrapper(std::vector<std::string> args, std::size_t n_cores)
3233
}
3334
argv.push_back(nullptr);
3435
int argc = static_cast<int>(args.size());
35-
utils::start_hpx_runtime(argc, argv.data());
36+
gprat::start_hpx_runtime(argc, argv.data());
3637
}
3738

3839
/**
@@ -43,7 +44,7 @@ void start_hpx_wrapper(std::vector<std::string> args, std::size_t n_cores)
4344
void init_utils(py::module &m)
4445
{
4546
m.def("compute_train_tiles",
46-
&utils::compute_train_tiles,
47+
&gprat::compute_train_tiles,
4748
py::arg("n_samples"),
4849
py::arg("n_tile_size"),
4950
R"pbdoc(
@@ -58,7 +59,7 @@ void init_utils(py::module &m)
5859
)pbdoc");
5960

6061
m.def("compute_train_tile_size",
61-
&utils::compute_train_tile_size,
62+
&gprat::compute_train_tile_size,
6263
py::arg("n_samples"),
6364
py::arg("n_tiles"),
6465
R"pbdoc(
@@ -73,7 +74,7 @@ void init_utils(py::module &m)
7374
)pbdoc");
7475

7576
m.def("compute_test_tiles",
76-
&utils::compute_test_tiles,
77+
&gprat::compute_test_tiles,
7778
py::arg("m_samples"),
7879
py::arg("n_tiles"),
7980
py::arg("n_tile_size"),
@@ -90,19 +91,19 @@ void init_utils(py::module &m)
9091
)pbdoc");
9192

9293
m.def("print_vector",
93-
&utils::print_vector,
94+
&gprat::print_vector,
9495
py::arg("vec"),
9596
py::arg("start") = 0,
9697
py::arg("end") = -1,
9798
py::arg("separator") = " ",
9899
"Print elements of a vector with optional start, end, and separator parameters");
99100

100101
m.def("start_hpx", &start_hpx_wrapper, py::arg("args"), py::arg("n_cores")); // Using the wrapper function
101-
m.def("resume_hpx", &utils::resume_hpx_runtime);
102-
m.def("suspend_hpx", &utils::suspend_hpx_runtime);
103-
m.def("stop_hpx", &utils::stop_hpx_runtime);
102+
m.def("resume_hpx", &gprat::resume_hpx_runtime);
103+
m.def("suspend_hpx", &gprat::suspend_hpx_runtime);
104+
m.def("stop_hpx", &gprat::stop_hpx_runtime);
104105

105-
m.def("compiled_with_cuda", &utils::compiled_with_cuda, "Check if the code was compiled with CUDA support");
106+
m.def("compiled_with_cuda", &gprat::compiled_with_cuda, "Check if the code was compiled with CUDA support");
106107

107108
m.def("print_available_gpus", &gprat::print_available_gpus, "Print available GPUs with their properties");
108109
m.def("gpu_count", &gprat::gpu_count, "Return the number of available GPUs");

core/include/gprat/cpu/adapter_cblas_fp32.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
#ifndef CPU_ADAPTER_CBLAS_FP32_H
2-
#define CPU_ADAPTER_CBLAS_FP32_H
1+
#ifndef GPRAT_CPU_ADAPTER_CBLAS_FP32_HPP
2+
#define GPRAT_CPU_ADAPTER_CBLAS_FP32_HPP
33

4+
#pragma once
5+
6+
#include "gprat/detail/config.hpp"
47
#include <hpx/future.hpp>
58
#include <vector>
9+
10+
GPRAT_NS_BEGIN
11+
612
using vector_future = hpx::shared_future<std::vector<float>>;
713

814
// Constants that are compatible with CBLAS
@@ -145,4 +151,6 @@ vector_future axpy(vector_future f_y, vector_future f_x, const int N);
145151
*/
146152
float dot(std::vector<float> a, std::vector<float> b, const int N);
147153

148-
#endif // end of CPU_ADAPTER_CBLAS_FP32_H
154+
GPRAT_NS_END
155+
156+
#endif

core/include/gprat/cpu/adapter_cblas_fp64.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
#ifndef CPU_ADAPTER_CBLAS_FP64_H
2-
#define CPU_ADAPTER_CBLAS_FP64_H
1+
#ifndef GPRAT_CPU_ADAPTER_CBLAS_FP64_HPP
2+
#define GPRAT_CPU_ADAPTER_CBLAS_FP64_HPP
33

4+
#pragma once
5+
6+
#include "gprat/detail/config.hpp"
47
#include <hpx/future.hpp>
58
#include <vector>
69

10+
GPRAT_NS_BEGIN
11+
712
using vector_future = hpx::shared_future<std::vector<double>>;
813

914
// Constants that are compatible with CBLAS
10-
1115
typedef enum BLAS_TRANSPOSE { Blas_no_trans = 111, Blas_trans = 112 } BLAS_TRANSPOSE;
1216

1317
typedef enum BLAS_SIDE { Blas_left = 141, Blas_right = 142 } BLAS_SIDE;
@@ -147,4 +151,6 @@ vector_future axpy(vector_future f_y, vector_future f_x, const int N);
147151
*/
148152
double dot(std::vector<double> a, std::vector<double> b, const int N);
149153

150-
#endif // end of CPU_ADAPTER_CBLAS_FP64_H
154+
GPRAT_NS_END
155+
156+
#endif

core/include/gprat/cpu/gp_algorithms.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
#ifndef CPU_GP_ALGORITHMS_H
2-
#define CPU_GP_ALGORITHMS_H
1+
#ifndef GPRAT_CPU_GP_ALGORITHMS_HPP
2+
#define GPRAT_CPU_GP_ALGORITHMS_HPP
3+
4+
#pragma once
5+
6+
#include "gprat/detail/config.hpp"
7+
#include "gprat/gp_kernels.hpp"
38

4-
#include "gp_kernels.hpp"
59
#include <vector>
610

11+
GPRAT_NS_BEGIN
12+
713
namespace cpu
814
{
915

@@ -22,7 +28,7 @@ namespace cpu
2228
double compute_covariance_function(std::size_t i_global,
2329
std::size_t j_global,
2430
std::size_t n_regressors,
25-
const gprat_hyper::SEKParams &sek_params,
31+
const SEKParams &sek_params,
2632
const std::vector<double> &i_input,
2733
const std::vector<double> &j_input);
2834

@@ -44,7 +50,7 @@ std::vector<double> gen_tile_covariance(
4450
std::size_t col,
4551
std::size_t N,
4652
std::size_t n_regressors,
47-
const gprat_hyper::SEKParams &sek_params,
53+
const SEKParams &sek_params,
4854
const std::vector<double> &input);
4955

5056
/**
@@ -66,7 +72,7 @@ std::vector<double> gen_tile_full_prior_covariance(
6672
std::size_t col,
6773
std::size_t N,
6874
std::size_t n_regressors,
69-
const gprat_hyper::SEKParams &sek_params,
75+
const SEKParams &sek_params,
7076
const std::vector<double> &input);
7177

7278
/**
@@ -88,7 +94,7 @@ std::vector<double> gen_tile_prior_covariance(
8894
std::size_t col,
8995
std::size_t N,
9096
std::size_t n_regressors,
91-
const gprat_hyper::SEKParams &sek_params,
97+
const SEKParams &sek_params,
9298
const std::vector<double> &input);
9399

94100
/**
@@ -111,7 +117,7 @@ std::vector<double> gen_tile_cross_covariance(
111117
std::size_t N_row,
112118
std::size_t N_col,
113119
std::size_t n_regressors,
114-
const gprat_hyper::SEKParams &sek_params,
120+
const SEKParams &sek_params,
115121
const std::vector<double> &row_input,
116122
const std::vector<double> &col_input);
117123

@@ -170,4 +176,6 @@ std::vector<double> gen_tile_identity(std::size_t N);
170176

171177
} // end of namespace cpu
172178

173-
#endif // end of CPU_GP_ALGORITHMS_H
179+
GPRAT_NS_END
180+
181+
#endif

core/include/gprat/cpu/gp_functions.hpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#ifndef CPU_GP_FUNCTIONS_H
2-
#define CPU_GP_FUNCTIONS_H
1+
#ifndef GPRAT_CPU_GP_FUNCTIONS_HPP
2+
#define GPRAT_CPU_GP_FUNCTIONS_HPP
33

4-
#include "gp_hyperparameters.hpp"
5-
#include "gp_kernels.hpp"
4+
#pragma once
5+
6+
#include "gprat/detail/config.hpp"
7+
#include "gprat/gp_hyperparameters.hpp"
8+
#include "gprat/gp_kernels.hpp"
69
#include <vector>
710

11+
GPRAT_NS_BEGIN
12+
813
namespace cpu
914
{
1015

@@ -22,7 +27,7 @@ namespace cpu
2227
*/
2328
std::vector<std::vector<double>>
2429
cholesky(const std::vector<double> &training_input,
25-
const gprat_hyper::SEKParams &sek_params,
30+
const SEKParams &sek_params,
2631
int n_tiles,
2732
int n_tile_size,
2833
int n_regressors);
@@ -46,7 +51,7 @@ std::vector<double>
4651
predict(const std::vector<double> &training_input,
4752
const std::vector<double> &training_output,
4853
const std::vector<double> &test_input,
49-
const gprat_hyper::SEKParams &sek_params,
54+
const SEKParams &sek_params,
5055
int n_tiles,
5156
int n_tile_size,
5257
int m_tiles,
@@ -72,7 +77,7 @@ std::vector<std::vector<double>> predict_with_uncertainty(
7277
const std::vector<double> &training_input,
7378
const std::vector<double> &training_output,
7479
const std::vector<double> &test_input,
75-
const gprat_hyper::SEKParams &sek_params,
80+
const SEKParams &sek_params,
7681
int n_tiles,
7782
int n_tile_size,
7883
int m_tiles,
@@ -98,7 +103,7 @@ std::vector<std::vector<double>> predict_with_full_cov(
98103
const std::vector<double> &training_input,
99104
const std::vector<double> &training_output,
100105
const std::vector<double> &test_data,
101-
const gprat_hyper::SEKParams &sek_params,
106+
const SEKParams &sek_params,
102107
int n_tiles,
103108
int n_tile_size,
104109
int m_tiles,
@@ -119,7 +124,7 @@ std::vector<std::vector<double>> predict_with_full_cov(
119124
*/
120125
double compute_loss(const std::vector<double> &training_input,
121126
const std::vector<double> &training_output,
122-
const gprat_hyper::SEKParams &sek_params,
127+
const SEKParams &sek_params,
123128
int n_tiles,
124129
int n_tile_size,
125130
int n_regressors);
@@ -146,8 +151,8 @@ optimize(const std::vector<double> &training_input,
146151
int n_tiles,
147152
int n_tile_size,
148153
int n_regressors,
149-
const gprat_hyper::AdamParams &adam_params,
150-
gprat_hyper::SEKParams &sek_params,
154+
const AdamParams &adam_params,
155+
SEKParams &sek_params,
151156
std::vector<bool> trainable_params);
152157

153158
/**
@@ -173,11 +178,13 @@ double optimize_step(const std::vector<double> &training_input,
173178
int n_tiles,
174179
int n_tile_size,
175180
int n_regressors,
176-
gprat_hyper::AdamParams &adam_params,
177-
gprat_hyper::SEKParams &sek_params,
181+
AdamParams &adam_params,
182+
SEKParams &sek_params,
178183
std::vector<bool> trainable_params,
179184
int iter);
180185

181186
} // end of namespace cpu
182187

183-
#endif // end of CPU_GP_FUNCTIONS_H
188+
GPRAT_NS_END
189+
190+
#endif

0 commit comments

Comments
 (0)