Skip to content

Instantly share code, notes, and snippets.

@anthonykasza
Created August 22, 2020 23:42
Show Gist options
  • Save anthonykasza/4f7a1415378c8a277c1634ecd2788de3 to your computer and use it in GitHub Desktop.
Save anthonykasza/4f7a1415378c8a277c1634ecd2788de3 to your computer and use it in GitHub Desktop.
toy matrices
# A toy example showing pure scriptland matrix types. Good luck multiplying anything.
module Matrix;
export {
type matrix_int: vector of vector of int;
type matrix_dbl: vector of vector of double;
global make_matrix_int: function(rows: count, cols: count): matrix_int;
global make_matrix_dbl: function(rows: count, cols: count): matrix_dbl;
}
function Matrix::make_int_matrix(rows: count, cols: count): Matrix::matrix_int {
local matrix: Matrix::matrix_int;
local r: count = 0;
local c: count = 0;
while (r < rows) {
matrix[r] = vector();
while (c < cols) {
matrix[r][c] = 0;
c += 1;
}
c = 0;
r += 1;
}
return matrix;
}
function Matrix::make_dbl_matrix(rows: count, cols: count): Matrix::matrix_dbl {
local matrix: Matrix::matrix_dbl;
local r: count = 0;
local c: count = 0;
while (r < rows) {
matrix[r] = vector();
while (c < cols) {
matrix[r][c] = 0;
c += 1;
}
c = 0;
r += 1;
}
return matrix;
}
event zeek_init() {
local m_i: Matrix::matrix_int = Matrix::make_int_matrix(3, 5);
print m_i;
local m_d: Matrix::matrix_dbl = Matrix::make_dbl_matrix(3, 5);
print m_d;
}
@anthonykasza
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment