Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer committed Oct 17, 2024
1 parent ba646ac commit e0287cb
Show file tree
Hide file tree
Showing 10 changed files with 1,177 additions and 2,140 deletions.
3 changes: 2 additions & 1 deletion src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Named vectors were added and can e.g. be constructed via `[a = 1, b = 2]`
* The `is_null()` primitive was added
* Setting a list value to `null` actually sets it to `null` and does not remove it.
* Stricter recycling rule are enforced (@98):
* Stricter recycling rules are enforced (@98):
Vectorized operations on two vectors `v1` and `v2` now requires either of:
* One of the vectors has length 1 and the other vector's length is not zero.
* The vectors have the same length.
Expand All @@ -20,6 +20,7 @@
This included a considerable refactor.
* Iterating over references of a `Rep<T>` was made much simpler and new methods were added
and unused ones removed.
* The `RepType` struct that was introduced in 0.4.0 was removed again.

## Notable Bugs Addressed

Expand Down
2 changes: 1 addition & 1 deletion src/callable/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait Callable: CallableFormals {

for (i, (maybe_name, value)) in args.pairs_ref().iter().enumerate() {
if let Character::Some(name) = maybe_name {
if let Some((Some(_), _)) = formals.remove_named(name) {
if let Some((Some(_), _)) = formals.remove_named(&name) {
matched_args.push_named(Character::Some(name.clone()), value.clone());
continue;
}
Expand Down
1 change: 0 additions & 1 deletion src/callable/primitive/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ impl Callable for PrimitiveC {
};

if let Some(names) = names {
println!("setting names");
Ok(Obj::Vector(v.set_names(names.into())))
} else {
Ok(Obj::Vector(v))
Expand Down
28 changes: 14 additions & 14 deletions src/callable/primitive/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::error::*;
use crate::formals;
use crate::internal_err;
use crate::lang::*;
use crate::object::reptype::RepType;
use crate::object::rep::Rep;
use crate::object::*;

/// Calculate a Sum of Elements
Expand Down Expand Up @@ -40,7 +40,7 @@ impl Callable for PrimitiveSum {
let (_, ellipsis) = self.match_arg_exprs(args, stack)?;

if ellipsis.is_empty() {
return EvalResult::Ok(Obj::Vector(Vector::from(RepType::from(vec![0.0]))));
return EvalResult::Ok(Obj::Vector(Vector::from(Rep::from(vec![0.0]))));
}

let objects: Vec<Obj> = force_promises(ellipsis, stack)?
Expand Down Expand Up @@ -78,8 +78,8 @@ impl Callable for PrimitiveSum {
for x in repr.inner().borrow().iter() {
match *x {
OptionNA::NA => {
let rep: RepType<OptionNA<f64>> =
RepType::from(vec![OptionNA::NA]);
let rep: Rep<OptionNA<f64>> =
Rep::from(vec![OptionNA::NA]);
return EvalResult::Ok(Obj::Vector(Vector::from(rep)));
}
OptionNA::Some(x) => sum += x as i32 as f64,
Expand All @@ -90,8 +90,8 @@ impl Callable for PrimitiveSum {
for x in repr.inner().borrow().iter() {
match *x {
OptionNA::NA => {
let rep: RepType<OptionNA<f64>> =
RepType::from(vec![OptionNA::NA]);
let rep: Rep<OptionNA<f64>> =
Rep::from(vec![OptionNA::NA]);
return EvalResult::Ok(Obj::Vector(Vector::from(rep)));
}
OptionNA::Some(x) => sum += x as f64,
Expand All @@ -102,8 +102,8 @@ impl Callable for PrimitiveSum {
for x in repr.inner().borrow().iter() {
match *x {
OptionNA::NA => {
let rep: RepType<OptionNA<f64>> =
RepType::from(vec![OptionNA::NA]);
let rep: Rep<OptionNA<f64>> =
Rep::from(vec![OptionNA::NA]);
return EvalResult::Ok(Obj::Vector(Vector::from(rep)));
}
OptionNA::Some(x) => sum += x,
Expand All @@ -116,7 +116,7 @@ impl Callable for PrimitiveSum {
_ => return internal_err!(),
}
}
EvalResult::Ok(Obj::Vector(Vector::from(RepType::from(vec![sum]))))
EvalResult::Ok(Obj::Vector(Vector::from(Rep::from(vec![sum]))))
} else {
let mut sum: i32 = 0;

Expand All @@ -128,8 +128,8 @@ impl Callable for PrimitiveSum {
for x in repr.inner().borrow().iter() {
match *x {
OptionNA::NA => {
let rep: RepType<OptionNA<i32>> =
RepType::from(vec![OptionNA::NA]);
let rep: Rep<OptionNA<i32>> =
Rep::from(vec![OptionNA::NA]);
return EvalResult::Ok(Obj::Vector(Vector::from(rep)));
}
OptionNA::Some(x) => sum += x as i32,
Expand All @@ -140,8 +140,8 @@ impl Callable for PrimitiveSum {
for x in repr.inner().borrow().iter() {
match *x {
OptionNA::NA => {
let rep: RepType<OptionNA<i32>> =
RepType::from(vec![OptionNA::NA]);
let rep: Rep<OptionNA<i32>> =
Rep::from(vec![OptionNA::NA]);
return EvalResult::Ok(Obj::Vector(Vector::from(rep)));
}
OptionNA::Some(x) => sum += x,
Expand All @@ -154,7 +154,7 @@ impl Callable for PrimitiveSum {
_ => return internal_err!(),
}
}
EvalResult::Ok(Obj::Vector(Vector::from(RepType::from(vec![sum]))))
EvalResult::Ok(Obj::Vector(Vector::from(Rep::from(vec![sum]))))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/object/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::object::reptype::RepType;
use crate::object::rep::Rep;
use crate::object::Obj;

pub type List = RepType<Obj>;
pub type List = Rep<Obj>;

#[cfg(test)]
mod tests {
Expand Down
59 changes: 17 additions & 42 deletions src/object/vector/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use crate::object::CowObj;
use crate::object::Obj;

use super::coercion::CoercibleInto;
use super::rep::IterableValues;
use super::rep::Rep;
use super::reptype::IterableValues;
use super::reptype::RepType;
use super::subset::Subset;
use super::types::*;

Expand Down Expand Up @@ -54,10 +53,10 @@ impl<T> OptionNA<T> {

#[derive(Debug, PartialEq)]
pub enum Vector {
Double(RepType<Double>),
Integer(RepType<Integer>),
Logical(RepType<Logical>),
Character(RepType<Character>),
Double(Rep<Double>),
Integer(Rep<Integer>),
Logical(Rep<Logical>),
Character(Rep<Character>),
// Complex(Complex),
// Raw(Raw),
}
Expand Down Expand Up @@ -96,16 +95,16 @@ impl Vector {
match self {
Double(x) => x
.set_subset(subset, value.try_into()?)
.map(|x| Double(RepType::from(vec![x]))),
.map(|x| Double(Rep::from(vec![x]))),
Integer(x) => x
.set_subset(subset, value.try_into()?)
.map(|x| Integer(RepType::from(vec![x]))),
.map(|x| Integer(Rep::from(vec![x]))),
Character(x) => x
.set_subset(subset, value.try_into()?)
.map(|x| Character(RepType::from(vec![x]))),
.map(|x| Character(Rep::from(vec![x]))),
Logical(x) => x
.set_subset(subset, value.try_into()?)
.map(|x| Logical(RepType::from(vec![x]))),
.map(|x| Logical(Rep::from(vec![x]))),
}
}

Expand Down Expand Up @@ -324,54 +323,30 @@ impl From<CowObj<Vec<Character>>> for Vector {
}
}

impl From<RepType<Double>> for Vector {
fn from(x: RepType<Double>) -> Self {
impl From<Rep<Double>> for Vector {
fn from(x: Rep<Double>) -> Self {
Vector::Double(x.into())
}
}

impl From<RepType<Integer>> for Vector {
fn from(x: RepType<Integer>) -> Self {
impl From<Rep<Integer>> for Vector {
fn from(x: Rep<Integer>) -> Self {
Vector::Integer(x.into())
}
}

impl From<RepType<Logical>> for Vector {
fn from(x: RepType<Logical>) -> Self {
impl From<Rep<Logical>> for Vector {
fn from(x: Rep<Logical>) -> Self {
Vector::Logical(x.into())
}
}

impl From<RepType<Character>> for Vector {
fn from(x: RepType<Character>) -> Self {
impl From<Rep<Character>> for Vector {
fn from(x: Rep<Character>) -> Self {
Vector::Character(x.into())
}
}

// impl From<RepType<Double>> for Vector {
// fn from(x: Rep<Double>) -> Self {
// Vector::Double(x)
// }
// }

// impl From<Rep<Integer>> for Vector {
// fn from(x: Rep<Integer>) -> Self {
// Vector::Integer(x)
// }
// }

// impl From<Rep<Logical>> for Vector {
// fn from(x: Rep<Logical>) -> Self {
// Vector::Logical(x)
// }
// }

// impl From<Rep<Character>> for Vector {
// fn from(x: Rep<Character>) -> Self {
// Vector::Character(x)
// }
// }

impl From<Vec<f64>> for Vector {
fn from(x: Vec<f64>) -> Self {
Vector::Double(x.into())
Expand Down
1 change: 0 additions & 1 deletion src/object/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pub mod coercion;
pub mod iterators;
pub mod rep;
pub mod reptype;
pub mod types;

mod subsets;
Expand Down
Loading

0 comments on commit e0287cb

Please sign in to comment.