dimforge / dimforge/alga

FiniteDimVectorSpace forces every type of vectors to have the same rank

Open
#84 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
201
Forks
40
PR merge metrics
No merged PRs in 30d

Description

Recall this definition:
```rust
pub trait FiniteDimVectorSpace: VectorSpace + Index + IndexMut {
fn dimension() -> usize;
fn canonical_basis_element(i: usize) -> Self;
fn dot(&self, other: &Self) -> Self::Field;
unsafe fn component_unchecked(&self, i: usize) -> &Self::Field;
unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut Self::Field;

fn canonical_basis bool>(f: F) { ... }
}
```

Note that `FiniteDimVectorSpace::dimension` is independent of `&self`. This forces all implementors of this trait to return constant value. Therefore, `Vec` where `T: Field` is not a vector over the field `T`.

This is an awkward definition. It might make some sense for vector space of a certain dimension known at compile time, such as `Vec2` and `Vec3` in the examples. However, it prohibits implementations in general.

The `dimension` associated method in the definition of `SquareMatrix` makes much less sense in this context. Recall its definition:
```rust
pub trait SquareMatrix: Matrix + MultiplicativeMonoid {
type Vector: FiniteDimVectorSpace;
fn diagonal(&self) -> Self::Vector;
fn determinant(&self) -> Self::Field;
fn try_inverse(&self) -> Option;

fn dimension(&self) -> usize { ... }
fn transpose_mut(&mut self) { ... }
}
```
The `dimension` associated method in this case takes `&self`, but it is in fact independent of `&self` once `Self::Vector` has constant rank at compile time.

The proposed change is to allow `FiniteDimVectorSpace::dimension` to accept `&self`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.