|
1 | | -use super::Quantity; |
| 1 | +use super::{Diff, Quantity}; |
2 | 2 | use nalgebra::{DefaultAllocator, Dim, OMatrix, OVector, U1, allocator::Allocator}; |
3 | 3 | use num_dual::{ |
4 | 4 | Dual, Dual2, Dual2Vec, Dual3, DualNum, DualStruct, DualVec, Gradients, HyperDual, HyperDualVec, |
5 | 5 | HyperHyperDual, Real, |
6 | 6 | }; |
7 | 7 | use std::ops::Sub; |
8 | | -use typenum::Diff; |
9 | 8 |
|
10 | 9 | impl<D, F, T: DualStruct<D, F>, U> DualStruct<D, F> for Quantity<T, U> { |
11 | 10 | type Real = Quantity<T::Real, U>; |
@@ -338,32 +337,10 @@ where |
338 | 337 | #[cfg(test)] |
339 | 338 | mod test_num_dual { |
340 | 339 | use super::*; |
341 | | - use crate::{Area, Length, METER, Temperature, Volume}; |
| 340 | + use crate::{Area, Length, METER, Volume}; |
342 | 341 | use approx::assert_relative_eq; |
343 | 342 | use nalgebra::{SMatrix, SVector, vector}; |
344 | 343 | use num_dual::{Dual64, ImplicitDerivative, ImplicitFunction}; |
345 | | - use typenum::{P2, P3}; |
346 | | - |
347 | | - struct MyArgs<D> { |
348 | | - temperature: Temperature<D>, |
349 | | - } |
350 | | - |
351 | | - impl<D: DualNum<f64> + Copy> DualStruct<D, f64> for MyArgs<D> { |
352 | | - type Real = MyArgs<f64>; |
353 | | - type Inner = MyArgs<D::Inner>; |
354 | | - |
355 | | - fn re(&self) -> Self::Real { |
356 | | - MyArgs { |
357 | | - temperature: self.temperature.re(), |
358 | | - } |
359 | | - } |
360 | | - |
361 | | - fn from_inner(inner: &Self::Inner) -> Self { |
362 | | - MyArgs { |
363 | | - temperature: Temperature::from_inner(&inner.temperature), |
364 | | - } |
365 | | - } |
366 | | - } |
367 | 344 |
|
368 | 345 | struct AreaImplicit; |
369 | 346 | impl ImplicitFunction<f64> for AreaImplicit { |
@@ -403,27 +380,27 @@ mod test_num_dual { |
403 | 380 | fn test_derivative() { |
404 | 381 | let (v, dv) = first_derivative(volume, 5.0 * METER); |
405 | 382 | println!("{v}\t{dv:3}"); |
406 | | - assert_eq!(v, 125.0 * METER.powi::<P3>()); |
407 | | - assert_eq!(dv, 75.0 * METER.powi::<P2>()); |
| 383 | + assert_eq!(v, 125.0 * METER.powi::<3>()); |
| 384 | + assert_eq!(dv, 75.0 * METER.powi::<2>()); |
408 | 385 |
|
409 | 386 | let (v, dv, d2v) = second_derivative(volume, 5.0 * METER); |
410 | 387 | println!("{v}\t{dv:3}\t\t{d2v}"); |
411 | | - assert_eq!(v, 125.0 * METER.powi::<P3>(),); |
412 | | - assert_eq!(dv, 75.0 * METER.powi::<P2>(),); |
| 388 | + assert_eq!(v, 125.0 * METER.powi::<3>(),); |
| 389 | + assert_eq!(dv, 75.0 * METER.powi::<2>(),); |
413 | 390 | assert_eq!(d2v, 30.0 * METER); |
414 | 391 |
|
415 | 392 | let (v, dv_dx, dv_dh, d2v) = |
416 | 393 | second_partial_derivative(volume2, (5.0 * METER, 20.0 * METER)); |
417 | 394 | println!("{v}\t{dv_dx:3}\t{dv_dh:3}\t{d2v}"); |
418 | | - assert_eq!(v, 500.0 * METER.powi::<P3>(),); |
419 | | - assert_eq!(dv_dx, 200.0 * METER.powi::<P2>(),); |
420 | | - assert_eq!(dv_dh, 25.0 * METER.powi::<P2>(),); |
| 395 | + assert_eq!(v, 500.0 * METER.powi::<3>(),); |
| 396 | + assert_eq!(dv_dx, 200.0 * METER.powi::<2>(),); |
| 397 | + assert_eq!(dv_dh, 25.0 * METER.powi::<2>(),); |
421 | 398 | assert_eq!(d2v, 10.0 * METER); |
422 | 399 |
|
423 | 400 | let (v, dv, d2v, d3v) = third_derivative(volume, 5.0 * METER); |
424 | 401 | println!("{v}\t{dv:3}\t\t{d2v}\t{d3v}"); |
425 | | - assert_eq!(v, 125.0 * METER.powi::<P3>(),); |
426 | | - assert_eq!(dv, 75.0 * METER.powi::<P2>(),); |
| 402 | + assert_eq!(v, 125.0 * METER.powi::<3>(),); |
| 403 | + assert_eq!(dv, 75.0 * METER.powi::<2>(),); |
427 | 404 | assert_eq!(d2v, 30.0 * METER); |
428 | 405 | assert_eq!(d3v.into_value(), 6.0); |
429 | 406 | } |
|
0 commit comments