Skip to content

Commit 5f83816

Browse files
avhzavhz
avhz
authored and
avhz
committed
chore: cleanup autodiff
1 parent 605db7c commit 5f83816

File tree

22 files changed

+1220
-3672
lines changed

22 files changed

+1220
-3672
lines changed

crates/RustQuant_autodiff/src/accumulate.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! - `DVector<Variable<'v>>` <- Currently not possible due to lifetimes
1818
//! - `Array<Variable<'v>, Ix2>` <- Work in progress
1919
20-
use super::variables::variable::Variable;
20+
use super::variable::Variable;
2121

2222
/// Trait to reverse accumulate the gradient for different types.
2323
pub trait Accumulate<OUT> {
@@ -50,18 +50,3 @@ impl Accumulate<Vec<f64>> for Variable<'_> {
5050
adjoints
5151
}
5252
}
53-
54-
// impl<'v> Accumulate<Array2<Vec<f64>>> for VariableArray<'v> {
55-
// /// Function to reverse accumulate the gradient
56-
// /// for an `Array2<Variable<'v>>`.
57-
// #[inline]
58-
// fn accumulate(&self) -> Array2<Vec<f64>> {
59-
// let mut adjoints = Array2::from_elem(self.data.dim(), Vec::new());
60-
61-
// for ((row, col), variable) in self.data.indexed_iter() {
62-
// adjoints[(row, col)] = variable.accumulate();
63-
// }
64-
65-
// adjoints
66-
// }
67-
// }

crates/RustQuant_autodiff/src/gradient.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// IMPORTS
1515
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1616

17-
use crate::variables::variable::Variable;
17+
use crate::variable::Variable;
1818

1919
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020
// GRADIENT TRAIT AND IMPLEMENTATIONS

crates/RustQuant_autodiff/src/graph.rs

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// IMPORTS
1818
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1919

20-
use crate::{variables::variable::Variable, Arity, Vertex};
20+
use crate::{variable::Variable, Arity, Vertex};
2121
use std::cell::RefCell;
2222

2323
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -185,70 +185,3 @@ impl Graph {
185185
len
186186
}
187187
}
188-
189-
// /// Nullary operator pushback.
190-
// ///
191-
// /// The vertex pushed to the graph is the result of a **nullary** operation.
192-
// /// e.g. `x.neg()` ($-x$)
193-
// /// Thus no partials and only the current index are added to the new vertex.
194-
// ///
195-
// /// 1. Constructs the vertex,
196-
// /// 2. Pushes the new vertex onto the graph,
197-
// /// 3. Returns the index of the new vertex.
198-
// #[inline]
199-
// pub fn push_nullary(&self) -> usize {
200-
// let mut vertices = self.vertices.borrow_mut();
201-
// let len = vertices.len();
202-
// vertices.push(Vertex {
203-
// partials: [0.0, 0.0],
204-
// parents: [len, len],
205-
// });
206-
// len
207-
// }
208-
209-
// /// Unary operator pushback.
210-
// ///
211-
// /// The vertex pushed to the graph is the result of a **unary** operation.
212-
// /// e.g. `x.sin()` ($sin(x)$)
213-
// /// Thus one partial and one parent are added to the new vertex.
214-
// ///
215-
// /// 1. Constructs the vertex,
216-
// /// 2. Pushes the new vertex onto the graph,
217-
// /// 3. Returns the index of the new vertex.
218-
// #[inline]
219-
// pub fn push_unary(&self, parent0: usize, partial0: f64) -> usize {
220-
// let mut vertices = self.vertices.borrow_mut();
221-
// let len = vertices.len();
222-
// vertices.push(Vertex {
223-
// partials: [partial0, 0.0],
224-
// parents: [parent0, len],
225-
// });
226-
// len
227-
// }
228-
229-
// /// Binary operator pushback.
230-
// ///
231-
// /// The vertex pushed to the graph is the result of a **binary** operation.
232-
// /// e.g. `x + y`
233-
// /// Thus two partials and two parents are added to the new vertex.
234-
// ///
235-
// /// 1. Constructs the vertex,
236-
// /// 2. Pushes the new vertex onto the graph,
237-
// /// 3. Returns the index of the new vertex.
238-
// #[inline]
239-
// pub fn push_binary(
240-
// &self,
241-
// parent0: usize,
242-
// partial0: f64,
243-
// parent1: usize,
244-
// partial1: f64,
245-
// ) -> usize {
246-
// let mut vertices = self.vertices.borrow_mut();
247-
// let len = vertices.len();
248-
// vertices.push(Vertex {
249-
// partials: [partial0, partial1],
250-
// parents: [parent0, parent1],
251-
// });
252-
// len
253-
// }
254-
// }

crates/RustQuant_autodiff/src/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! language. At the moment, I'm simply trying to make a function that outputs
1616
//! `dot` code for a given graph.
1717
18-
use crate::{variables::variable::Variable, Graph};
18+
use crate::{variable::Variable, Graph};
1919

2020
// impl std::fmt::Display for Graph {
2121
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/RustQuant_autodiff/src/lib.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! - i.e. for functions $f:\mathbb{R}^n \rightarrow \mathbb{R}^m$, where $m \gg n$
2222
//!
2323
//! ```
24-
//! use RustQuant::autodiff::*;
24+
//! # use RustQuant_autodiff::*;
2525
//!
2626
//! // Create a new Graph to store the computations.
2727
//! let g = Graph::new();
@@ -91,44 +91,6 @@ pub use vertex::*;
9191
pub mod overload;
9292
pub use overload::*;
9393

94-
// /// Operator/function overloading.
95-
// /// This module contains the overloaded operators and primitive functions.
96-
// /// In Griewank and Walther - Evaluating Derivatives, they refer to this
97-
// /// as the "elemental library".
98-
// /// Operations such as `+` and `*` are redefined, along with primitive
99-
// /// functions such as `sin`, `exp`, and `log`.
100-
// /// Each overload has an associated test to ensure functionality.
101-
// pub mod overloading {
102-
// /// Overload the standard addition operator (`+`).
103-
// pub mod add;
104-
// /// Overload the standard division operator (`/`).
105-
// pub mod div;
106-
// /// Overload the standard f64 type methods.
107-
// pub mod f64;
108-
// /// Overload the iterator traits.
109-
// pub mod iter;
110-
// /// Overload the standard logarithm function (`log`).
111-
// pub mod log;
112-
// /// Overload the standard min/max functions (`min` and `max`).
113-
// pub mod minmax;
114-
// /// Overload the standard multiplication operator (`*`).
115-
// pub mod mul;
116-
// /// Overload the power functions.
117-
// pub mod pow;
118-
// /// Overloading functions from `statrs`.
119-
// pub mod statrs;
120-
// /// Overload the standard subtraction operator (`-`).
121-
// pub mod sub;
122-
// }
123-
// pub use overloading::{log::*, minmax::*, pow::*};
124-
12594
/// `Variable`s for `autodiff`.
126-
pub mod variables {
127-
// /// Implements `Variable`s for `nalgebra`.
128-
// pub mod nalgebra;
129-
// /// Implements `Variable`s for `ndarray`.
130-
// pub mod ndarray;
131-
/// Base trait for all `Variable`s.
132-
pub mod variable;
133-
}
134-
pub use variables::variable::*;
95+
pub mod variable;
96+
pub use variable::*;

0 commit comments

Comments
 (0)