dimforge / dimforge/alga

Operations on references

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

Description

I found that writing generic arithmetic with alga involves some extra clones. The reason is, that there is no way to apply operators to references. Therefore you have to pass ownership to the operator, which requires a clone, as soon as you need a value more than once.

For example, given two (large) vectors, `a: T` and `b: U`, where `T: ClosedAdd`, I would like to be able to do all of these operations:

```rust
// possible today
a + b
a += b
// not possible without adding extra trait bounds
a + &b
&a + b
&a + &b
a += &b
```

That would probably require the `ClosedAdd` trait to be extended to this

```rust
trait ClosedAdd:
Sized +
Add +
for<'a> Add<&'a Right, Output = Self> +
AddAssign +
for<'a> AddAssign<&'a Right>
where
for<'a> &'a Self: Add,
for<'a, 'b> &'a Self: Add<&'b Right, Output = Self>
{}
```

Of course, this adds extra burden on trait implementors. It is also a backwards-incompatible change, as it breaks implementations that do not fulfill the extra bounds yet. (afaik, at least nalgebra should be fine.)

I would argue, that any arithmetic type should be able to handle these cases. Happy to hear a counter-example, but I can't really think of any yet.

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.