-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmath.poly
More file actions
36 lines (31 loc) · 867 Bytes
/
math.poly
File metadata and controls
36 lines (31 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#[interface]
type Matrix
fn create_matrix(rows: u32, cols: u32) -> Matrix
fn multiply(a: Matrix, b: Matrix) -> Matrix
fn transform(m: Matrix) -> Matrix
#[rust]
// Rust handles the low-level Matrix type and allocation
#[derive(Debug, Clone)]
pub struct Matrix {
pub data: Vec<f64>,
pub rows: u32,
pub cols: u32,
}
fn create_matrix(rows: u32, cols: u32) -> Matrix {
println!("Rust: Creating {}x{} matrix", rows, cols);
Matrix {
data: vec![0.0; (rows * cols) as usize],
rows,
cols,
}
}
fn multiply(a: Matrix, b: Matrix) -> Matrix {
println!("Rust: Matrix multiply {}x{} * {}x{}", a.rows, a.cols, b.rows, b.cols);
// Simple identity return for demo
a
}
#[python]
# Python handles the higher-level transformations
def transform(m: Matrix) -> Matrix:
print(f"Python: Transforming matrix")
return m