← Commit history
test: migrate pyre benchmarks and test scripts to Java-like Ash
lennoxrose committed on Oct 18, 2026 at 00:44 UTC
2 files changed+81−72
hearth/pyre/benchmarks/matrix/matrix_multiply.ashmodified
+47−41@@ -14,50 +14,56 @@1414
1515
// Matrix multiplication: C = A x B1616
// Dimensions: N x N17
-local N = 2000;18
-19
-forge create_matrix(size, value) {20
- local mat = [];21
- local i = 0;22
- during i < size {23
- local row = [];24
- local j = 0;25
- during j < size {26
- push(row, value);27
- j += 1;17
+package benchmarks;18
+19
+class MatrixMultiply {20
+ static double[][] createMatrix(int size, double value) {21
+ double[][] mat = new double[size][];22
+ int i = 0;23
+ while (i < size) {24
+ double[] row = new double[size];25
+ int j = 0;26
+ while (j < size) {27
+ row[j] = value;28
+ j += 1;29
+ }30
+ mat[i] = row;31
+ i += 1;2832
}29
- push(mat, row);30
- i += 1;33
+ return mat;3134
}32
- yield mat;33
-}3435
35
-// 1. Initialize two N x N matrices36
-local A = create_matrix(N, 1.5);37
-local B = create_matrix(N, 2.0);38
-39
-// 2. Initialize the result matrix C with zeros40
-local C = create_matrix(N, 0.0);41
-42
-say "Starting matrix multiplication (" + str(N) + "x" + str(N) + ")...";43
-44
-// 3. Compute C = A x B45
-// Total operations: 2 * N^3 = 250,000,000 floating point operations46
-local i = 0;47
-during i < N {48
- local j = 0;49
- during j < N {50
- local sum = 0.0;51
- local k = 0;52
- during k < N {53
- sum += A[i][k] * B[k][j];54
- k += 1;36
+ public static void main(String[] args) {37
+ int n = 2000;38
+39
+ // 1. Initialize two N x N matrices40
+ double[][] a = createMatrix(n, 1.5);41
+ double[][] b = createMatrix(n, 2.0);42
+43
+ // 2. Initialize the result matrix C with zeros44
+ double[][] c = createMatrix(n, 0.0);45
+46
+ System.out.println("Starting matrix multiplication (" + n + "x" + n + ")...");47
+48
+ // 3. Compute C = A x B49
+ // Total operations: 2 * N^3 = 250,000,000 floating point operations50
+ int i = 0;51
+ while (i < n) {52
+ int j = 0;53
+ while (j < n) {54
+ double sum = 0.0;55
+ int k = 0;56
+ while (k < n) {57
+ sum += a[i][k] * b[k][j];58
+ k += 1;59
+ }60
+ c[i][j] = sum;61
+ j += 1;62
+ }63
+ i += 1;5564
}56
- C[i][j] = sum;57
- j += 1;65
+66
+ System.out.println("Done!");67
+ System.out.println("Sample element C[0][0]: " + c[0][0]); // Should be 1500.05868
}59
- i += 1;6069
}61
-62
-say "Done!";63
-say "Sample element C[0][0]: " + str(C[0][0]); // Should be 1500\ No newline at end of filehearth/pyre/benchmarks/monte_carlo_no_pi/mcnp.ashmodified
+34−31@@ -14,46 +14,49 @@1414
//1515
// if you cant beat it by atleast 50% then you are not allowed to submit your solution1616
17
-local ITERATIONS = 1000000000;18
-local threshold = 0.75;17
+package benchmarks;1918
20
-forge random(seed) {21
- seed = (seed * 1664525 + 1013904223) % 4294967296;22
- yield seed;23
-}19
+class MonteCarloNoPi {20
+ static long random(long seed) {21
+ return (seed * 1664525L + 1013904223L) % 4294967296L;22
+ }2423
25
-local seed = 123456789;26
-local risky = 0;24
+ public static void main(String[] args) {25
+ long iterations = 1000000000L;26
+ double threshold = 0.75;27
+ long seed = 123456789L;28
+ long risky = 0L;2729
28
-say "Starting Monte Carlo simulation...";29
-say "Iterations: " + str(ITERATIONS);30
+ System.out.println("Starting Monte Carlo simulation...");31
+ System.out.println("Iterations: " + iterations);3032
31
-local i = 0;33
+ long i = 0L;34
+ while (i < iterations) {35
+ long randomValue = random(seed);36
+ seed = randomValue;3237
33
-during i < ITERATIONS {34
- local random_value = random(seed);35
- seed = random_value;38
+ double normalized = randomValue / 4294967296.0;3639
37
- local normalized = random_value / 4294967296.0;40
+ // Simulate a risk event.41
+ // Combine two independent random values.42
+ long randomValue2 = random(seed);43
+ seed = randomValue2;3844
39
- // Simulate a risk event.40
- // Combine two independent random values.41
- local random_value_2 = random(seed);42
- seed = random_value_2;45
+ double normalized2 = randomValue2 / 4294967296.0;4346
44
- local normalized_2 = random_value_2 / 4294967296.0;47
+ double score = normalized * normalized2;4548
46
- local score = normalized * normalized_2;49
+ if (score > threshold) {50
+ risky += 1L;51
+ }4752
48
- given score > threshold {49
- risky += 1;50
- }53
+ i += 1L;54
+ }5155
52
- i += 1;53
-}56
+ double probability = (double) risky / iterations;5457
55
-local probability = risky / ITERATIONS;56
-57
-say "Done!";58
-say "Risky outcomes: " + str(risky);59
-say "Estimated probability: " + str(probability);\ No newline at end of file58
+ System.out.println("Done!");59
+ System.out.println("Risky outcomes: " + risky);60
+ System.out.println("Estimated probability: " + probability);61
+ }62
+}