Commit Graph

2767 Commits

Author SHA1 Message Date
Andreas Borgen Longva eb228faa2b
Improved stack! implementation, tests (#1375)
* Add macro for concatenating matrices

* Replace DimUnify with DimEq::representative

* Add some simple cat macro output generation tests

* Fix formatting in cat macro code

* Add random prefix to cat macro output

* Add simple quote_spanned for cat macro

* Use `generic_view_mut` in cat macro

* Fix clippy lints in cat macro

* Clean up documentation for cat macro

* Remove identity literal from cat macro

* Allow references in input to cat macro

* Rename cat macro to stack

* Add more stack macro tests

* Add comment to explain reason for prefix in stack! macro

* Refactor matrix!, stack! macros into separate modules

* Take all blocks by reference in stack! macro

* Make empty stack![] invocation well-defined

* Fix stack! macro incorrect reference to data

* More extensive tests for stack! macro

* Move nalgebra-macros tests to nalgebra tests

By testing matrix!, stack! macros etc. in nalgebra, we ensure that
these macros are used in the same way that users will be using them.

* Fix stack! code generation tests

* Add back nalgebra as dev-dependency of nalgebra-macros

* Fix accidental wrong matrix! macro references in docs

* Rewrite stack! documentation for clarity

* Formatting

* Skip formatting of macro, rustfmt messes it up

* Rewrite stack! impl for improved clarity, Span behavior

This improves error messages upon dimension mismatch, among other
things. I've also tried to make the implementation easier to understand,
adding some comments to help the reader understand the individual steps.

* Use SameNumberOfRows/Columns instead of DimEq in stack! macro

This gives more accurate compiler errors if matrix dimensions
are mismatched.

* Check that stack! panics at runtime for basic dimension mismatch

* Add suggested edge cases from initial PR to tests

* stack! impl: use fixed prefix everywhere

This ensures that the expected generated code in tests
is the actual generated code when used in the wild.

* nalgebra-macros: Remove clippy pedantic, fix clippy complaints

pedantic seems to be mostly intent on wasting the programmer's time

* Add stack! sanity tests for built-ins and Complex

* Fix formatting in test

* Improve readability of format_ident! calls in stack! impl

* fix trybuild tests

* chore: run tests with a specific rust version

* More trybuild fixes

---------

Co-authored-by: Birk Tjelmeland <git@birktj.no>
Co-authored-by: Sébastien Crozet <sebcrozet@dimforge.com>
2024-06-23 11:29:28 +02:00
Christopher Durham 49906a35be
Fix glm::is_null epsilon test (#1350)
The existing implementation compares each component to zero with
an epsilon; effectively `glm::all(glm::is_comp_null(v, epsilon))`.
This probably isn't the desired semantics when calling `glm::is_null`;
rather, we want to determine if the magnitude of the vector is within
`epsilon` units of zero. It's the question of circle versus square.

This behavior matches that of OpenGL Mathematics.
2024-06-23 11:09:52 +02:00
Sébastien Crozet 292abfbaa0
chore: update to simba 0.9 (#1415) 2024-06-22 19:06:20 +02:00
Bruce Mitchener f812694959
deps: Update to `itertools` 0.13 (#1398) 2024-06-22 18:50:08 +02:00
Bruce Mitchener 9712aebd1f
Support conversion for glam 0.28 (#1409) 2024-06-22 18:49:46 +02:00
Yotam Ofek 5cb9dcbda1
Update syn to `2.0` (#1342) 2024-06-22 18:43:32 +02:00
Junfeng Liu d1edb4fd7b Fix document of Rotation's transpose and inverse methods 2024-06-18 11:19:35 -07:00
Markus Mayer 42a9dbeb54 Fix typo in ArrayStorage documentation comment
Signed-off-by: Markus Mayer <widemeadows@gmail.com>
2024-06-17 12:27:10 -07:00
Sébastien Crozet c23807ac5d
feat: use GAT to remove the scalar type T from the Allocator trait (#1397) 2024-06-12 11:16:06 +02:00
Bruce Mitchener 28e993a4f5
Support conversion for glam 0.27 (#1390) 2024-06-12 10:58:39 +02:00
Andreas Borgen Longva afc03cc403
Merge pull request #1384 from jnyfah/dev
Inverting a 4x4 matrix with `try_inverse_mut` doesn't leave `self` unchanged if the inversion fails.
2024-05-05 12:04:49 +02:00
Jennifer Chukwu 343eb214ef format 2024-05-05 09:39:20 +00:00
Jennifer Chukwu 914a7cf1fa add assert 2024-05-02 14:36:28 +00:00
Jennifer Chukwu e3a08c9b60 test with a fixed input 2024-05-02 10:16:45 +00:00
Jennifer Chukwu 825d078294 add tests 2024-04-30 16:25:35 +00:00
Andreas Borgen Longva 9bc7f8b0d8
Merge pull request #1383 from derchr/column-major-fix
Fix false row-major comment in doc
2024-04-30 14:22:19 +02:00
Jennifer Chukwu 5e8779957e missed one cofactor 2024-04-28 16:02:46 +00:00
Adrian H e84ea21c74
Fixed a typo in documentation in matrix_view.rs 2024-04-22 19:51:49 -07:00
Jennifer Chukwu c21df4e1a3 remove else 2024-04-22 19:00:44 +00:00
Jennifer Chukwu a0da49fb83 early return 2024-04-22 12:36:35 +00:00
Jennifer Chukwu d331bbd7c1 inversion 2024-04-19 14:49:14 +00:00
Derek Christ 28d04b61cd Fix false row-major comment in doc
In the documentation of RawStorage::stride it was falsely claimed that
the storage of the matrix happens in a row-major fashion. In fact it is
column-major.
2024-04-18 18:07:21 +02:00
Sébastien Crozet a803815bd1
chore: update changelog 2024-03-28 15:34:41 +01:00
Vollkornaffe c475c4000c
Fix numerical issue on SVD with near-identity matrix (#1369)
* fix: Normalize the column once more

The column may not be normalized if the `factor` is on a scale of 1e-40.
Possibly, f32 just runs out of precision.

There is likely a better solution to the problem.

* chore: Add test that fails before fix

* chore: add comment providing details on the householder fix.

* chore: rename regression test

---------

Co-authored-by: Sébastien Crozet <sebcrozet@dimforge.com>
2024-03-28 15:26:11 +01:00
tpdickso 749a9fee17
Merge pull request #1317 from yotamofek/swap-unchecked-ub
Fix UB in `RawStorageMut::swap_unchecked_linear`
2024-03-27 20:44:39 -04:00
Yotam Ofek 1cfc539a96 Fix type inference error in tests on rustc beta 2024-03-22 12:36:59 -07:00
Yotam Ofek 3651942670 Merge branch 'dev' of https://github.com/dimforge/nalgebra into swap-unchecked-ub 2024-03-22 17:56:35 +00:00
tpdickso 9948bf7e23
Merge pull request #1349 from CAD97/patch-3
Fix `glm::is_normalized` epsilon test
2024-03-20 23:01:15 -04:00
Yotam Ofek 095c561b60
Apply suggestions from code review
Co-authored-by: tpdickso <terence.dickson.prf@gmail.com>
2024-03-20 19:55:03 +02:00
Yotam Ofek d1b5df480f Merge branch 'dev' of https://github.com/dimforge/nalgebra into swap-unchecked-ub 2024-03-20 16:37:44 +00:00
tpdickso 990afe6b26
Merge pull request #1371 from yotamofek/redundant-import
Fix redundant import errors in `nalgebra-glm`
2024-03-20 12:11:02 -04:00
Yotam Ofek cf44429837 Fix redundant import errors in `nalgebra-glm`
More fallout from https://github.com/rust-lang/rust/issues/121708
Should make CI green again
2024-03-20 13:12:01 +00:00
Yotam Ofek d884a7e2d0 fmt 2024-03-19 16:39:28 +00:00
Yotam Ofek 546d06b541 Update src/base/storage.rs
Co-authored-by: tpdickso <terence.dickson.prf@gmail.com>
2024-03-19 16:39:28 +00:00
Yotam Ofek adc3a8103b Fix UB in `RawStorageMut::swap_unchecked_linear` 2024-03-19 16:39:28 +00:00
tpdickso 8c6f14fcd0
Merge pull request #1287 from mohe2015/triplet-iter-clone
Implement `Clone` for `CsrTripletIter` and `CscTripletIter`
2024-02-20 17:51:17 -05:00
tpdickso ee486792a6
Merge pull request #1357 from Jondolf/glam025
Support Glam 0.25 type conversion
2024-02-13 22:25:42 -05:00
Joona Aalto bbac38b2f5 Support Glam 0.25 type conversion 2024-01-27 21:11:47 +02:00
Moritz Hedtke 86bde5ff1d Implement `Clone` for `CsrTripletIter` and `CscTripletIter` 2024-01-14 22:37:58 +01:00
Christopher Durham f578181351 Fix glm::is_normalized epsilon
The existing comparison bound of $\epsilon^2$ is improperly scaled for
testing an epsilon of the squared vector magnitude. Let $\epsilon$ be
our specified epsilon and $\delta$ be the permissible delta of the
squared magnitude. Thus, for a nearly-normalized vector, we have

$$\begin{align}
\sqrt{1 + \delta} &=  1 + \epsilon        \\
          \delta  &= (1 + \epsilon)^2 - 1 \\
          \delta  &=  \epsilon^2 + 2\epsilon
\text{ .}\end{align}$$

Since we only care about small epsilon, we can assume
that $\epsilon^2$ is small and just use $\delta = 2\epsilon$. And in
fact, [this is the bound used by GLM][GLM#isNormalized] (MIT license)
... except they're using `length` and not `length2` for some reason.

[GLM#isNormalized]: b06b775c1c/glm/gtx/vector_query.inl (L102)

If we stick an epsilon of `1.0e-6` into the current implementation,
this gives us a computed delta of `1.0e-12`: smaller than the `f32`
machine epsilon, and thus no different than direct float comparison
without epsilon. This also gives an effetive epsilon of `5.0e-13`;
*much* less than the intended `1.0e-6` of intended permitted slack!
By doing a bit more algebra, we can find the effective epsilon is
$\sqrt{\texttt{epsilon}^2 + 1} - 1$. This patch makes the effective
epsilon $\sqrt{2\times\texttt{epsilon} + 1} - 1$ which still isn't
*perfect*, but it's effectively linear in the domain we care about,
only really making a practical difference above an epsilon of 10%.

TL;DR: the existing `is_normalized` considers a vector normalized if
the squared magnitude is within `epsilon*epsilon` of `1`. This is wrong
and it should be testing if it's within `2*epsilon`. This PR fixes it.

For absence of doubt, a comparison epsilon of $\texttt{epsilon}^2$ is
correct when comparing squared magnitude against zero, such as when
testing if a displacement vector is nearly zero.
2024-01-13 00:02:26 -05:00
Ababwa 0b89950fca Correct less than or equal symbol in doc in vector_relational.rs
Less than or equal <=
2024-01-11 23:24:13 -08:00
Benjamin Saunders 7866bcee5c Remove CUDA support relying on abandoned toolchain 2024-01-11 23:09:17 -08:00
Benjamin De Roeck a60870daf6
docs: Demonstrate correct function in to_homogeneous example (#1346) 2024-01-04 19:21:40 -08:00
Kurt Lawrence 6dce471297
Make OPoint call `T::fmt` to respect formatting modifiers (#1336) 2023-12-20 14:42:54 -08:00
Julian Knodt 1e0cb7bc09
Fix Clippy Warnings (#1300) 2023-12-16 13:54:38 -08:00
zachs18 a01fa48e33
Forward `std` feature to some deps. (#1321) 2023-12-10 19:35:54 -08:00
Bruce Mitchener c3fe38b318 docs: Fix unbalanced backticks. 2023-12-10 14:04:53 -08:00
Sébastien Crozet a91e3b0d89
Merge pull request #1315 from yotamofek/owned-view-iter
Allow creating matrix iter with an owned view
2023-11-12 23:29:41 +01:00
Sébastien Crozet 83eccc6b8f
Merge pull request #1312 from arscisca/dev-DefaultTrait
Implement Default trait for sparse matrix types
2023-11-12 23:27:37 +01:00
Sébastien Crozet 2e99320d01
Merge pull request #1314 from rasmusgo/fix-svd-near-zero
Fix bug in SVD related to values near zero
2023-11-12 23:18:59 +01:00