Skip to content

Commit 3d366f4

Browse files
committed
Fixed impl for scalar / matrix and added matrix recip().
1 parent cbd9df7 commit 3d366f4

File tree

23 files changed

+325
-32
lines changed

23 files changed

+325
-32
lines changed

src/f32/coresimd/mat2.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,13 @@ impl Mat2 {
403403
Self(self.0 / f32x4::splat(rhs))
404404
}
405405

406+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
407+
#[inline]
408+
#[must_use]
409+
pub fn recip(&self) -> Self {
410+
Self::from_cols(self.x_axis.recip(), self.y_axis.recip())
411+
}
412+
406413
/// Returns true if the absolute difference of all elements between `self` and `rhs`
407414
/// is less than or equal to `max_abs_diff`.
408415
///
@@ -716,7 +723,7 @@ impl Div<Mat2> for f32 {
716723
type Output = Mat2;
717724
#[inline]
718725
fn div(self, rhs: Mat2) -> Self::Output {
719-
rhs.div_scalar(self)
726+
Mat2(f32x4::splat(self) / rhs.0)
720727
}
721728
}
722729

src/f32/coresimd/mat3a.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,17 @@ impl Mat3A {
826826
)
827827
}
828828

829+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
830+
#[inline]
831+
#[must_use]
832+
pub fn recip(&self) -> Self {
833+
Self::from_cols(
834+
self.x_axis.recip(),
835+
self.y_axis.recip(),
836+
self.z_axis.recip(),
837+
)
838+
}
839+
829840
/// Returns true if the absolute difference of all elements between `self` and `rhs`
830841
/// is less than or equal to `max_abs_diff`.
831842
///
@@ -1147,7 +1158,11 @@ impl Div<Mat3A> for f32 {
11471158
type Output = Mat3A;
11481159
#[inline]
11491160
fn div(self, rhs: Mat3A) -> Self::Output {
1150-
rhs.div_scalar(self)
1161+
Mat3A::from_cols(
1162+
self.div(rhs.x_axis),
1163+
self.div(rhs.y_axis),
1164+
self.div(rhs.z_axis),
1165+
)
11511166
}
11521167
}
11531168

src/f32/coresimd/mat4.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,18 @@ impl Mat4 {
14691469
)
14701470
}
14711471

1472+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
1473+
#[inline]
1474+
#[must_use]
1475+
pub fn recip(&self) -> Self {
1476+
Self::from_cols(
1477+
self.x_axis.recip(),
1478+
self.y_axis.recip(),
1479+
self.z_axis.recip(),
1480+
self.w_axis.recip(),
1481+
)
1482+
}
1483+
14721484
/// Returns true if the absolute difference of all elements between `self` and `rhs`
14731485
/// is less than or equal to `max_abs_diff`.
14741486
///
@@ -1805,7 +1817,12 @@ impl Div<Mat4> for f32 {
18051817
type Output = Mat4;
18061818
#[inline]
18071819
fn div(self, rhs: Mat4) -> Self::Output {
1808-
rhs.div_scalar(self)
1820+
Mat4::from_cols(
1821+
self.div(rhs.x_axis),
1822+
self.div(rhs.y_axis),
1823+
self.div(rhs.z_axis),
1824+
self.div(rhs.w_axis),
1825+
)
18091826
}
18101827
}
18111828

src/f32/mat3.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,17 @@ impl Mat3 {
756756
)
757757
}
758758

759+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
760+
#[inline]
761+
#[must_use]
762+
pub fn recip(&self) -> Self {
763+
Self::from_cols(
764+
self.x_axis.recip(),
765+
self.y_axis.recip(),
766+
self.z_axis.recip(),
767+
)
768+
}
769+
759770
/// Returns true if the absolute difference of all elements between `self` and `rhs`
760771
/// is less than or equal to `max_abs_diff`.
761772
///
@@ -1077,7 +1088,11 @@ impl Div<Mat3> for f32 {
10771088
type Output = Mat3;
10781089
#[inline]
10791090
fn div(self, rhs: Mat3) -> Self::Output {
1080-
rhs.div_scalar(self)
1091+
Mat3::from_cols(
1092+
self.div(rhs.x_axis),
1093+
self.div(rhs.y_axis),
1094+
self.div(rhs.z_axis),
1095+
)
10811096
}
10821097
}
10831098

src/f32/neon/mat2.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ impl Mat2 {
445445
Self(unsafe { vdivq_f32(self.0, vld1q_dup_f32(&rhs)) })
446446
}
447447

448+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
449+
#[inline]
450+
#[must_use]
451+
pub fn recip(&self) -> Self {
452+
Self::from_cols(self.x_axis.recip(), self.y_axis.recip())
453+
}
454+
448455
/// Returns true if the absolute difference of all elements between `self` and `rhs`
449456
/// is less than or equal to `max_abs_diff`.
450457
///
@@ -764,7 +771,7 @@ impl Div<Mat2> for f32 {
764771
type Output = Mat2;
765772
#[inline]
766773
fn div(self, rhs: Mat2) -> Self::Output {
767-
rhs.div_scalar(self)
774+
Mat2(unsafe { vdivq_f32(vld1q_dup_f32(&self), rhs.0) })
768775
}
769776
}
770777

src/f32/neon/mat3a.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ impl Mat3A {
844844
)
845845
}
846846

