workarounds -> traits. All ICE are now compiler errors.
This commit is contained in:
parent
6e627f3378
commit
caee7eb423
|
@ -1,7 +1,7 @@
|
||||||
use std::num::{One, Zero};
|
use std::num::{One, Zero};
|
||||||
use std::rand::{Rand, Rng, RngUtil};
|
use std::rand::{Rand, Rng, RngUtil};
|
||||||
use std::cmp::ApproxEq;
|
use std::cmp::ApproxEq;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use traits::dim::Dim;
|
use traits::dim::Dim;
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use traits::rotation::Rotation;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::delta_transform::{DeltaTransform, DeltaTransformVector};
|
use traits::delta_transform::{DeltaTransform, DeltaTransformVector};
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
|
|
||||||
#[deriving(Eq, ToStr)]
|
#[deriving(Eq, ToStr)]
|
||||||
pub struct Transform<M, V>
|
pub struct Transform<M, V>
|
||||||
|
|
|
@ -5,7 +5,7 @@ use traits::dim::Dim;
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use dim1::vec1::Vec1;
|
use dim1::vec1::Vec1;
|
||||||
|
|
||||||
#[deriving(Eq, ToStr)]
|
#[deriving(Eq, ToStr)]
|
||||||
|
|
|
@ -8,7 +8,7 @@ use traits::norm::Norm;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::sub_dot::SubDot;
|
use traits::sub_dot::SubDot;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
|
|
||||||
#[deriving(Eq, Ord, ToStr)]
|
#[deriving(Eq, Ord, ToStr)]
|
||||||
pub struct Vec1<N>
|
pub struct Vec1<N>
|
||||||
|
|
|
@ -6,7 +6,7 @@ use traits::dim::Dim;
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use dim2::vec2::Vec2;
|
use dim2::vec2::Vec2;
|
||||||
|
|
||||||
#[deriving(Eq, ToStr)]
|
#[deriving(Eq, ToStr)]
|
||||||
|
|
|
@ -10,7 +10,7 @@ use traits::sub_dot::SubDot;
|
||||||
use traits::norm::Norm;
|
use traits::norm::Norm;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
|
|
||||||
#[deriving(Eq, Ord, ToStr)]
|
#[deriving(Eq, Ord, ToStr)]
|
||||||
pub struct Vec2<N>
|
pub struct Vec2<N>
|
||||||
|
|
|
@ -6,7 +6,7 @@ use traits::dim::Dim;
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use dim3::vec3::Vec3;
|
use dim3::vec3::Vec3;
|
||||||
|
|
||||||
#[deriving(Eq, ToStr)]
|
#[deriving(Eq, ToStr)]
|
||||||
|
|
|
@ -9,7 +9,7 @@ use traits::sub_dot::SubDot;
|
||||||
use traits::norm::Norm;
|
use traits::norm::Norm;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
|
|
||||||
#[deriving(Eq, Ord, ToStr)]
|
#[deriving(Eq, Ord, ToStr)]
|
||||||
pub struct Vec3<N>
|
pub struct Vec3<N>
|
||||||
|
|
|
@ -70,17 +70,9 @@ pub mod traits
|
||||||
pub mod division_ring;
|
pub mod division_ring;
|
||||||
pub mod sub_dot;
|
pub mod sub_dot;
|
||||||
pub mod flatten;
|
pub mod flatten;
|
||||||
|
|
||||||
/// This package contains everything done because the current compiler either
|
|
||||||
/// crashes or miss features.
|
|
||||||
/// Therefore, keep in mind anything in there will be inevitably removed some
|
|
||||||
/// days. So dont rely on them too much.
|
|
||||||
pub mod workarounds
|
|
||||||
{
|
|
||||||
pub mod rlmul;
|
pub mod rlmul;
|
||||||
pub mod scalar_op;
|
pub mod scalar_op;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests
|
pub mod tests
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::iterator::IteratorUtil;
|
||||||
use traits::inv::Inv;
|
use traits::inv::Inv;
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use ndim::dvec::{DVec, zero_vec_with_dim};
|
use ndim::dvec::{DVec, zero_vec_with_dim};
|
||||||
|
|
||||||
#[deriving(Eq, ToStr, Clone)]
|
#[deriving(Eq, ToStr, Clone)]
|
||||||
|
|
|
@ -9,7 +9,7 @@ use traits::dot::Dot;
|
||||||
use traits::sub_dot::SubDot;
|
use traits::sub_dot::SubDot;
|
||||||
use traits::norm::Norm;
|
use traits::norm::Norm;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
|
|
||||||
#[deriving(Eq, Ord, ToStr, Clone)]
|
#[deriving(Eq, Ord, ToStr, Clone)]
|
||||||
pub struct DVec<N>
|
pub struct DVec<N>
|
||||||
|
|
|
@ -7,7 +7,7 @@ use traits::inv::Inv;
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
use traits::transpose::Transpose;
|
use traits::transpose::Transpose;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::rlmul::{RMul, LMul};
|
use traits::rlmul::{RMul, LMul};
|
||||||
use ndim::dmat::{DMat, one_mat_with_dim, zero_mat_with_dim, is_zero_mat};
|
use ndim::dmat::{DMat, one_mat_with_dim, zero_mat_with_dim, is_zero_mat};
|
||||||
use ndim::nvec::NVec;
|
use ndim::nvec::NVec;
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,12 @@ use traits::sub_dot::SubDot;
|
||||||
use traits::norm::Norm;
|
use traits::norm::Norm;
|
||||||
use traits::translation::Translation;
|
use traits::translation::Translation;
|
||||||
use traits::flatten::Flatten;
|
use traits::flatten::Flatten;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
|
|
||||||
// D is a phantom parameter, used only as a dimensional token.
|
// D is a phantom parameter, used only as a dimensional token.
|
||||||
// Its allows use to encode the vector dimension at the type-level.
|
// Its allows use to encode the vector dimension at the type-level.
|
||||||
// It can be anything implementing the Dim trait. However, to avoid confusion,
|
// It can be anything implementing the Dim trait. However, to avoid confusion,
|
||||||
// using d0, d1, d2, d3, ..., d7 (or your own dn) are prefered.
|
// using d0, d1, d2, d3, ..., d7 (or your own dn) are prefered.
|
||||||
// FIXME: it might be possible to implement type-level integers and use them
|
|
||||||
// here?
|
|
||||||
#[deriving(Eq, Ord, ToStr)]
|
#[deriving(Eq, Ord, ToStr)]
|
||||||
pub struct NVec<D, N>
|
pub struct NVec<D, N>
|
||||||
{ at: DVec<N> }
|
{ at: DVec<N> }
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/**
|
||||||
|
* Trait of objects having a right multiplication with another element.
|
||||||
|
*/
|
||||||
|
pub trait RMul<V>
|
||||||
|
{
|
||||||
|
/// Computes self * v
|
||||||
|
fn rmul(&self, v : &V) -> V;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait of objects having a left multiplication with another element.
|
||||||
|
*/
|
||||||
|
pub trait LMul<V>
|
||||||
|
{
|
||||||
|
/// Computes v * self
|
||||||
|
fn lmul(&self, &V) -> V;
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* Trait of objects having a multiplication with a scalar.
|
||||||
|
*/
|
||||||
|
pub trait ScalarMul<N>
|
||||||
|
{
|
||||||
|
/// Gets the result of a multiplication by a scalar.
|
||||||
|
fn scalar_mul(&self, &N) -> Self;
|
||||||
|
|
||||||
|
/// In-place version of `scalar_mul`.
|
||||||
|
fn scalar_mul_inplace(&mut self, &N);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait of objects having a division with a scalar.
|
||||||
|
*/
|
||||||
|
pub trait ScalarDiv<N>
|
||||||
|
{
|
||||||
|
/// Gets the result of a division by a scalar.
|
||||||
|
fn scalar_div(&self, &N) -> Self;
|
||||||
|
|
||||||
|
/// In-place version of `scalar_div`.
|
||||||
|
fn scalar_div_inplace(&mut self, &N);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait of objects having an addition with a scalar.
|
||||||
|
*/
|
||||||
|
pub trait ScalarAdd<N>
|
||||||
|
{
|
||||||
|
/// Gets the result of an addition by a scalar.
|
||||||
|
fn scalar_add(&self, &N) -> Self;
|
||||||
|
|
||||||
|
/// In-place version of `scalar_add`.
|
||||||
|
fn scalar_add_inplace(&mut self, &N);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait of objects having a subtraction with a scalar.
|
||||||
|
*/
|
||||||
|
pub trait ScalarSub<N>
|
||||||
|
{
|
||||||
|
/// Gets the result of a subtraction by a scalar.
|
||||||
|
fn scalar_sub(&self, &N) -> Self;
|
||||||
|
|
||||||
|
/// In-place version of `scalar_sub`.
|
||||||
|
fn scalar_sub_inplace(&mut self, &N);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
use std::num::Zero;
|
use std::num::Zero;
|
||||||
use traits::division_ring::DivisionRing;
|
use traits::division_ring::DivisionRing;
|
||||||
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv};
|
use traits::scalar_op::{ScalarMul, ScalarDiv};
|
||||||
|
|
||||||
/// Trait of elements of a vector space. A vector space is an algebraic
|
/// Trait of elements of a vector space. A vector space is an algebraic
|
||||||
/// structure, the elements of which have addition, substraction, negation,
|
/// structure, the elements of which have addition, substraction, negation,
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
/**
|
|
||||||
* Trait of objects having a right multiplication with another element.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Mul<V, M> for M
|
|
||||||
* trait Mul<V2, M> for M
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait RMul<V>
|
|
||||||
{
|
|
||||||
/// Computes self * v
|
|
||||||
fn rmul(&self, v : &V) -> V;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trait of objects having a left multiplication with another element.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Mul<V, M> for M
|
|
||||||
* trait Mul<V2, M> for M
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait LMul<V>
|
|
||||||
{
|
|
||||||
/// Computes v * self
|
|
||||||
fn lmul(&self, &V) -> V;
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/**
|
|
||||||
* Trait of objects having a multiplication with a scalar.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Mul<V, N> for N
|
|
||||||
* trait Mul<V2, N> for N
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait ScalarMul<N>
|
|
||||||
{
|
|
||||||
/// Gets the result of a multiplication by a scalar.
|
|
||||||
fn scalar_mul(&self, &N) -> Self;
|
|
||||||
|
|
||||||
/// In-place version of `scalar_mul`.
|
|
||||||
fn scalar_mul_inplace(&mut self, &N);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trait of objects having a division with a scalar.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Div<V, N> for N
|
|
||||||
* trait Div<V2, N> for N
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait ScalarDiv<N>
|
|
||||||
{
|
|
||||||
/// Gets the result of a division by a scalar.
|
|
||||||
fn scalar_div(&self, &N) -> Self;
|
|
||||||
|
|
||||||
/// In-place version of `scalar_div`.
|
|
||||||
fn scalar_div_inplace(&mut self, &N);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trait of objects having an addition with a scalar.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Add<V, N> for N
|
|
||||||
* trait Add<V2, N> for N
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait ScalarAdd<N>
|
|
||||||
{
|
|
||||||
/// Gets the result of an addition by a scalar.
|
|
||||||
fn scalar_add(&self, &N) -> Self;
|
|
||||||
|
|
||||||
/// In-place version of `scalar_add`.
|
|
||||||
fn scalar_add_inplace(&mut self, &N);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trait of objects having a subtraction with a scalar.
|
|
||||||
* This is a workaround of the fact we cannot implement the same trait
|
|
||||||
* (with different type parameters) twice for the same type. The following
|
|
||||||
* exemple does not compile (end with an ICE):
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* trait Sub<V, N> for N
|
|
||||||
* trait Sub<V2, N> for N
|
|
||||||
* ~~~
|
|
||||||
*/
|
|
||||||
pub trait ScalarSub<N>
|
|
||||||
{
|
|
||||||
/// Gets the result of a subtraction by a scalar.
|
|
||||||
fn scalar_sub(&self, &N) -> Self;
|
|
||||||
|
|
||||||
/// In-place version of `scalar_sub`.
|
|
||||||
fn scalar_sub_inplace(&mut self, &N);
|
|
||||||
}
|
|
Loading…
Reference in New Issue