add copying function

main
Brett 2024-01-30 00:30:24 -05:00
parent 93188a6120
commit 95d01f4589
3 changed files with 30 additions and 8 deletions

View File

@ -1 +1,2 @@
target/ target/
Cargo.lock

4
extern/bindings/Cargo.lock generated vendored
View File

@ -231,8 +231,8 @@ dependencies = [
[[package]] [[package]]
name = "stattest" name = "stattest"
version = "0.0.0" version = "0.0.1"
source = "git+https://github.com/Tri11Paragon/stattest#d05d11f1515278904c1be74a76311e9c4550eeae" source = "git+https://github.com/Tri11Paragon/stattest#f28a14740a90cc63f69d0fe26f63da96dad6e319"
dependencies = [ dependencies = [
"rand", "rand",
"statrs", "statrs",

View File

@ -1,5 +1,7 @@
#![crate_type="cdylib"] #![crate_type="cdylib"]
use stattest::test::{ShapiroWilkError, ShapiroWilkStatus, ShapiroWilkTest};
#[no_mangle] #[no_mangle]
pub extern "C" fn test() { pub extern "C" fn test() {
println!("Hello"); println!("Hello");
@ -17,12 +19,7 @@ pub struct Bruh {
weights_capacity: usize, weights_capacity: usize,
} }
#[no_mangle] fn create_bruh(result: Result<ShapiroWilkTest, ShapiroWilkError>) -> Bruh {
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);
match result { match result {
Ok(results) => { Ok(results) => {
let (weights, weights_len, weights_capacity) = { 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)
}