Skip to content

Commit

Permalink
add a method to initialize a 2D matrix from a linear array. Will be v…
Browse files Browse the repository at this point in the history
…ery useful for HLLs that need to instantiate array constants
  • Loading branch information
Whiteknight committed Nov 2, 2009
1 parent 66f7571 commit 1a03b3b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/pmc/nummatrix2d.pmc
Expand Up @@ -486,6 +486,23 @@ pmclass NumMatrix2D dynpmc auto_attrs {
attrs->storage = new_s;
free(old_s);
}

METHOD initialize_from_array(INTVAL x_size, INTVAL y_size, PMC *values) {
Parrot_NumMatrix2D_attributes * const attrs = PARROT_NUMMATRIX2D(SELF);
FLOATVAL * const s = attrs->storage;
INTVAL x = attrs->x;
INTVAL y = attrs->y;
INTVAL i, j, num = 0;
resize_matrix(INTERP, SELF, x_size - 1, y_size - 1);
for (i = 0; i < y_size; i++) {
for (j = 0; j < x_size; j++) {
FLOATVAL value = VTABLE_get_number_keyed(INTERP, values, num);
num++;
ITEM_XY_ROWMAJOR(s, x, y, j, i) = value;
}
}
}

/*

=back
Expand Down

0 comments on commit 1a03b3b

Please sign in to comment.