Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement eigenvalue and eigenvector computation #589

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions codegen/templates/mat.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,19 @@ impl {{ self_t }} {
{% endif %}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> {{ scalar_t }} {
{% if dim == 2 %}
self.x_axis.x + self.y_axis.y
{% elif dim == 3 %}
self.x_axis.x + self.y_axis.y + self.z_axis.z
{% elif dim == 4 %}
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
{% endif %}
}

/// Returns the determinant of `self`.
{%- if dim < 4 %}
#[inline]
Expand Down Expand Up @@ -1518,7 +1531,7 @@ impl {{ self_t }} {
glam_assert!(Mat2(tmp).is_finite());
//let dbca = simd_swizzle!(abcd, [3, 1, 2, 0]);
let dbca = vsetq_lane_f32(
vgetq_lane_f32(abcd, 0),
vgetq_lane_f32(abcd, 0),
vsetq_lane_f32(vgetq_lane_f32(abcd, 3), abcd, 0),
3,
);
Expand Down Expand Up @@ -2676,4 +2689,3 @@ impl fmt::Display for {{ self_t }} {
}
}
}

7 changes: 7 additions & 0 deletions src/f32/coresimd/mat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ impl Mat2 {
Self(simd_swizzle!(self.0, [0, 2, 1, 3]))
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/coresimd/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ impl Mat3A {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/coresimd/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,13 @@ impl Mat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f32 {
Expand Down
7 changes: 7 additions & 0 deletions src/f32/mat3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,13 @@ impl Mat3 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/neon/mat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ impl Mat2 {
})
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/neon/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,13 @@ impl Mat3A {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/neon/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ impl Mat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f32 {
Expand Down
7 changes: 7 additions & 0 deletions src/f32/scalar/mat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ impl Mat2 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/scalar/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@ impl Mat3A {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/scalar/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ impl Mat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f32 {
Expand Down
7 changes: 7 additions & 0 deletions src/f32/sse2/mat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ impl Mat2 {
Self(unsafe { _mm_shuffle_ps(self.0, self.0, 0b11_01_10_00) })
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/sse2/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ impl Mat3A {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/sse2/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ impl Mat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f32 {
Expand Down
7 changes: 7 additions & 0 deletions src/f32/wasm32/mat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ impl Mat2 {
Self(i32x4_shuffle::<0, 2, 5, 7>(self.0, self.0))
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/wasm32/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ impl Mat3A {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/wasm32/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,13 @@ impl Mat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f32 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f32 {
Expand Down
7 changes: 7 additions & 0 deletions src/f64/dmat2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ impl DMat2 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f64 {
self.x_axis.x + self.y_axis.y
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f64/dmat3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ impl DMat3 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f64 {
self.x_axis.x + self.y_axis.y + self.z_axis.z
}

/// Returns the determinant of `self`.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f64/dmat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ impl DMat4 {
}
}

/// Returns the trace of `self`.
#[inline]
#[must_use]
pub fn trace(&self) -> f64 {
self.x_axis.x + self.y_axis.y + self.z_axis.z + self.w_axis.w
}

/// Returns the determinant of `self`.
#[must_use]
pub fn determinant(&self) -> f64 {
Expand Down
Loading