Skip to content

Commit

Permalink
COMPILER ICE
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKwint committed Nov 25, 2021
1 parent ae08953 commit f4cb763
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 460 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ exclude = [
]

[features]
default = ["openblas-system"]
rayon = ["ndarray/rayon", "truncnorm/rayon", "good_lp/minilp"]
lp_coincbc = ["good_lp/coin_cbc"]
lp_gurobi = ["grb"]
rayon = ["ndarray/rayon", "truncnorm/rayon"]
intel-mkl = ["ndarray-linalg/intel-mkl", "truncnorm/intel-mkl"]
openblas-system = ["ndarray/blas", "blas-src", "openblas-src", "ndarray-linalg/openblas-system", "truncnorm/openblas-system"]

Expand All @@ -25,9 +26,11 @@ crate-type = ["lib"]
[dependencies]
approx = "^0.4.0"
blas-src = { version = "0.8", features = ["openblas"], optional = true }
cfg-if = "1.0.0"
env_logger = "0.9.0"
float-cmp = "0.9.0"
good_lp = { version = "^1.2.0", features = ["coin_cbc"] }
good_lp = { version = "^1.2.0", optional = true }
grb = { version = "1.3.0", optional = true }
itertools = "^0.10.1"
log = "^0.4"
ndarray = { version = "^0.15.2" }
Expand Down
77 changes: 0 additions & 77 deletions examples/criterion.rs

This file was deleted.

3 changes: 3 additions & 0 deletions gurobi.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OutputFlag 0
CSClientLog 0
LogToConsole 0
25 changes: 12 additions & 13 deletions src/asterism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ impl<'a, T: NNVFloat> Asterism<'a, T, Ix2> {
return Some((vec![safe_sample], path_logp, total_infeasible_cdf));
}
Err((unsafe_sample, val)) => {
best_sample = Some(unsafe_sample);
best_sample_val = val;
if val < best_sample_val {
best_sample = Some(unsafe_sample);
best_sample_val = val;
}
}
};
// check feasibility of current node
Expand Down Expand Up @@ -269,16 +271,14 @@ impl<'a, T: NNVFloat> Asterism<'a, T, Ix2> {
stability_eps,
);
let unsafe_len = unsafe_sample[0].len();
let fixed_input_part: Option<Array1<T>> = {
self.constellation
.get_input_bounds()
.as_ref()
.map(|bounds| {
let fixed_bounds: Bounds1<T> = bounds.split_at(unsafe_len).1;
let fixed_array: Array1<T> = fixed_bounds.lower().to_owned();
fixed_array
})
};
let fixed_input_part: Option<Array1<T>> = self
.constellation
.get_node_input_bounds(current_node)
.map(|bounds| {
let fixed_bounds: Bounds1<T> = bounds.split_at(unsafe_len).1;
let fixed_array: Array1<T> = fixed_bounds.lower().to_owned();
fixed_array
});
let dnn_idx = self.constellation.get_node_dnn_index(current_node);
let mut best_sample = Array1::zeros(1);
let mut best_val = T::infinity();
Expand Down Expand Up @@ -340,7 +340,6 @@ impl<'a, T: NNVFloat> Asterism<'a, T, Ix2> {
rng: &mut R,
stability_eps: T,
) -> Option<(usize, T)> {
let input_bounds = self.constellation.get_input_bounds();
debug_assert!(self
.constellation
.try_get_gaussian_distribution(current_node)
Expand Down
64 changes: 47 additions & 17 deletions src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::NNVFloat;
use ndarray::concatenate;
use ndarray::iter::{Lanes, LanesMut};
use ndarray::Array2;
use ndarray::ArrayView1;
use ndarray::Axis;
use ndarray::Ix2;
use ndarray::RemoveAxis;
Expand All @@ -15,6 +16,7 @@ use ndarray::{ArrayView, ArrayViewMut, ArrayViewMut1};
use rand::distributions::Uniform;
use rand::rngs::StdRng;
use std::fmt::Display;
use std::ops::{Mul, MulAssign};

pub type Bounds1<T> = Bounds<T, Ix2>;

Expand Down Expand Up @@ -112,12 +114,29 @@ impl<T: NNVFloat, D: Dimension + ndarray::RemoveAxis> Bounds<T, D> {
}

impl<T: NNVFloat> Bounds1<T> {
pub fn new_by_dim(dim_bounds: &[ArrayView1<T>]) -> Self {
let dims: Vec<_> = dim_bounds
.into_iter()
.map(|x| x.insert_axis(Axis(0)))
.collect();
Self {
data: concatenate(Axis(0), &dims).unwrap(),
}
}

pub fn default(dim: usize) -> Self {
Self {
data: Array2::default([2, dim]),
}
}

pub fn trivial(dim: usize) -> Self {
Self::new(
Array::from_elem(dim, T::neg_infinity()).view(),
Array::from_elem(dim, T::infinity()).view(),
)
}

pub fn affine_map(&self, aff: &Affine2<T>) -> Self {
let lower = aff.apply(&self.lower());
let upper = aff.apply(&self.upper());
Expand All @@ -136,23 +155,6 @@ impl<T: NNVFloat> Bounds1<T> {
)
}

pub fn drop_idxs<I: Iterator<Item = bool>>(&self, idxs: I) -> Self {
Self {
data: concatenate(
Axis(1),
&self
.data
.columns()
.into_iter()
.zip(idxs)
.filter(|(_dim, drop)| !drop)
.map(|(dim, _drop)| dim.insert_axis(Axis(0)))
.collect::<Vec<_>>(),
)
.unwrap(),
}
}

/// # Panics
pub fn append(mut self, other: &Self) -> Self {
self.data.append(Axis(1), other.data.view()).unwrap();
Expand All @@ -162,6 +164,34 @@ impl<T: NNVFloat> Bounds1<T> {
pub fn index_mut(&mut self, index: usize) -> ArrayViewMut1<T> {
self.data.index_axis_mut(Axis(1), index)
}

pub fn get_ith_bounds(&self, index: usize) -> Self {
Bounds {
data: self
.data
.index_axis(Axis(1), index)
.to_owned()
.insert_axis(Axis(0)),
}
}
}

/// Scale by scalar
impl<T: NNVFloat, D: Dimension> Mul<T> for Bounds<T, D> {
type Output = Self;

fn mul(self, rhs: T) -> Self {
Self {
data: self.data * rhs,
}
}
}

/// Scale by scalar
impl<T: NNVFloat, D: Dimension> MulAssign<T> for Bounds<T, D> {
fn mul_assign(&mut self, rhs: T) {
self.data *= rhs;
}
}

impl<T: NNVFloat, D: Dimension + RemoveAxis> Display for Bounds<T, D> {
Expand Down
Loading

0 comments on commit f4cb763

Please sign in to comment.