Created
August 22, 2020 23:42
-
-
Save anthonykasza/4f7a1415378c8a277c1634ecd2788de3 to your computer and use it in GitHub Desktop.
toy matrices
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
# 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resize()
may be helpful too.https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#id-resize