1#![cfg_attr(
2 all(feature = "nightly-avx", rustc_is_nightly),
3 feature(stdarch_x86_avx512)
4)]
5#![cfg_attr(
6 all(feature = "nightly-avx", rustc_is_nightly),
7 feature(avx512_target_feature)
8)]
9#![cfg_attr(all(feature = "nightly-avx", rustc_is_nightly), feature(portable_simd))]
10#![cfg_attr(
11 all(feature = "nightly-avx", rustc_is_nightly),
12 feature(likely_unlikely)
13)]
14#![allow(warnings)]
15#![allow(clippy::needless_range_loop)]
16
17pub mod indicators;
18pub mod utilities;
19
20#[cfg(feature = "cuda")]
21pub mod cuda;
22
23#[cfg(all(test, not(target_arch = "wasm32")))]
24mod _rayon_one_big_stack {
25 use ctor::ctor;
26 use rayon::ThreadPoolBuilder;
27
28 #[ctor]
29 fn init_rayon_pool() {
30 let _ = ThreadPoolBuilder::new()
31 .num_threads(1)
32 .stack_size(8 * 1024 * 1024)
33 .build_global();
34 }
35}
36
37pub mod bindings {
38 #[cfg(feature = "python")]
39 pub mod python;
40
41 #[cfg(all(target_arch = "wasm32", feature = "wasm"))]
42 pub mod wasm;
43}
44
45#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
46use wasm_bindgen::prelude::*;
47
48#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
49#[wasm_bindgen]
50pub fn allocate_f64_array(len: usize) -> *mut f64 {
51 let mut v = Vec::<f64>::with_capacity(len);
52 let ptr = v.as_mut_ptr();
53 std::mem::forget(v);
54 ptr
55}
56
57#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
58#[wasm_bindgen]
59pub fn deallocate_f64_array(ptr: *mut f64) {}
60
61#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
62#[wasm_bindgen]
63pub fn read_f64_array(ptr: *const f64, len: usize) -> Vec<f64> {
64 unsafe { std::slice::from_raw_parts(ptr, len).to_vec() }
65}
66
67#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
68#[wasm_bindgen]
69pub fn allocate_f64_matrix(rows: usize, cols: usize) -> *mut f64 {
70 let mut v = Vec::<f64>::with_capacity(rows * cols);
71 let ptr = v.as_mut_ptr();
72 std::mem::forget(v);
73 ptr
74}
75
76#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
77#[wasm_bindgen]
78pub fn deallocate_f64_matrix(ptr: *mut f64) {}
79
80#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
81#[wasm_bindgen]
82pub fn read_f64_matrix(ptr: *const f64, rows: usize, cols: usize) -> js_sys::Array {
83 unsafe {
84 let flat = std::slice::from_raw_parts(ptr, rows * cols);
85 let result = js_sys::Array::new_with_length(rows as u32);
86 for i in 0..rows {
87 let row = js_sys::Float64Array::from(&flat[i * cols..(i + 1) * cols][..]);
88 result.set(i as u32, row.into());
89 }
90 result
91 }
92}