-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5805a8a
commit 3f8d607
Showing
21 changed files
with
274 additions
and
80 deletions.
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 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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
[package] | ||
name = "carefree-pyo3" | ||
[workspace] | ||
members = [ | ||
"cfpyo3_rs_core", | ||
"cfpyo3_rs_py", | ||
] | ||
resolver = "2" | ||
|
||
[workspace.package] | ||
version = "0.1.7" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
name = "cfpyo3" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
itertools = "0.13.0" | ||
md-5 = "0.10.6" | ||
num-traits = "0.2.19" | ||
numpy = "0.21.0" | ||
paste = "1.0.15" | ||
pyo3 = { version = "0.21.0", features = ["abi3-py38", "chrono", "extension-module", "multiple-pymethods"] } | ||
rayon = "1.10.0" | ||
authors = ["carefree0910 <[email protected]>"] | ||
description = "a collection of performant utilities" | ||
homepage = "https://github.com/carefree0910/carefree-pyo3" | ||
repository = "https://github.com/carefree0910/carefree-pyo3" | ||
readme = "README.md" | ||
keywords = ["python", "rust", "pyo3"] | ||
categories = ["algorithms", "data-structures"] | ||
license-file = "LICENSE" |
This file contains 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,23 @@ | ||
[package] | ||
name = "cfpyo3_rs_core" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
license-file.workspace = true | ||
|
||
[lib] | ||
name = "cfpyo3_core" | ||
crate-type = ["rlib"] | ||
|
||
[dependencies] | ||
itertools = "0.13.0" | ||
md-5 = "0.10.6" | ||
num-traits = "0.2.19" | ||
numpy = "0.21.0" | ||
rayon = "1.10.0" |
File renamed without changes.
This file contains 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,12 @@ | ||
use crate::toolkit::array::AFloat; | ||
|
||
use super::{ColumnsDtype, IndexDtype}; | ||
use numpy::ndarray::{ArrayView1, ArrayView2}; | ||
|
||
mod ops; | ||
|
||
pub struct DataFrame<'a, T: AFloat> { | ||
pub index: ArrayView1<'a, IndexDtype>, | ||
pub columns: ArrayView1<'a, ColumnsDtype>, | ||
pub data: ArrayView2<'a, T>, | ||
} |
This file contains 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,13 @@ | ||
use super::DataFrame; | ||
use crate::toolkit::array::{corr_axis1, mean_axis1, AFloat}; | ||
use numpy::ndarray::ArrayView2; | ||
|
||
impl<'a, T: AFloat> DataFrame<'a, T> { | ||
pub fn mean_axis1(&'a self, num_threads: usize) -> Vec<T> { | ||
mean_axis1(&self.data.view(), num_threads) | ||
} | ||
|
||
pub fn corr_with_axis1(&'a self, other: ArrayView2<T>, num_threads: usize) -> Vec<T> { | ||
corr_axis1(&self.data.view(), &other.view(), num_threads) | ||
} | ||
} |
This file contains 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,2 @@ | ||
pub mod df; | ||
pub mod toolkit; |
File renamed without changes.
This file contains 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 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 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,71 @@ | ||
use cfpyo3_core::toolkit::array; | ||
use numpy::ndarray::ArrayView2; | ||
|
||
fn assert_allclose<T: array::AFloat>(a: &[T], b: &[T]) { | ||
let atol = T::from_f64(1e-6).unwrap(); | ||
let rtol = T::from_f64(1e-6).unwrap(); | ||
a.iter().zip(b.iter()).for_each(|(&x, &y)| { | ||
assert!( | ||
(x - y).abs() <= atol + rtol * y.abs(), | ||
"not close - x: {:?}, y: {:?}", | ||
x, | ||
y | ||
); | ||
}); | ||
} | ||
|
||
macro_rules! test_fast_concat_2d_axis0 { | ||
($dtype:ty) => { | ||
let array_2d_u = ArrayView2::<$dtype>::from_shape((1, 3), &[1., 2., 3.]).unwrap(); | ||
let array_2d_l = | ||
ArrayView2::<$dtype>::from_shape((2, 3), &[4., 5., 6., 7., 8., 9.]).unwrap(); | ||
let arrays = vec![array_2d_u, array_2d_l]; | ||
let mut out: Vec<$dtype> = vec![0.; 3 * 3]; | ||
let out_slice = array::UnsafeSlice::new(out.as_mut_slice()); | ||
array::fast_concat_2d_axis0(arrays, vec![1, 2], 3, 1, out_slice); | ||
assert_eq!(out.as_slice(), &[1., 2., 3., 4., 5., 6., 7., 8., 9.]); | ||
}; | ||
} | ||
|
||
macro_rules! test_mean_axis1 { | ||
($dtype:ty) => { | ||
let array = ArrayView2::<$dtype>::from_shape((2, 3), &[1., 2., 3., 4., 5., 6.]).unwrap(); | ||
let out = array::mean_axis1(&array, 1); | ||
assert_allclose(out.as_slice(), &[2., 5.]); | ||
}; | ||
} | ||
|
||
macro_rules! test_corr_axis1 { | ||
($dtype:ty) => { | ||
let array = ArrayView2::<$dtype>::from_shape((2, 3), &[1., 2., 3., 4., 5., 6.]).unwrap(); | ||
let out = array::corr_axis1(&array, &(&array + 1.).view(), 1); | ||
assert_allclose(out.as_slice(), &[1., 1.]); | ||
}; | ||
} | ||
|
||
#[test] | ||
fn test_fast_concat_2d_axis0_f32() { | ||
test_fast_concat_2d_axis0!(f32); | ||
} | ||
#[test] | ||
fn test_fast_concat_2d_axis0_f64() { | ||
test_fast_concat_2d_axis0!(f64); | ||
} | ||
|
||
#[test] | ||
fn test_mean_axis1_f32() { | ||
test_mean_axis1!(f32); | ||
} | ||
#[test] | ||
fn test_mean_axis1_f64() { | ||
test_mean_axis1!(f64); | ||
} | ||
|
||
#[test] | ||
fn test_corr_axis1_f32() { | ||
test_corr_axis1!(f32); | ||
} | ||
#[test] | ||
fn test_corr_axis1_f64() { | ||
test_corr_axis1!(f64); | ||
} |
This file contains 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,22 @@ | ||
[package] | ||
name = "cfpyo3_rs_py" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
license-file.workspace = true | ||
|
||
[lib] | ||
name = "cfpyo3" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
cfpyo3_rs_core = { path = "../cfpyo3_rs_core" } | ||
numpy = "0.21.0" | ||
paste = "1.0.15" | ||
pyo3 = { version = "0.21.0", features = ["abi3-py38", "chrono", "extension-module", "multiple-pymethods"] } |
This file contains 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 @@ | ||
pub mod frame; |
This file contains 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 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
Oops, something went wrong.