aboutsummaryrefslogtreecommitdiff
path: root/libmu/src/maths/matrix.rs
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2024-09-16 20:53:46 +0200
committerhachem <im@hachem.wtf>2024-09-16 20:53:46 +0200
commit5abda23c3ed21db3c0a4541b85b6e2e916ce569e (patch)
treeb4b468ad97710be0de53968f8485dab747effc7c /libmu/src/maths/matrix.rs
parentb6ad90a40761d27d04ed5447dd0fd2f31adb786e (diff)
Matrix and vector products + macros
Diffstat (limited to 'libmu/src/maths/matrix.rs')
-rw-r--r--libmu/src/maths/matrix.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/libmu/src/maths/matrix.rs b/libmu/src/maths/matrix.rs
index 7662652..9724086 100644
--- a/libmu/src/maths/matrix.rs
+++ b/libmu/src/maths/matrix.rs
@@ -1,6 +1,38 @@
use super::Float;
use core::{fmt, ops};
+#[macro_export]
+macro_rules! matrix {
+ ($( $( $x:expr ),* );* ) => {{
+ let data = vec![
+ $(
+ $(
+ $x,
+ )*
+ )*
+ ];
+
+ let rows = <[()]>::len(&[$( $crate::count_items!($($x),*) ),*]);
+ let cols = $crate::count_items!($($x),*);
+
+ $crate::Matrix::new(rows, cols, data)
+ }};
+}
+
+#[macro_export]
+macro_rules! count_items {
+ ($($item:expr),*) => {
+ <[()]>::len(&[$( $crate::replace_expr!($item ())),*])
+ };
+}
+
+#[macro_export]
+macro_rules! replace_expr {
+ ($_t:tt $sub:expr) => {
+ $sub
+ };
+}
+
pub struct Matrix<T: Float> {
pub data: Vec<T>,
pub rows: usize,