-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rs2bril cleanup, lil documentation and tests
- Loading branch information
Showing
26 changed files
with
381 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
509 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//# Compute the Ackermann function recursively. | ||
//# WARNING: Will quickly exceed stack size | ||
//# ARGS: 3 6 | ||
fn main(m:i64, n:i64) { | ||
let tmp : i64 = ack(m, n); | ||
println!("{:?}", tmp); | ||
} | ||
|
||
fn ack(m:i64, n:i64) -> i64 { | ||
if m == 0 { | ||
return n + 1; | ||
} else if n == 0 { | ||
return ack(m -1, 1); | ||
} else { | ||
let t1 : i64 = ack(m, n -1); | ||
return ack(m -1, t1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn main() { | ||
let x: bool = true; | ||
if x { | ||
let one:i64 = 1; | ||
println!("{:?}", one); | ||
} else { | ||
let two:i64 = 2; | ||
println!("{:?}", two); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let x :i64 = 5; | ||
call_print(x); | ||
} | ||
|
||
fn call_print(x:i64) { | ||
println!("{:?}", x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
65.00000000000000000 | ||
0.00000000000000000 | ||
0.00000000000000000 | ||
0.00000000000000000 | ||
137.43076923076924345 | ||
55.16143280081702471 | ||
0.00000000000000000 | ||
0.00000000000000000 | ||
148.46153846153845279 | ||
22.60304899166557746 | ||
44.73559850849774477 | ||
0.00000000000000000 | ||
432.26153846153846416 | ||
250.01098702698598686 | ||
374.19363889460623795 | ||
548.34440759751453243 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
fn fillarray() -> [f64; 16] { | ||
return [ | ||
34.0, 28.0, 38.0, 29.0, 26.0, 78.0, 91.0, 83.0, 67.0, 92.0, 56.0, 92.0, 67.0, 826.0, 38.0, | ||
43.0, | ||
]; | ||
} | ||
|
||
fn print_array(size: i64, arr: &[f64]) { | ||
let mut i: i64 = 0; | ||
while i < size { | ||
let val: f64 = arr[i as usize]; | ||
println!("{:.17}", val); | ||
i += 1 | ||
} | ||
} | ||
|
||
fn matmul(size: i64, arr1: &[f64], arr2: &[f64], dest: &mut [f64]) { | ||
let mut row: i64 = 0; | ||
while row < size { | ||
let mut col: i64 = 0; | ||
while col < size { | ||
let mut sum: f64 = 0.0; | ||
let mut i: i64 = 0; | ||
while i < size { | ||
sum += arr1[((row * size) + i) as usize] * arr2[((i * size) + col) as usize]; | ||
i += 1; | ||
} | ||
dest[((row * size) + col) as usize] = sum; | ||
col += 1; | ||
} | ||
row += 1; | ||
} | ||
} | ||
|
||
fn transpose(size: i64, input: &[f64], output: &mut [f64]) { | ||
let mut row: i64 = 0; | ||
while row < size { | ||
let mut col: i64 = 0; | ||
while col < size { | ||
output[((col * size) + row) as usize] = input[((row * size) + col) as usize]; | ||
col += 1; | ||
} | ||
row += 1; | ||
} | ||
} | ||
|
||
fn sqrt(input: f64) -> f64 { | ||
let n: f64 = input; | ||
let precision: f64 = 0.00001; | ||
let mut x: f64 = input; | ||
let mut notdone: bool = true; | ||
while notdone { | ||
let root: f64 = 0.5 * (x + (n / x)); | ||
let diff: f64 = root - x; | ||
if diff < 0.0 { | ||
diff = -diff; | ||
} | ||
|
||
if (diff < precision) { | ||
notdone = false; | ||
} | ||
|
||
x = root; | ||
} | ||
return x; | ||
} | ||
|
||
fn cholesky(size: i64, arr1: &mut [f64], arr2: &mut [f64]) { | ||
let mut i: i64 = 0; | ||
while (i < size) { | ||
let mut j: i64 = 0; | ||
while (j <= i) { | ||
let mut k: i64 = 0; | ||
while (k < j) { | ||
// prepare indices | ||
let ik_index: i64 = (i * size) + k; | ||
|
||
let jk_index: i64 = (j * size) + k; | ||
|
||
let ij_index: i64 = (i * size) + j; | ||
|
||
// load values | ||
let b_ik: f64 = arr2[(ik_index) as usize]; | ||
|
||
let b_jk: f64 = arr2[(jk_index) as usize]; | ||
|
||
let a_ij: f64 = arr1[(ij_index) as usize]; | ||
|
||
let value: f64 = a_ij - (b_ik * b_jk); | ||
arr1[(ij_index) as usize] = value; | ||
|
||
k += 1; | ||
} | ||
|
||
let ij_index: i64 = (i * size) + j; | ||
let jj_index: i64 = (j * size) + j; | ||
|
||
arr2[(ij_index) as usize] = (arr1[(ij_index) as usize] / arr2[(jj_index) as usize]); | ||
|
||
j += 1; | ||
} | ||
let index: i64 = (i * size) + i; | ||
arr2[index as usize] = sqrt(arr1[index as usize]); | ||
|
||
i += 1; | ||
} | ||
return; | ||
} | ||
|
||
fn main() { | ||
let size: i64 = 4; | ||
let arr1: [f64; 16] = fillarray(); | ||
let mut arr1_transposed: [f64; 16] = fillarray(); | ||
let mut hermitian: [f64; 16] = fillarray(); | ||
let mut res: [f64; 16] = [0.0; 16]; | ||
transpose(size, &arr1, &mut arr1_transposed); | ||
matmul(size, &arr1, &arr1_transposed, &mut hermitian); | ||
cholesky(size, &mut hermitian, &mut res); | ||
print_array(16, &res); | ||
drop(arr1); | ||
drop(arr1_transposed); | ||
drop(hermitian); | ||
drop(res); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 |
Oops, something went wrong.