feat: Added ndarray_15 feature
This commit is contained in:
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -18,6 +18,19 @@ dependencies = [
|
|||||||
"rawpointer",
|
"rawpointer",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ndarray"
|
||||||
|
version = "0.15.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32"
|
||||||
|
dependencies = [
|
||||||
|
"matrixmultiply",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"rawpointer",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ndarray"
|
name = "ndarray"
|
||||||
version = "0.16.1"
|
version = "0.16.1"
|
||||||
@@ -37,7 +50,8 @@ dependencies = [
|
|||||||
name = "ndarray-math"
|
name = "ndarray-math"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ndarray",
|
"ndarray 0.15.6",
|
||||||
|
"ndarray 0.16.1",
|
||||||
"num",
|
"num",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ license = "MIT"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ndarray = "0.16"
|
ndarray = { version = "0.16" }
|
||||||
|
ndarray_15 = { package = "ndarray", version = "0.15.6", optional = true }
|
||||||
num = "0.4.3"
|
num = "0.4.3"
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
ndarray_15 = ["dep:ndarray_15"]
|
||||||
|
|||||||
@@ -132,6 +132,7 @@
|
|||||||
stableToolchainWithRustAnalyzer
|
stableToolchainWithRustAnalyzer
|
||||||
cargo-nextest
|
cargo-nextest
|
||||||
cargo-deny
|
cargo-deny
|
||||||
|
cargo-hack
|
||||||
]
|
]
|
||||||
++ (lib.optionals pkgs.stdenv.isDarwin [
|
++ (lib.optionals pkgs.stdenv.isDarwin [
|
||||||
apple-sdk_13
|
apple-sdk_13
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
#[cfg(feature = "ndarray_15")]
|
||||||
|
use crate::ndarray_15_extra::Pow;
|
||||||
use ndarray::{ArrayBase, Ix1};
|
use ndarray::{ArrayBase, Ix1};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
|
||||||
pub enum CosineSimilarityError {
|
pub enum CosineSimilarityError {
|
||||||
#[error(
|
#[error(
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
|
#[cfg(feature = "ndarray_15")]
|
||||||
|
extern crate ndarray_15 as ndarray;
|
||||||
|
pub mod ndarray_15_extra;
|
||||||
|
|
||||||
mod cosine;
|
mod cosine;
|
||||||
pub use cosine::{CosineSimilarity, CosineSimilarityError};
|
pub use cosine::{CosineSimilarity, CosineSimilarityError};
|
||||||
|
|||||||
15
src/ndarray_15_extra.rs
Normal file
15
src/ndarray_15_extra.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
pub trait Pow {
|
||||||
|
type Output;
|
||||||
|
fn powi(&self, rhs: i32) -> Self::Output;
|
||||||
|
}
|
||||||
|
impl<T, S, D> Pow for ndarray::ArrayBase<S, D>
|
||||||
|
where
|
||||||
|
S: ndarray::Data<Elem = T>,
|
||||||
|
T: num::Float,
|
||||||
|
D: ndarray::Dimension,
|
||||||
|
{
|
||||||
|
type Output = ndarray::Array<T, D>;
|
||||||
|
fn powi(&self, rhs: i32) -> Self::Output {
|
||||||
|
self.mapv(|x| x.powi(rhs))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user