Skip to content

Commit

Permalink
Revert "Transpose functions (#86)"
Browse files Browse the repository at this point in the history
This reverts commit 1ee11a9.
  • Loading branch information
samestep authored Sep 11, 2023
1 parent 1ee11a9 commit d4a7216
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 1,155 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 13 additions & 33 deletions crates/interp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Val {
Bool(bool),
F64(Cell<f64>),
Fin(usize),
Ref(Rc<Val>, Option<usize>),
Ref(Rc<Val>),
Array(Vals), // assume all indices are `Fin`
Tuple(Vals),
}
Expand Down Expand Up @@ -50,35 +50,9 @@ impl Val {
}
}

fn fin(&self) -> usize {
match self {
&Val::Fin(i) => i,
_ => unreachable!(),
}
}

fn get(&self, i: usize) -> &Self {
match self {
Val::Array(x) => &x[i],
Val::Tuple(x) => &x[i],
_ => unreachable!(),
}
}

fn slice(&self, i: usize) -> Self {
match self {
Val::Ref(x, None) => Val::Ref(Rc::clone(x), Some(i)),
Val::Ref(x, Some(j)) => Val::Ref(Rc::new(x.get(*j).clone()), Some(i)),
_ => unreachable!(),
}
}

fn inner(&self) -> &Self {
match self {
Val::Ref(x, i) => match i {
None => x.as_ref(),
&Some(j) => x.get(j),
},
Val::Ref(x) => x.as_ref(),
_ => unreachable!(),
}
}
Expand All @@ -90,7 +64,7 @@ impl Val {
&Self::Bool(x) => Self::Bool(x),
Self::F64(_) => Self::F64(Cell::new(0.)),
&Self::Fin(x) => Self::Fin(x),
Self::Ref(..) => unreachable!(),
Self::Ref(_) => unreachable!(),
Self::Array(x) => Self::Array(collect_vals(x.iter().map(|x| x.zero()))),
Self::Tuple(x) => Self::Tuple(collect_vals(x.iter().map(|x| x.zero()))),
}
Expand Down Expand Up @@ -218,8 +192,14 @@ impl<'a, 'b, O: Opaque, T: Refs<'a, Opaque = O>> Interpreter<'a, 'b, O, T> {
_ => unreachable!(),
},

&Expr::Slice { array, index } => self.get(array).slice(self.get(index).fin()),
&Expr::Field { tuple, member } => self.get(tuple).slice(member.member()),
&Expr::Slice { array, index } => match (self.get(array).inner(), self.get(index)) {
(Val::Array(v), &Val::Fin(i)) => v[i].clone(),
_ => unreachable!(),
},
&Expr::Field { tuple, member } => match self.get(tuple).inner() {
Val::Tuple(x) => x[member.member()].clone(),
_ => unreachable!(),
},

&Expr::Unary { op, arg } => {
let x = self.get(arg);
Expand Down Expand Up @@ -277,8 +257,8 @@ impl<'a, 'b, O: Opaque, T: Refs<'a, Opaque = O>> Interpreter<'a, 'b, O, T> {
))
}

&Expr::Read { var } => Val::Ref(Rc::new(self.get(var).clone()), None),
&Expr::Accum { shape } => Val::Ref(Rc::new(self.get(shape).zero()), None),
&Expr::Read { var } => Val::Ref(Rc::new(self.get(var).clone())),
&Expr::Accum { shape } => Val::Ref(Rc::new(self.get(shape).zero())),

&Expr::Ask { var } => self.get(var).inner().clone(),
&Expr::Add { accum, addend } => {
Expand Down
8 changes: 0 additions & 8 deletions crates/transpose/Cargo.toml

This file was deleted.

Loading

0 comments on commit d4a7216

Please sign in to comment.