Skip to content

Commit

Permalink
pub(crate) for the Derivative map helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cormacrelf committed May 2, 2023
1 parent 6735104 commit 47a40c3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/derivative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ where
Self::new(None)
}

pub(crate) fn map<T2, F2>(&self, mut f: impl FnMut(T) -> T2) -> Derivative<T2, F2, R, C>
where
T2: DualNum<F2>,
DefaultAllocator: Allocator<T2, R, C>,
{
let opt = self.0.as_ref().map(move |eps| eps.map(|e| f(e)));
Derivative::new(opt)
}

// A version of map that doesn't clone values before mapping. Useful for the SimdValue impl,
// which would be redundantly cloning all the lanes of each epsilon value before extracting
// just one of them.
Expand Down Expand Up @@ -73,6 +82,7 @@ where
Derivative::new(opt)
}

/// Same but bails out if the closure returns None
pub(crate) fn try_map_borrowed<T2, F2>(
&self,
mut f: impl FnMut(&T) -> Option<T2>,
Expand Down Expand Up @@ -105,15 +115,6 @@ where
.map(Derivative::some)
}

pub fn map<T2, F2>(&self, mut f: impl FnMut(T) -> T2) -> Derivative<T2, F2, R, C>
where
T2: DualNum<F2>,
DefaultAllocator: Allocator<T2, R, C>,
{
let opt = self.0.as_ref().map(move |eps| eps.map(|e| f(e)));
Derivative::new(opt)
}

pub fn derivative_generic(r: R, c: C, i: usize) -> Self {
let mut m = OMatrix::zeros_generic(r, c);
m[i] = T::one();
Expand Down

0 comments on commit 47a40c3

Please sign in to comment.