Skip to content

Commit

Permalink
refactor!: completely overhaul the domain type
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Nov 12, 2023
1 parent 7e72ec7 commit 606da4f
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 312 deletions.
4 changes: 2 additions & 2 deletions examples/rosenbrock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gomez::nalgebra as na;
use gomez::prelude::*;
use gomez::solver::TrustRegion;
use na::{Dim, DimName, IsContiguous};
use na::{DimName, IsContiguous};

// https://en.wikipedia.org/wiki/Rosenbrock_function
struct Rosenbrock {
Expand Down Expand Up @@ -37,7 +37,7 @@ impl System for Rosenbrock {

fn main() -> Result<(), String> {
let f = Rosenbrock { a: 1.0, b: 1.0 };
let dom = Domain::with_dim(f.dim().value());
let dom = f.domain();
let mut solver = TrustRegion::new(&f, &dom);

// Initial guess.
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ where
Sx: StorageMut<F::Scalar, F::Dim> + IsContiguous,
Sfx: StorageMut<F::Scalar, F::Dim>,
{
let scale_iter = dom.vars().iter().map(|var| var.scale());
let scale = OVector::from_iterator_generic(f.dim(), U1::name(), scale_iter);
let scale = dom
.scale()
.map(|scale| OVector::from_iterator_generic(f.dim(), U1::name(), scale.iter().copied()))
.unwrap_or_else(|| OVector::from_element_generic(f.dim(), U1::name(), convert(1.0)));

// Compute F'(x) in the initial point.
f.eval(x, fx)?;
Expand Down
4 changes: 2 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! traits, optionally specifying the [domain](Domain).
//!
//! Algorithms *developers* are interested in implementing the [`Solver`] trait
//! (or possibly the [`Optimizer`] trait too) and using extension traits (e.g.,
//! [`VectorDomainExt`]) as well as tools in [derivatives](crate::derivatives).
//! (or possibly the [`Optimizer`] trait too) as well as tools in
//! [derivatives](crate::derivatives).
mod base;
mod domain;
Expand Down
2 changes: 1 addition & 1 deletion src/core/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait Problem {
/// Get the domain (bound constraints) of the system. If not overridden, the
/// system is unconstrained.
fn domain(&self) -> Domain<Self::Scalar> {
Domain::with_dim(self.dim().value())
Domain::unconstrained(self.dim().value())
}
}

Expand Down
Loading

0 comments on commit 606da4f

Please sign in to comment.