Skip to content

Commit

Permalink
Expose macros for the implementation of DualNum publicly (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner authored Nov 6, 2024
1 parent f0973d9 commit 60f99af
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 114 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.10.1] - 2204-11-05
## [0.10.2] - 2024-11-06
## Changed
- Exposed macros for the implementation of the `DualNum` trait publicly. [#83](https://github.com/itt-ustutt/num-dual/pull/83)

## [0.10.1] - 2024-11-05
## Added
- Expose the inner type of a generalized (hyper) dual number in the `DualNum` trait. [#82](https://github.com/itt-ustutt/num-dual/pull/82)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "num-dual"
version = "0.10.1"
version = "0.10.2"
authors = [
"Gernot Bauer <bauer@itt.uni-stuttgart.de>",
"Philipp Rehner <prehner@ethz.ch>",
Expand Down
25 changes: 16 additions & 9 deletions src/derivatives.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[macro_export]
macro_rules! impl_derivatives {
($deriv:ident, $nderiv:expr, $struct:ident, [$($im:ident),*]$(, [$($dim:tt),*])?) => {
($deriv:ident, $nderiv:expr, $struct:ident, [$($im:ident),*]$(, [$($dim:tt),*]$(, [$($ddim:tt),*])?)?) => {
impl<T: DualNum<F>, F: DualNumFloat$($(, $dim: Dim)*)?> DualNum<F> for $struct<T, F$($(, $dim)*)?>
where
$($(DefaultAllocator: Allocator<$dim> + Allocator<U1, $dim> + Allocator<$dim, $dim>,)*
DefaultAllocator: Allocator<$($dim,)*>)?
$($(DefaultAllocator: Allocator<$dim> + Allocator<U1, $dim> + Allocator<$dim, $dim>,)*)?
$($(DefaultAllocator: Allocator<$($ddim,)*>)?)?
{
const NDERIV: usize = T::NDERIV + $nderiv;

Expand Down Expand Up @@ -303,6 +304,7 @@ macro_rules! impl_derivatives {
};
}

#[macro_export]
macro_rules! second {
(first, $($code:tt)*) => {};
(second, $($code:tt)*) => {
Expand All @@ -313,6 +315,7 @@ macro_rules! second {
};
}

#[macro_export]
macro_rules! third {
(first, $($code:tt)*) => {};
(second, $($code:tt)*) => {};
Expand All @@ -321,6 +324,7 @@ macro_rules! third {
};
}

#[macro_export]
macro_rules! chain_rule {
(first, Self::chain_rule($self:ident, $f0:expr, $f1:expr, $f2:expr, $f3:expr)) => {
Self::chain_rule($self, $f0, $f1)
Expand All @@ -333,20 +337,23 @@ macro_rules! chain_rule {
};
}

#[macro_export]
macro_rules! impl_first_derivatives {
($struct:ident, [$($im:ident),*]$(, [$($const:tt),*])?) => {
impl_derivatives!(first, 1, $struct, [$($im),*]$(, [$($const),*])?);
($struct:ident, [$($im:ident),*]$(, [$($dim:tt),*]$(, [$($ddim:tt),*])?)?) => {
impl_derivatives!(first, 1, $struct, [$($im),*]$(, [$($dim),*]$(, [$($ddim),*])?)?);
};
}

#[macro_export]
macro_rules! impl_second_derivatives {
($struct:ident, [$($im:ident),*]$(, [$($const:tt),*])?) => {
impl_derivatives!(second, 2, $struct, [$($im),*]$(, [$($const),*])?);
($struct:ident, [$($im:ident),*]$(, [$($dim:tt),*]$(, [$($ddim:tt),*])?)?) => {
impl_derivatives!(second, 2, $struct, [$($im),*]$(, [$($dim),*]$(, [$($ddim),*])?)?);
};
}

#[macro_export]
macro_rules! impl_third_derivatives {
($struct:ident, [$($im:ident),*]$(, [$($const:tt),*])?) => {
impl_derivatives!(third, 3, $struct, [$($im),*]$(, [$($const),*])?);
($struct:ident, [$($im:ident),*]$(, [$($dim:tt),*]$(, [$($ddim:tt),*])?)?) => {
impl_derivatives!(third, 3, $struct, [$($im),*]$(, [$($dim),*]$(, [$($ddim),*])?)?);
};
}
4 changes: 2 additions & 2 deletions src/hyperdual_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,5 @@ where
}
}

impl_second_derivatives!(HyperDualVec, [eps1, eps2, eps1eps2], [M, N]);
impl_dual!(HyperDualVec, [eps1, eps2, eps1eps2], [M, N]);
impl_second_derivatives!(HyperDualVec, [eps1, eps2, eps1eps2], [M, N], [M, N]);
impl_dual!(HyperDualVec, [eps1, eps2, eps1eps2], [M, N], [M, N]);
Loading

0 comments on commit 60f99af

Please sign in to comment.