Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update dependencies #2

Merged
merged 7 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/ndg/make.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ndarray::Dimension;
use ndarray::{Dimension, ArrayView1, ArrayView2};

use crate::{
Real,
Expand All @@ -14,10 +14,13 @@ use super::{
util::permute_axes
};

use std::ops::Add;

impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
where
T: Real<T>,


D: Dimension
{
pub(super) fn make_spline(&mut self) -> Result<()> {
Expand All @@ -33,12 +36,21 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
let permuted_axes: D = permute_axes(ndim);

for ax in (0..ndim).rev() {
let x = breaks[ax].view();
let y = to_2d_simple(coeffs.view())?;
let x: ArrayView1<T> = breaks[ax].view();
let y: ArrayView2<T> = to_2d_simple(coeffs.view())?;

let weights = self.weights[ax].map(|v| v.reborrow());
let s = self.smooth[ax];

StefanUlbrich marked this conversation as resolved.
Show resolved Hide resolved
// Cannot explain how this error happens
//
// = note: required because of the requirements on the impl of `for<'r> Add` for `&'r CsMatBase<Simd<_, {_: usize}>, _, _, _, _, _>`
// = note: 127 redundant requirements hidden
// = note: required because of the requirements on the impl of `for<'r> Add` for `&'r CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase
// <CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase
// <CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase
// <CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase<CsMatBase

let sp = CubicSmoothingSpline::new(x, y)
.with_optional_weights(weights)
.with_optional_smooth(s)
Expand Down
42 changes: 36 additions & 6 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use ndarray::NdFloat;
use almost::AlmostEqual;
use sprs::{MulAcc};

use std::ops::{Mul, DivAssign};
use ndarray::NdFloat;
use sprs::{CsMatBase, MulAcc};

use num_traits;
use std::{
io::Read,
ops::{DivAssign, Mul, Add},
};

/// Floating-point element types `f32` and `f64`.
///
Expand All @@ -12,9 +15,36 @@ use std::ops::{Mul, DivAssign};
/// checking almost equality.
///
/// This trait can only be implemented by `f32` and `f64`.
pub trait Real<T>: NdFloat + AlmostEqual + Default + MulAcc + for<'r> DivAssign<&'r T> + Mul<T> {}
pub trait Real<T>:
num_traits::Zero
+ NdFloat
+ PartialEq
+ AlmostEqual
+ Clone
+ Default
+ MulAcc
+ for<'r> DivAssign<&'r T>
+ Mul<T>
{
}


impl Real<f32> for f32 {}
impl Real<f64> for f64 {}


fn test<T>(
a: &CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>, usize>,
b: &CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>, usize>,
) where
T: Real<T>,
for<'r> &'r T: Add<&'r T, Output = T>,
{
let c = a + b;
}

fn test2(
a: &CsMatBase<f64, usize, Vec<usize>, Vec<usize>, Vec<f64>, usize>,
b: &CsMatBase<f64, usize, Vec<usize>, Vec<usize>, Vec<f64>, usize>,
) {
let c = a + b;
}
17 changes: 14 additions & 3 deletions src/umv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use ndarray::{
ArrayView2,
};

use std::ops::Add;

use crate::{Real, Result};


Expand All @@ -26,7 +28,11 @@ use crate::{Real, Result};
/// for the given data sites.
///
#[derive(Debug)]
pub struct NdSpline<'a, T: Real<T>>
pub struct NdSpline<'a, T>
where

T: Real<T>,

{
/// The spline dimensionality
ndim: usize,
Expand All @@ -46,8 +52,9 @@ pub struct NdSpline<'a, T: Real<T>>


impl<'a, T> NdSpline<'a, T>
where
T: Real<T>
where

T: Real<T>,
{
/// Creates `NdSpline` struct from given `breaks` and `coeffs`
///
Expand Down Expand Up @@ -148,6 +155,8 @@ impl<'a, T> NdSpline<'a, T>
pub struct CubicSmoothingSpline<'a, T, D>
where
T: Real<T>,


D: Dimension
{
/// X data sites (also breaks)
Expand All @@ -173,6 +182,8 @@ pub struct CubicSmoothingSpline<'a, T, D>
impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
where
T: Real<T>,
for<'r> &'r T: Add<&'r T, Output = T>,

D: Dimension
{
/// Creates `CubicSmoothingSpline` struct from the given `X` data sites and `Y` data values
Expand Down
21 changes: 14 additions & 7 deletions src/umv/make.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ndarray::{prelude::*, concatenate, s};
use std::ops::Add;

use ndarray::{prelude::*, concatenate, s};


use crate::{
Expand All @@ -14,8 +15,9 @@ use super::{NdSpline, CubicSmoothingSpline};

impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
where
T: Real<T>,
D: Dimension
T: Real<T>,
for<'r> &'r T: Add<&'r T, Output = T>,
D: Dimension
{
pub(super) fn make_spline(&mut self) -> Result<()> {
let one = T::one();
Expand Down Expand Up @@ -102,13 +104,18 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>

// cannot multiply `&CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>>` by `T`
// the trait `Mul<T>` is not implemented for `&CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>>`

let a1 = qtwq.map(|el| s1 * *el );
let a2 = r.map(|el| *el * smooth);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last issue blocking compilation: The Mul trait is not implemented for the CsMatBase I am not sure whether it can be implemented outside the sprs crate (I tried at the bottom of trait.rs -- commented out. @espdev , any ideas?

let a1 = &qtwq * s1;
let a2 = &r * smooth;

// let a1 = &qtwq * s1;
// let a2 = &r * smooth;
drop(qtwq);
drop(r);

&a1 + &a2

&a1 + &a2
};

let b = diff(&dydx, Some(Axis(1))).t().to_owned();
Expand Down Expand Up @@ -147,7 +154,7 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
let p1 = diff(&c3, Some(Axis(0))) / &dx;
let p2 = &c3_head * three;
let p3 = diff(&yi, Some(Axis(0))) / &dx - (&c3_head * two + c3_tail) * dx;
let p4 = yi.view().slice(s![..-1 as i32, ..]);
let p4 = yi.slice(s![..-1 as i32, ..]); // was yi.view()

drop(c3);

Expand Down