847+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
848+
#[inline]
849+
#[must_use]
850+
pub fn recip(&self) -> Self {
851+
Self::from_cols(
852+
self.x_axis.recip(),
853+
self.y_axis.recip(),
854+
self.z_axis.recip(),
855+
)
856+
}
857+
847858
/// Returns true if the absolute difference of all elements between `self` and `rhs`
848859
/// is less than or equal to `max_abs_diff`.
849860
///
@@ -1165,7 +1176,11 @@ impl Div<Mat3A> for f32 {
11651176
type Output = Mat3A;
11661177
#[inline]
11671178
fn div(self, rhs: Mat3A) -> Self::Output {
1168-
rhs.div_scalar(self)
1179+
Mat3A::from_cols(
1180+
self.div(rhs.x_axis),
1181+
self.div(rhs.y_axis),
1182+
self.div(rhs.z_axis),
1183+
)
11691184
}
11701185
}
11711186

src/f32/neon/mat4.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,18 @@ impl Mat4 {
14811481
)
14821482
}
14831483

1484+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
1485+
#[inline]
1486+
#[must_use]
1487+
pub fn recip(&self) -> Self {
1488+
Self::from_cols(
1489+
self.x_axis.recip(),
1490+
self.y_axis.recip(),
1491+
self.z_axis.recip(),
1492+
self.w_axis.recip(),
1493+
)
1494+
}
1495+
14841496
/// Returns true if the absolute difference of all elements between `self` and `rhs`
14851497
/// is less than or equal to `max_abs_diff`.
14861498
///
@@ -1817,7 +1829,12 @@ impl Div<Mat4> for f32 {
18171829
type Output = Mat4;
18181830
#[inline]
18191831
fn div(self, rhs: Mat4) -> Self::Output {
1820-
rhs.div_scalar(self)
1832+
Mat4::from_cols(
1833+
self.div(rhs.x_axis),
1834+
self.div(rhs.y_axis),
1835+
self.div(rhs.z_axis),
1836+
self.div(rhs.w_axis),
1837+
)
18211838
}
18221839
}
18231840

src/f32/scalar/mat2.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ impl Mat2 {
412412
Self::from_cols(self.x_axis.div(rhs), self.y_axis.div(rhs))
413413
}
414414

415+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
416+
#[inline]
417+
#[must_use]
418+
pub fn recip(&self) -> Self {
419+
Self::from_cols(self.x_axis.recip(), self.y_axis.recip())
420+
}
421+
415422
/// Returns true if the absolute difference of all elements between `self` and `rhs`
416423
/// is less than or equal to `max_abs_diff`.
417424
///
@@ -716,7 +723,7 @@ impl Div<Mat2> for f32 {
716723
type Output = Mat2;
717724
#[inline]
718725
fn div(self, rhs: Mat2) -> Self::Output {
719-
rhs.div_scalar(self)
726+
Mat2::from_cols(self.div(rhs.x_axis), self.div(rhs.y_axis))
720727
}
721728
}
722729

src/f32/scalar/mat3a.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,17 @@ impl Mat3A {
828828
)
829829
}
830830

831+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
832+
#[inline]
833+
#[must_use]
834+
pub fn recip(&self) -> Self {
835+
Self::from_cols(
836+
self.x_axis.recip(),
837+
self.y_axis.recip(),
838+
self.z_axis.recip(),
839+
)
840+
}
841+
831842
/// Returns true if the absolute difference of all elements between `self` and `rhs`
832843
/// is less than or equal to `max_abs_diff`.
833844
///
@@ -1149,7 +1160,11 @@ impl Div<Mat3A> for f32 {
11491160
type Output = Mat3A;
11501161
#[inline]
11511162
fn div(self, rhs: Mat3A) -> Self::Output {
1152-
rhs.div_scalar(self)
1163+
Mat3A::from_cols(
1164+
self.div(rhs.x_axis),
1165+
self.div(rhs.y_axis),
1166+
self.div(rhs.z_axis),
1167+
)
11531168
}
11541169
}
11551170

src/f32/scalar/mat4.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,18 @@ impl Mat4 {
13741374
)
13751375
}
13761376

1377+
/// Returns a matrix containing the reciprocal `1.0/n` of each element of `self`.
1378+
#[inline]
1379+
#[must_use]
1380+
pub fn recip(&self) -> Self {
1381+
Self::from_cols(
1382+
self.x_axis.recip(),
1383+
self.y_axis.recip(),
1384+
self.z_axis.recip(),
1385+
self.w_axis.recip(),
1386+
)
1387+
}
1388+
13771389
/// Returns true if the absolute difference of all elements between `self` and `rhs`
13781390
/// is less than or equal to `max_abs_diff`.
13791391
///
@@ -1710,7 +1722,12 @@ impl Div<Mat4> for f32 {
17101722
type Output = Mat4;
17111723
#[inline]
17121724
fn div(self, rhs: Mat4) -> Self::Output {
1713-
rhs.div_scalar(self)
1725+
Mat4::from_cols(
1726+
self.div(rhs.x_axis),
1727+
self.div(rhs.y_axis),
1728+
self.div(rhs.z_axis),
1729+
self.div(rhs.w_axis),
1730+
)
17141731
}
17151732
}
17161733

0 commit comments

Comments
 (0)