Commit Graph

1333 Commits

Author SHA1 Message Date
Avi Weinstock
a02e485556 Add Clone to Scalar, providing a default implementation of inlined_clone. Change Scalar + Clone bounds to just Scalar. 2019-12-16 18:10:32 -05:00
Avi Weinstock
ec1c37d09f Add inlined_clone to Scalar, and relax bounds from Scalar + Copy to Scalar + Clone nearly everywhere.
The various nalgebra-lapack FooScalars are still Copy because they make use of uninitialized memory.
nalgebgra-glm Number still uses Copy because upstream `approx` requires it.
2019-12-05 17:54:17 -05:00
Sébastien Crozet
a7649e1f9f
Merge pull request #680 from aweinstock314/copy-scalar-separation
Move `Copy` constraint from the definition of `Scalar` to all its use…
2019-11-22 08:12:34 +01:00
Sébastien Crozet
0cc8650cce
Merge pull request #681 from Aaron1011/fix/more-iter-offset
Fix some out-of-bounds `offset` calls
2019-11-22 08:08:57 +01:00
Aaron Hill
46904d710b
Fix some out-of-bounds offset calls
After we yield the final element from the iterator, we don't offset
`ptr` agian, to avoid having it go out-of-bounds.

However, `inner_end` may be several elements out-of-bounds, depending on
the value of `size`. Therefore, we use `wrapping_offset` to avoid
undefined behavior.
2019-11-21 17:23:49 -05:00
Avi Weinstock
87d935267e Add Scalar + Copy bounds in nalgebra-lapack.
```bash
export RELEVANT_SOURCEFILES="$(find nalgebra-lapack -name '*.rs')"
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar,/N\1: Scalar + Copy,/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar>/N\1: Scalar + Copy>/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/\([A-Z]*Scalar\): Scalar {/\1: Scalar + Copy {/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/SVDScalar<R: DimMin<C>, C: Dim>: Scalar/SVDScalar<R: DimMin<C>, C: Dim>: Scalar + Copy/' $f; done
```
2019-11-21 17:15:18 -05:00
Avi Weinstock
fb573f726c Add Scalar + Copy bounds to code that's under feature flags.
`./ci/test.sh` now passes locally.

Refactoring done via the following sed commands:
```bash
export RELEVANT_SOURCEFILES="$(find src -name '*.rs') $(find examples -name '*.rs')"
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Arbitrary\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Serialize\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Deserialize\)/N\1: Scalar + Copy + \2/' $f; do
export RELEVANT_SOURCEFILES="$(find nalgebra-glm -name '*.rs')"
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar,/N\1: Scalar + Copy,/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar>/N\1: Scalar + Copy>/' $f; done
for f in algebra-glm/src/traits.rs; do sed -i 's/Scalar + Ring/Scalar + Copy + Ring>/' $f; done # Number trait definition
```
2019-11-21 16:45:33 -05:00
Sébastien Crozet
4e3fb80b4c
Merge pull request #662 from Aaron1011/fix/final-offset
Don't call 'offset' on a dangling pointer
2019-11-21 22:11:56 +01:00
Avi Weinstock
4d38537240 Move Copy constraint from the definition of Scalar to all its use-sites.
This should semantically be a no-op, but enables refactorings to use non-Copy scalars on a case-by-case basis.
Also, the only instance of a `One + Zero` trait bound was changed into a `Zero + One` bound to match the others.

The following sed scripts were used in the refactoring (with each clause added to reduce the error count of `cargo check`):

