From 95d01f4589ca173da6f2c3f5ad45821e7e4c4ef5 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 30 Jan 2024 00:30:24 -0500 Subject: [PATCH] add copying function --- extern/bindings/.gitignore | 1 + extern/bindings/Cargo.lock | 4 ++-- extern/bindings/src/lib.rs | 33 +++++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/extern/bindings/.gitignore b/extern/bindings/.gitignore index 2f7896d..2c96eb1 100644 --- a/extern/bindings/.gitignore +++ b/extern/bindings/.gitignore @@ -1 +1,2 @@ target/ +Cargo.lock diff --git a/extern/bindings/Cargo.lock b/extern/bindings/Cargo.lock index 9a299fc..10aebad 100644 --- a/extern/bindings/Cargo.lock +++ b/extern/bindings/Cargo.lock @@ -231,8 +231,8 @@ dependencies = [ [[package]] name = "stattest" -version = "0.0.0" -source = "git+https://github.com/Tri11Paragon/stattest#d05d11f1515278904c1be74a76311e9c4550eeae" +version = "0.0.1" +source = "git+https://github.com/Tri11Paragon/stattest#f28a14740a90cc63f69d0fe26f63da96dad6e319" dependencies = [ "rand", "statrs", diff --git a/extern/bindings/src/lib.rs b/extern/bindings/src/lib.rs index f25ed0a..ce1892a 100644 --- a/extern/bindings/src/lib.rs +++ b/extern/bindings/src/lib.rs @@ -1,5 +1,7 @@ #![crate_type="cdylib"] +use stattest::test::{ShapiroWilkError, ShapiroWilkStatus, ShapiroWilkTest}; + #[no_mangle] pub extern "C" fn test() { println!("Hello"); @@ -17,12 +19,7 @@ pub struct Bruh { weights_capacity: usize, } -#[no_mangle] -pub extern "C-unwind" fn willbert(data: *const f64, len: usize) -> Bruh { - use stattest::test::{ShapiroWilkError, ShapiroWilkStatus}; - - let slice = unsafe { std::slice::from_raw_parts(data, len) }; - let result = stattest::test::ShapiroWilkTest::new(slice); +fn create_bruh(result: Result) -> Bruh { match result { Ok(results) => { let (weights, weights_len, weights_capacity) = { @@ -60,3 +57,27 @@ pub extern "C-unwind" fn willbert(data: *const f64, len: usize) -> Bruh { } } } + +/// # Safety +/// data must be a valid unique ptr to len f64's +/// requires input data to be sorted +#[no_mangle] +pub extern "C-unwind" fn willbert(data: *const f64, len: usize) -> Bruh { + let slice = unsafe { std::slice::from_raw_parts(data, len) }; + let result = ShapiroWilkTest::new_sorted(slice); + create_bruh(result) +} + +#[no_mangle] +pub extern "C-unwind" fn willbert_unsorted(data: *mut f64, len: usize) -> Bruh { + let slice = unsafe { std::slice::from_raw_parts_mut(data, len) }; + let result = ShapiroWilkTest::new(slice); + create_bruh(result) +} + +#[no_mangle] +pub extern "C-unwind" fn willbert_unsorted_copy(data: *const f64, len: usize) -> Bruh { + let slice = unsafe { std::slice::from_raw_parts(data, len) }; + let result = ShapiroWilkTest::new_copy(slice); + create_bruh(result) +} \ No newline at end of file