Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ exclude = [".github/*", "benches/*", "notebooks/*", ".readthedocs.yaml",]

[lib]
name = "rateslib"
path = "src/lib.rs"
path = "rust/lib.rs"
#crate-type = ["rlib"]
#crate-type = ["cdylib"] # for pyO3
crate-type = ["lib"]

[[bin]]
name = "main"
path = "rust/main.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dual::{FieldOps, MathFuncs};
use crate::dual::{NumericOps, MathFuncs};
use std::{
cmp::{PartialEq, PartialOrd},
ops::{Mul, Sub},
Expand All @@ -16,7 +16,7 @@ use std::{
/// Calculate the linear interpolation between two coordinates.
pub(crate) fn linear_interp<T>(x1: f64, y1: &T, x2: f64, y2: &T, x: f64) -> T
where
for<'a> &'a T: FieldOps<T>,
for<'a> &'a T: NumericOps<T>,
T: Mul<f64, Output = T>,
{
y1 + &((y2 - y1) * ((x - x1) / (x2 - x1)))
Expand All @@ -25,7 +25,7 @@ where
/// Calculate the log-linear interpolation between two coordinates.
pub(crate) fn log_linear_interp<T>(x1: f64, y1: &T, x2: f64, y2: &T, x: f64) -> T
where
for<'a> &'a T: FieldOps<T>,
for<'a> &'a T: NumericOps<T>,
T: Mul<f64, Output = T> + MathFuncs,
{
let (y1, y2) = (y1.log(), y2.log());
Expand All @@ -36,7 +36,7 @@ where
/// Calculate the linear zero rate interpolation between two coordinates.
pub(crate) fn linear_zero_interp<T>(x0: f64, x1: f64, y1: &T, x2: f64, y2: &T, x: f64) -> T
where
for<'a> &'a T: FieldOps<T>,
for<'a> &'a T: NumericOps<T>,
T: Mul<f64, Output = T> + MathFuncs + Sub + Clone,
{
let t1: f64 = x1 - x0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/dual/dual.rs → rust/dual/dual.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::dual::dual_ops::convert::{set_order, set_order_clone};
pub use crate::dual::dual_ops::field_ops::FieldOps;
pub use crate::dual::dual_ops::numeric_ops::NumericOps;
pub use crate::dual::dual_ops::math_funcs::MathFuncs;
use indexmap::set::IndexSet;
use ndarray::{Array, Array1, Array2, Axis};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/dual/dual_ops/mod.rs → rust/dual/dual_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod add;
pub mod convert;
mod div;
mod eq;
pub mod field_ops;
pub mod numeric_ops;
mod from;
pub mod math_funcs;
mod mul;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::dual::dual::{Dual, Dual2, Number};
use std::ops::{Add, Div, Mul, Sub};

pub trait FieldOps<T>:
pub trait NumericOps<T>:
Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Sized + Clone
{
}
impl<'a, T: 'a> FieldOps<T> for &'a T where
impl<'a, T: 'a> NumericOps<T> for &'a T where
&'a T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>
{
}
impl FieldOps<Dual> for Dual {}
impl FieldOps<Dual2> for Dual2 {}
impl FieldOps<f64> for f64 {}
impl FieldOps<Number> for Number {}
impl NumericOps<Dual> for Dual {}
impl NumericOps<Dual2> for Dual2 {}
impl NumericOps<f64> for f64 {}
impl NumericOps<Number> for Number {}

#[cfg(test)]
mod tests {
Expand All @@ -22,14 +22,14 @@ mod tests {
fn test_fieldops() {
fn test_ops<T>(a: &T, b: &T) -> T
where
for<'a> &'a T: FieldOps<T>,
for<'a> &'a T: NumericOps<T>,
{
&(a + b) - a
}

fn test_ops2<T>(a: T, b: T) -> T
where
T: FieldOps<T>,
T: NumericOps<T>,
{
(a.clone() + b) - a
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 8 additions & 9 deletions src/dual/mod.rs → rust/dual/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
//!
//! # AD Architecture
//!
//! This library
//!
//! Create and use data types for calculating derivatives up to second order using automatic
//! differentiation (AD). The type of AD used in *rateslib* is forward mode, dual number based.
//!
//! A first order dual number represents a function value and a linear manifold of the
//! gradient at that point. A second order dual number represents a function value and
//! a quadratic manifold of the gradient at that point.
//! The entire *rateslib* library is built around three core numeric types: [f64],
//! [Dual] and [Dual2]. Obviously [f64] allows for traditional computation, which benefits
//! from efficient calculation leveraging BLAS, while [Dual] and [Dual2] reduce performance
//! of calculation but provide efficient calculation of first order and second order
//! derivatives, respectively. Derivatives are calculated using forward mode AD,
//! similar, but not identical, to the
//! [Julia ForwardDiff library](https://github.com/JuliaDiff/ForwardDiff.jl).
//!
//! Mathematical operations are defined to give dual numbers the ability to combine, and
//! flexibly reference different variables at any point during calculations.
Expand All @@ -22,7 +21,7 @@ pub mod linalg;
pub(crate) mod linalg_py;

pub use crate::dual::dual::{
set_order, set_order_clone, ADOrder, Dual, Dual2, FieldOps, Gradient1, Gradient2, MathFuncs,
set_order, set_order_clone, ADOrder, Dual, Dual2, NumericOps, Gradient1, Gradient2, MathFuncs,
Number, Vars, VarsRelationship,
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.