```bash
export RELEVANT_SOURCEFILES="$(find src -name '*.rs') $(find examples -name '*.rs')"
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar,/N: Scalar+Copy,/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + Field/N: Scalar + Copy + Field/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + Zero/N: Scalar + Copy + Zero/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + Closed/N: Scalar + Copy + Closed/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + Eq/N: Scalar + Copy + Eq/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + PartialOrd/N: Scalar + Copy + PartialOrd/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: *Scalar + Zero/N: Scalar + Copy + Zero/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + PartialEq/N: Scalar + Copy + PartialEq/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar>/N: Scalar+Copy>/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: Scalar + $bound/N: Scalar + Copy + $bound/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: *Scalar + $bound/N: Scalar + Copy + $bound/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\): *Scalar,/N\1: Scalar+Copy,/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N: *Scalar + $trait/N: Scalar + Copy + $trait/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\): *Scalar + Superset/N\1: Scalar + Copy + Superset/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\): *Scalar + \([a-zA-Z]*Eq\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \([a-zA-Z]*Eq\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(hash::\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar {/N\1: Scalar + Copy {/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Zero\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Bounded\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Lattice\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Meet\|Join\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(fmt::\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Ring\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Hash\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Send\|Sync\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/One + Zero/Zero + One/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \(Zero\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar + \($marker\)/N\1: Scalar + Copy + \2/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/N\([0-9]\?\): *Scalar>/N\1: Scalar + Copy>/' $f; done
for f in $RELEVANT_SOURCEFILES; do sed -i 's/Scalar+Copy/Scalar + Copy/' $f; done
```
2019-11-19 18:08:28 -05:00
Aaron Hill
df87769988
Switch to wrapping_offset instead of unsafe offset 2019-11-19 17:42:45 -05:00
Sébastien Crozet
d09aa50a31
Fix Vector::axpy for noncommutative cases (#648)
Fix Vector::axpy for noncommutative cases
2019-11-19 22:06:01 +01:00
Aaron Hill
8dd673d48b
Don't call 'offset' on a dangling pointer
When creating a matrix with only one zero dimension, we end up with a
matrix with a total size of zero, but a non-zero stride for elements.
While such a matrix can never actually have any elements, we need to be
careful with how we use the pointer associated with it.

Since such a pointer will always be dangling, it can never be used with `ptr.offset`,
which requires that the pointer be in-bounds or one passed the end of an
allocation. Violating this results in undefined behavior.

This commit adds in checks before the uses of `ptr.offset`. If we ever
need to offset from a pointer when our actual allocation size is zero,
we skip offsetting, and return the original pointer. This is fine
because any actual use of the original or offsetted pointer would
already be undefined behavior - we shoul never be trying to dereference
the pointer associated with a zero-size matrix.

This issue was caught be running `cargo miri test` on the project.
2019-11-17 13:53:33 -05:00
Sébastien Crozet
f5163260cb
Cholupdate (#673)
Cholupdate
2019-11-17 15:17:25 +01:00
Sébastien Crozet
9ed7dba750
Import IsaacRng from rand_isaac instead of rand. (#678)
Import IsaacRng from rand_isaac instead of rand.
2019-11-17 13:49:25 +01:00
Nestor Demeure
e848f76aa7
Update cholesky.rs
corrected typo ni doc for `xx_rank_one_update`
2019-11-17 13:40:19 +01:00
sebcrozet
04ebd9254f Add some missing spaces. 2019-11-17 13:24:00 +01:00
sebcrozet
246f72ebc0 Fix Cholesky for no-std platforms. 2019-11-17 13:10:50 +01:00
Avi Weinstock
8bce398653 Import IsaacRng from rand_isaac instead of rand.
The rand crate removed IsaacRng in the 0.5 -> 0.6 transition, so the benchmarks that use it haven't compiled since 9c37c51203.
2019-11-15 14:29:18 -05:00
Sébastien Crozet
31ef5f0ab0
Merge pull request #669 from daingun/patch-2
Use same algorithm to solve 2x2 eigenvalue problem
2019-11-05 23:02:13 +01:00
Andreas Longva
f03bd552c2 Generalize From<_> for MatrixSlice(Mut) to allow different strides 2019-11-05 22:52:49 +01:00
Andreas Longva
796db161d8 Implement From<&Matrix> for MatrixSlice 2019-11-05 22:52:49 +01:00
Jakub Konka
9276b1dc64 Add Vector::axcpy method
The added method `Vector::axcpy` generalises `Vector::gemv` to
noncommutative cases since it allows us to write for `gemv`
`self.axcpy(alpha, &col2, val, beta)`, instead the usual
`self.axpy(alpha * val, &col2, beta)`. Hence, `axcpy` preserves the
order of scalar multiplication which is important for applications where
commutativity is not guaranteed (e.g., matrices of quaternions, etc.).

This commmit also removes helpers `array_axpy` and `array_ax`, and
replaces them with `array_axcpy` and `array_axc` respectively, which
like above preserve the order of scalar multiplication.

Finally, `Vector::axpy` is preserved, however, now expressed in terms of
`Vector::axcpy` like so:

```
self.axcpy(alpha * val, &col2, beta)
```
2019-11-04 10:27:57 +01:00
Nestor Demeure
7302defe56 finished cleaning 2019-11-03 21:24:44 +01:00
Nestor Demeure
72834186d8 needs faster matrix initialization 2019-11-03 20:00:15 +01:00
Nestor Demeure
46687b7cde tests pass, needs cleanup 2019-11-03 18:48:04 +01:00
Nestor Demeure
e6467c2a3e insert does compile 2019-11-03 18:02:27 +01:00
Nestor Demeure
b4c078ca76 insert does not compile yet 2019-11-03 15:43:49 +01:00
Nestor Demeure
6d1a00218f found uneeded storagemut 2019-11-03 15:17:20 +01:00
Nestor Demeure
fd5cef6609 remove column is now working 2019-11-03 14:33:35 +01:00
Nestor Demeure
ebbfc84e96 added template for remove_column 2019-11-03 13:26:18 +01:00
Nestor Demeure
03730f594b finally got the correct type for insert column 2019-11-03 13:20:56 +01:00
Nestor Demeure
cf2286cb36 added assertion 2019-11-03 09:36:03 +01:00
Nestor Demeure
19fce3addc removed useless if 2019-11-02 19:28:46 +01:00
Nestor Demeure
d4d3f69429 code cleaned 2019-11-02 19:05:39 +01:00
Nestor Demeure
3123da5529 code cleaned 2019-11-02 19:04:07 +01:00
Nestor Demeure
3ae88127ee rank update passed tests 2019-11-02 18:27:01 +01:00
Nestor Demeure
bc7935ac24 updated comment 2019-11-02 16:49:57 +01:00
Nestor Demeure
80d2efcb5d added real constraint on sigma 2019-11-02 16:45:30 +01:00
Nestor Demeure
e49ecdc0a1 test is now correct 2019-11-02 16:36:23 +01:00
Nestor Demeure
bdccc81874 got test to compile 2019-11-02 15:56:59 +01:00
Nestor Demeure
1fe4ef956b added test for update 2019-11-02 15:11:14 +01:00
Nestor Demeure
2beb09dab2 first version of rank one update 2019-11-02 14:59:07 +01:00
daingun
97374f41b9
Merge pull request #1 from daingun/patch-1
Correct Schur decomposition for 2x2 matrices
2019-11-02 13:38:23 +01:00
Nestor Demeure
90209752e2 used Storage trait for solve
see issue 667
2019-11-02 10:58:24 +01:00
Nestor Demeure
535e9d9ebd used Storage trait for solve method
as per issue 667 https://github.com/rustsim/nalgebra/issues/667
2019-11-02 10:58:24 +01:00
Nestor Demeure
7777ec43ea Used Storage trait for solve method
See issue 667 : https://github.com/rustsim/nalgebra/issues/667
2019-11-02 10:58:24 +01:00
daingun
640b008fa5
Use same algorithm to solve 2x2 eigenvalue problem
The eigenvalue problem is solved in two different method that use different methods
to calculate the discriminant of the solution to the quadratic equation.
Use the method whose computation is considered more stable.
2019-11-01 23:27:08 +01:00
daingun
ead2360f8e Correct Schur decomposition for 2x2 matrices
Due to rounding and possible loss of precision the lower left element of the 2x2 matrix
may be different from zero.
2019-11-01 22:50:28 +01:00
daingun
c550921bcf
Correct Schur decomposition for 2x2 matrices
Due to rounding and possible loss of precision the lower left element of the 2x2 matrix
may be different from zero.
2019-11-01 22:12:59 +01:00
sebcrozet
286a37364e Release nalgebra 0.19.0. 2019-10-28 13:40:37 +01:00