Skip to content

Commit e97f3a7

Browse files
authored
Expose inner type in DualNum trait (#82)
1 parent c79b42d commit e97f3a7

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.10.1] - 2204-11-05
10+
## Added
11+
- Expose the inner type of a generalized (hyper) dual number in the `DualNum` trait. [#81](https://github.com/itt-ustutt/num-dual/pull/81)
12+
913
## [0.10.0] - 2024-10-22
1014
### Packaging
1115
- Updated `nalgebra` dependency to 0.33. [#75](https://github.com/itt-ustutt/num-dual/pull/75)

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "num-dual"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
authors = [
55
"Gernot Bauer <[email protected]>",
66
"Philipp Rehner <[email protected]>",

src/derivatives.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ macro_rules! impl_derivatives {
77
{
88
const NDERIV: usize = T::NDERIV + $nderiv;
99

10+
type Inner = T;
11+
12+
#[inline]
13+
fn from_inner(inner: Self::Inner) -> Self {
14+
Self::from_re(inner)
15+
}
16+
1017
#[inline]
1118
fn re(&self) -> F {
1219
self.re.re()

src/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,16 @@ pub trait DualNum<F>:
117117
/// Highest derivative that can be calculated with this struct
118118
const NDERIV: usize;
119119

120+
/// Type of the elements of this generalized (hyper) dual number
121+
type Inner;
122+
123+
/// Construct a new generalized (hyper) dual number from its real part
124+
fn from_inner(inner: Self::Inner) -> Self;
125+
120126
/// Real part (0th derivative) of the number
121127
fn re(&self) -> F;
122128

123-
/// Reciprocal (inverse) of a number `1/x`.
129+
/// Reciprocal (inverse) of a number `1/x`
124130
fn recip(&self) -> Self;
125131

126132
/// Power with integer exponent `x^n`
@@ -243,6 +249,12 @@ macro_rules! impl_dual_num_float {
243249
impl DualNum<$float> for $float {
244250
const NDERIV: usize = 0;
245251

252+
type Inner = $float;
253+
254+
fn from_inner(inner: Self::Inner) -> Self {
255+
inner
256+
}
257+
246258
fn re(&self) -> $float {
247259
*self
248260
}

0 commit comments

Comments
 (0)