-
Notifications
You must be signed in to change notification settings - Fork 9
Mock external libome #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Mock external libome #562
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12c59ff
Init mock C++ library
AkshatRai07 e4d8595
Added build.rs
AkshatRai07 77867b3
Added as3.rs
AkshatRai07 9e8ff3c
Updated spacelike.rs fn and tests
AkshatRai07 9c6b85c
Updated ekore_capi and ekore_py
AkshatRai07 5f1b591
Updated ffi types
AkshatRai07 56a9123
Updated build.rs
AkshatRai07 0a3369d
Added gitlab/libome in README
AkshatRai07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,26 @@ | ||
| //! Build script to compile the mock `libome` C++ library from `extras/gsoc/libome` | ||
| //! and link it statically into `ekore`. | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| fn main() { | ||
| let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let libome_dir = manifest_dir.join("../../extras/gsoc/libome"); | ||
|
|
||
| println!( | ||
| "cargo:rerun-if-changed={}", | ||
| libome_dir.join("ome.cpp").display() | ||
| ); | ||
| println!( | ||
| "cargo:rerun-if-changed={}", | ||
| libome_dir.join("ome.h").display() | ||
| ); | ||
|
|
||
| cc::Build::new() | ||
| .cpp(true) | ||
| .flag_if_supported("-std=c++11") | ||
| .flag_if_supported("/std:c++14") | ||
| .include(&libome_dir) | ||
| .file(libome_dir.join("ome.cpp")) | ||
| .compile("ome"); | ||
|
Copilot marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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
94 changes: 94 additions & 0 deletions
94
crates/ekore/src/operator_matrix_elements/unpolarized/spacelike/as3.rs
This file contains hidden or 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,94 @@ | ||
| //! |N3LO| unpolarized, space-like |OME| via external `libome` C ABI. | ||
|
|
||
| use std::ffi::{c_int, c_uint}; | ||
|
|
||
| use num::Zero; | ||
| use num::complex::Complex; | ||
|
|
||
| use crate::harmonics::cache::Cache; | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug)] | ||
| struct OmeComplex { | ||
| re: f64, | ||
| im: f64, | ||
| } | ||
|
|
||
| impl From<Complex<f64>> for OmeComplex { | ||
| fn from(c: Complex<f64>) -> Self { | ||
| Self { re: c.re, im: c.im } | ||
| } | ||
| } | ||
|
|
||
| impl From<OmeComplex> for Complex<f64> { | ||
| fn from(c: OmeComplex) -> Self { | ||
| Complex::new(c.re, c.im) | ||
| } | ||
| } | ||
|
|
||
| unsafe extern "C" { | ||
| fn ome_as3_Agg(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_Agq(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_Aqg(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_AHg(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_AHq(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_AqqPS(n: OmeComplex, nf: c_uint, L: f64) -> OmeComplex; | ||
| fn ome_as3_AqqNS(n: OmeComplex, nf: c_uint, L: f64, eta: c_int) -> OmeComplex; | ||
| } | ||
|
|
||
| /// Compute the |N3LO| singlet |OME|. | ||
| pub(super) fn A_singlet(c: &mut Cache, nf: u8, L: f64) -> [[Complex<f64>; 3]; 3] { | ||
| let n: OmeComplex = c.n().into(); | ||
| let nf_c = c_uint::from(nf); | ||
|
|
||
| let a_gg = unsafe { Complex::from(ome_as3_Agg(n, nf_c, L)) }; | ||
| let a_gq = unsafe { Complex::from(ome_as3_Agq(n, nf_c, L)) }; | ||
| let a_qg = unsafe { Complex::from(ome_as3_Aqg(n, nf_c, L)) }; | ||
| let a_hg = unsafe { Complex::from(ome_as3_AHg(n, nf_c, L)) }; | ||
| let a_hq = unsafe { Complex::from(ome_as3_AHq(n, nf_c, L)) }; | ||
| let a_qq_ps = unsafe { Complex::from(ome_as3_AqqPS(n, nf_c, L)) }; | ||
| let a_qq_ns = unsafe { Complex::from(ome_as3_AqqNS(n, nf_c, L, 1 as c_int)) }; | ||
|
|
||
| [ | ||
| [a_gg, a_gq, Complex::<f64>::zero()], | ||
| [a_qg, a_qq_ps + a_qq_ns, Complex::<f64>::zero()], | ||
| [a_hg, a_hq, Complex::<f64>::zero()], | ||
| ] | ||
| } | ||
|
|
||
| /// Compute the |N3LO| non-singlet |OME|. | ||
| pub(super) fn A_ns(c: &mut Cache, nf: u8, L: f64) -> [[Complex<f64>; 2]; 2] { | ||
| let n: OmeComplex = c.n().into(); | ||
| let nf_c = c_uint::from(nf); | ||
| let a_qq_ns = unsafe { Complex::from(ome_as3_AqqNS(n, nf_c, L, -1 as c_int)) }; | ||
|
|
||
| [ | ||
| [a_qq_ns, Complex::<f64>::zero()], | ||
| [Complex::<f64>::zero(), Complex::<f64>::zero()], | ||
| ] | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::cmplx; | ||
|
|
||
| #[test] | ||
| fn test_as3_calls() { | ||
| const NF: u8 = 4; | ||
| let n = cmplx!(2.0, 1.5); | ||
| let mut c = Cache::new(n); | ||
| let a_s = A_singlet(&mut c, NF, 0.0); | ||
| for row in a_s.iter() { | ||
| for entry in row.iter() { | ||
| assert_eq!(*entry, Complex::zero()); | ||
| } | ||
| } | ||
| let a_ns = A_ns(&mut c, NF, 0.0); | ||
| for row in a_ns.iter() { | ||
| for entry in row.iter() { | ||
| assert_eq!(*entry, Complex::zero()); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.