Skip to content

Commit

Permalink
Change C API
Browse files Browse the repository at this point in the history
  • Loading branch information
frostedoyster committed Aug 19, 2024
1 parent 0d61c52 commit 1ca11d3
Show file tree
Hide file tree
Showing 4 changed files with 785 additions and 108 deletions.
4 changes: 2 additions & 2 deletions benchmarks/cpp/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ template <typename DTYPE> void run_timings(int l_max, int n_tries, int n_samples
auto ddsph1 = std::vector<DTYPE>(n_samples * 9 * (l_max + 1) * (l_max + 1), 0.0);

{
SphericalHarmonics<DTYPE> calculator(l_max, false);
SolidHarmonics<DTYPE> calculator(l_max);
sxyz[0] = xyz[0];
sxyz[1] = xyz[1];
sxyz[2] = xyz[2];
Expand Down Expand Up @@ -143,7 +143,7 @@ template <typename DTYPE> void run_timings(int l_max, int n_tries, int n_samples
}

{
SphericalHarmonics<DTYPE> calculator(l_max, true);
SphericalHarmonics<DTYPE> calculator(l_max);
benchmark("Call without derivatives (normalized)", n_samples, n_tries, [&]() {
calculator.compute(xyz, sph1);
});
Expand Down
26 changes: 15 additions & 11 deletions examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,36 @@ int main(int argc, char* argv[]) {
/* ===== API calls ===== */

// opaque pointer declaration: initializes buffers and numerical factors
sphericart_calculator_t* calculator = sphericart_new(l_max, 0);
sphericart_spherical_harmonics_calculator_t* calculator =
sphericart_spherical_harmonics_new(l_max);

// function calls
// without derivatives
sphericart_compute_array(calculator, xyz, 3 * n_samples, sph, sph_size);
sphericart_spherical_harmonics_compute_array(calculator, xyz, 3 * n_samples, sph, sph_size);
// with derivatives
sphericart_compute_array_with_gradients(
sphericart_spherical_harmonics_compute_array_with_gradients(
calculator, xyz, 3 * n_samples, sph, sph_size, dsph, dsph_size
);
// with second derivatives
sphericart_compute_array_with_hessians(
sphericart_spherical_harmonics_compute_array_with_hessians(
calculator, xyz, 3 * n_samples, sph, sph_size, dsph, dsph_size, ddsph, ddsph_size
);

// per-sample calculation - we reuse the same arrays for simplicity, but
// only the first item is computed
sphericart_compute_sample(calculator, xyz, 3, sph, sph_size);
sphericart_compute_sample_with_gradients(calculator, xyz, 3, sph, sph_size, dsph, dsph_size);
sphericart_compute_sample_with_hessians(
sphericart_spherical_harmonics_compute_sample(calculator, xyz, 3, sph, sph_size);
sphericart_spherical_harmonics_compute_sample_with_gradients(
calculator, xyz, 3, sph, sph_size, dsph, dsph_size
);
sphericart_spherical_harmonics_compute_sample_with_hessians(
calculator, xyz, 3, sph, sph_size, dsph, dsph_size, ddsph, ddsph_size
);

// float version
sphericart_calculator_f_t* calculator_f = sphericart_new_f(l_max, 0);
sphericart_spherical_harmonics_calculator_f_t* calculator_f =
sphericart_spherical_harmonics_new_f(l_max);

sphericart_compute_array_with_gradients_f(
sphericart_spherical_harmonics_compute_array_with_gradients_f(
calculator_f, xyz_f, 3 * n_samples, sph_f, sph_size, dsph_f, dsph_size
);

Expand All @@ -83,12 +87,12 @@ int main(int argc, char* argv[]) {
/* ===== clean up ===== */

// frees up data arrays and sph object pointers
sphericart_delete(calculator);
sphericart_spherical_harmonics_delete(calculator);
free(xyz);
free(sph);
free(dsph);

sphericart_delete_f(calculator_f);
sphericart_spherical_harmonics_delete_f(calculator_f);
free(xyz_f);
free(sph_f);
free(dsph_f);
Expand Down
Loading

0 comments on commit 1ca11d3

Please sign in to comment.