diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index 6259b36..d5cc43a 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -255,6 +255,30 @@ pmclass NumMatrix2D dynpmc auto_attrs { return PMCNULL; } + VTABLE PMC * clone() { + PMC * const c = pmc_new(INTERP, SELF->vtable->base_type); + Parrot_NumMatrix2D_attributes * const old_atts = + (Parrot_NumMatrix2D_attributes *)PARROT_NUMMATRIX2D(SELF); + Parrot_NumMatrix2D_attributes * const new_atts = + (Parrot_NumMatrix2D_attributes *)PARROT_NUMMATRIX2D(c); + INTVAL x, y; + INTVAL const x_size = old_attrs->x; + INTVAL const y_size = old_attrs->y; + INTVAL const newsize = x_size * y_size; + FLOATVAL * old_s = old_attrs->storage; + FLOATVAL * new_s = (FLOATVAL *)mem_sys_allocate_zeroed(newsize * sizeof (FLOATVAL)); + for (x = 0; x < x_size; ++x) { + for (y = 0; y < y_size; ++y) { + ITEM_XY_ROWMAJOR(new_s, x_size, y_size, x, y) = + ITEM_XY_ROWMAJOR(old_s, x_size, y_size, x, y); + } + } + new_attrs->storage = new_s; + new_attrs->x = x_size; + new_attrs->y = y_size; + return c; + } + METHOD fill(FLOATVAL value) { Parrot_NumMatrix2D_attributes * const attrs = (Parrot_NumMatrix2D_attributes *) PARROT_NUMMATRIX2D(SELF); @@ -315,7 +339,7 @@ pmclass NumMatrix2D dynpmc auto_attrs { for (j = 0; j < min_y; j++) { FLOATVAL value = ITEM_XY_ROWMAJOR(old_s, x, y, i, j); FLOATVAL result = 0.0; - Parrot_ext_call(INTERP, func, "PiNPf->N", SELF, value, args, &result); + Parrot_ext_call(INTERP, func, "PNPf->N", SELF, value, args, &result); ITEM_XY_ROWMAJOR(new_s, x, y, i, j) = result; } }