Merge pull request #847 from dimforge/simd_cap_magnitude
Add simd_cap_magnitude, a SIMD version of cap_magnitude.
This commit is contained in:
commit
01cfc62112
|
@ -4,6 +4,11 @@ documented here.
|
||||||
|
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/).
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
|
## [0.25.3] - WIP
|
||||||
|
### Added
|
||||||
|
- The `Vector::simd_cap_magnitude` method to cap the magnitude of the a vector with
|
||||||
|
SIMD components.
|
||||||
|
|
||||||
## [0.25.2]
|
## [0.25.2]
|
||||||
### Added
|
### Added
|
||||||
- A `convert-glam` cargo feature to enable implementations of `From` traits to convert
|
- A `convert-glam` cargo feature to enable implementations of `From` traits to convert
|
||||||
|
|
|
@ -8,9 +8,9 @@ use crate::allocator::Allocator;
|
||||||
use crate::base::{DefaultAllocator, Dim, DimName, Matrix, MatrixMN, Normed, VectorN};
|
use crate::base::{DefaultAllocator, Dim, DimName, Matrix, MatrixMN, Normed, VectorN};
|
||||||
use crate::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
use crate::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
||||||
use crate::storage::{Storage, StorageMut};
|
use crate::storage::{Storage, StorageMut};
|
||||||
use crate::{ComplexField, RealField, Scalar, SimdComplexField, Unit};
|
use crate::{ComplexField, Scalar, SimdComplexField, Unit};
|
||||||
use simba::scalar::ClosedNeg;
|
use simba::scalar::ClosedNeg;
|
||||||
use simba::simd::{SimdOption, SimdPartialOrd};
|
use simba::simd::{SimdOption, SimdPartialOrd, SimdValue};
|
||||||
|
|
||||||
// TODO: this should be be a trait on alga?
|
// TODO: this should be be a trait on alga?
|
||||||
/// A trait for abstract matrix norms.
|
/// A trait for abstract matrix norms.
|
||||||
|
@ -343,7 +343,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cap_magnitude(&self, max: N::RealField) -> MatrixMN<N, R, C>
|
pub fn cap_magnitude(&self, max: N::RealField) -> MatrixMN<N, R, C>
|
||||||
where
|
where
|
||||||
N: RealField,
|
N: ComplexField,
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
DefaultAllocator: Allocator<N, R, C>,
|
||||||
{
|
{
|
||||||
let n = self.norm();
|
let n = self.norm();
|
||||||
|
@ -355,6 +355,20 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a new vector with the same magnitude as `self` clamped between `0.0` and `max`.
|
||||||
|
#[inline]
|
||||||
|
pub fn simd_cap_magnitude(&self, max: N::SimdRealField) -> MatrixMN<N, R, C>
|
||||||
|
where
|
||||||
|
N: SimdComplexField,
|
||||||
|
N::Element: Scalar,
|
||||||
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
|
||||||
|
{
|
||||||
|
let n = self.norm();
|
||||||
|
let scaled = self.scale(max / n);
|
||||||
|
let use_scaled = n.simd_gt(max);
|
||||||
|
scaled.select(use_scaled, self.clone_owned())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`.
|
/// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`.
|
||||||
///
|
///
|
||||||
/// The components of this matrix cannot be SIMD types (see `simd_try_normalize`) instead.
|
/// The components of this matrix cannot be SIMD types (see `simd_try_normalize`) instead.
|
||||||
|
|
Loading…
Reference in New Issue