From f80856e8bc70253394e4ceb435fbf6aa19c6b776 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Tue, 24 Aug 2010 09:04:35 -0400 Subject: [PATCH 1/8] rearrange some things so that we build again. I've moved the DECLATTR and ALLOCATE_STORAGE macros into the header file, which turns out to be a wasted exercise since my library files can't get access to the Parrot_*_attributes structures, due to the order of the build --- src/include/pla_blas.h | 17 +++++ src/include/pla_matrix_types.h | 14 ++++ src/lib/pla_blas.c | 70 +++++++----------- src/pmc/complexmatrix2d.pmc | 131 +++++++++++++++++++-------------- src/pmc/nummatrix2d.pmc | 115 ++++++++++++++++------------- src/pmc/pmcmatrix2d.pmc | 71 +++++++++--------- 6 files changed, 230 insertions(+), 188 deletions(-) diff --git a/src/include/pla_blas.h b/src/include/pla_blas.h index 36c359e..e1e5b1e 100644 --- a/src/include/pla_blas.h +++ b/src/include/pla_blas.h @@ -61,4 +61,21 @@ extern void zgemm_( ); # endif /* _PLA_HAVE_CBLAS_H */ + +void call_dgemm( + FLOATVAL alpha, + INTVAL flags_A, FLOATVAL * A, INTVAL rows_A, INTVAL cols_A, + INTVAL flags_B, FLOATVAL * B, INTVAL cols_B, + FLOATVAL beta, + FLOATVAL * C +); + +void call_zgemm( + FLOATVAL alpha_r, FLOATVAL alpha_i, + INTVAL flags_a, FLOATVAL * A, INTVAL rows_a, INTVAL cols_a, + INTVAL flags_b, FLOATVAL * B, INTVAL cols_b, + FLOATVAL beta_r, FLOATVAL beta_i, + FLOATVAL * C +); + #endif /* _PLA_BLAS_H_ */ diff --git a/src/include/pla_matrix_types.h b/src/include/pla_matrix_types.h index 2089b06..356d666 100644 --- a/src/include/pla_matrix_types.h +++ b/src/include/pla_matrix_types.h @@ -5,6 +5,20 @@ extern INTVAL __PLA_Type_NumMatrix2D; extern INTVAL __PLA_Type_ComplexMatrix2D; extern INTVAL __PLA_Type_PMCMatrix2D; +#define ALLOCATE_STORAGE_NumMatrix2D(s) \ + (FLOATVAL *)mem_sys_allocate_zeroed(s * sizeof (FLOATVAL)) +#define DECLATTRS_NumMatrix2D(p, a) Parrot_NumMatrix2D_attributes * const (a) = \ + (Parrot_NumMatrix2D_attributes *)((p)->data) + +#define ALLOCATE_STORAGE_ComplexMatrix2D(s) \ + (FLOATVAL *)mem_sys_allocate_zeroed(s * sizeof (FLOATVAL) * 2) +#define DECLATTRS_ComplexMatrix2D(p, a) Parrot_ComplexMatrix2D_attributes * const (a) = \ + (Parrot_ComplexMatrix2D_attributes *)((p)->data) + +#define ALLOCATE_STORAGE_PMCMatrix2D(s) (PMC **)mem_sys_allocate_zeroed(s * sizeof (PMC *)) +#define DECLATTRS_PMCMatrix2D(p, a) Parrot_PMCMatrix2D_attributes * const (a) = \ + (Parrot_PMCMatrix2D_attributes *)((p)->data) + #define SWAP_XY(a) do { \ const INTVAL __temp_val = a->rows; \ a->rows = a->cols; \ diff --git a/src/lib/pla_blas.c b/src/lib/pla_blas.c index 64d2387..5b8ba6e 100644 --- a/src/lib/pla_blas.c +++ b/src/lib/pla_blas.c @@ -3,80 +3,62 @@ /* Wrapper to call the dgemm function from BLAS with PMC arguments. Assumes A, B, and C are all NumMatrix2D. */ void -call_dgemm(PARROT_INTERP, FLOATVAL alpha, PMC * A, PMC *B, FLOATVAL beta, PMC *C) +call_dgemm(FLOATVAL alpha, + INTVAL flags_A, FLOATVAL * A, INTVAL rows_A, INTVAL cols_A, + INTVAL flags_B, FLOATVAL * B, INTVAL cols_B, + FLOATVAL beta, FLOATVAL * C) { - DECLATTRS(A, attrs_a); - DECLATTRS(B, attrs_b); - DECLATTRS(C, attrs_c); - const INTVAL M = attrs_a->rows; - const INTVAL N = attrs_b->cols; - const INTVAL K = attrs_a->cols; - if (attrs_c->rows != M) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA DGEMM: A, C indices do not match in gemm"); - if (attrs_c->cols != N) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA DGEMM: B, C indices do not match in gemm"); - if (attrs_b->rows != K) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA DGEMM: A, B indeces do not match in gemm"); + const INTVAL M = rows_A; + const INTVAL N = cols_B; + const INTVAL K = cols_A; dgemm(CblasRowMajor, - IS_TRANSPOSED_BLAS(attrs_a->flags), - IS_TRANSPOSED_BLAS(attrs_b->flags), + IS_TRANSPOSED_BLAS(flags_A), + IS_TRANSPOSED_BLAS(flags_B), M, N, K, alpha, - attrs_a->storage, + A, M, - attrs_b->storage, + B, N, beta, - attrs_c->storage, + C, M ); } /* Wrapper to call the zdgemm function from BLAS with PMC arguments. Assumes A, B, and C are all ComplexMatrix2D. */ -static void -call_zgemm(PARROT_INTERP, FLOATVAL alpha_r, FLOATVAL alpha_i, PMC * A, PMC *B, - FLOATVAL beta_r, FLOATVAL beta_i, PMC *C) +void +call_zgemm(FLOATVAL alpha_r, FLOATVAL alpha_i, + INTVAL flags_a, FLOATVAL * A, INTVAL rows_a, INTVAL cols_a, + INTVAL flags_b, FLOATVAL * B, INTVAL cols_b, + FLOATVAL beta_r, FLOATVAL beta_i, FLOATVAL * C) { - DECLATTRS(A, attrs_a); - DECLATTRS(B, attrs_b); - DECLATTRS(C, attrs_c); - const INTVAL M = attrs_a->rows; - const INTVAL N = attrs_b->cols; - const INTVAL K = attrs_a->cols; + const INTVAL M = rows_a; + const INTVAL N = cols_b; + const INTVAL K = cols_a; FLOATVAL alpha_p[2]; FLOATVAL beta_p[2]; - if (attrs_c->rows != M) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA ZGEMM: A, C indices do not match in gemm"); - if (attrs_c->cols != N) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA ZGEMM: B, C indices do not match in gemm"); - if (attrs_b->rows != K) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, - "PLA ZGEMM: A, B indeces do not match in gemm"); + alpha_p[0] = alpha_r; alpha_p[1] = alpha_i; beta_p[0] = beta_r; beta_p[1] = beta_i; zgemm(CblasRowMajor, - IS_TRANSPOSED_BLAS(attrs_a->flags), - IS_TRANSPOSED_BLAS(attrs_b->flags), + IS_TRANSPOSED_BLAS(flags_a), + IS_TRANSPOSED_BLAS(flags_b), M, N, K, alpha_p, - attrs_a->storage, + A, M, - attrs_b->storage, + B, N, beta_p, - attrs_c->storage, + C, M ); } diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index 16c912b..849b445 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -1,9 +1,6 @@ #include "pla.h" -#define ALLOCATE_STORAGE(s) (FLOATVAL *)mem_sys_allocate_zeroed(s * sizeof (FLOATVAL) * 2) #define PLATYPENAME "ComplexMatrix2D" -#define DECLATTRS(p, a) Parrot_ComplexMatrix2D_attributes * const (a) = \ - (Parrot_ComplexMatrix2D_attributes *)((p)->data) INTVAL __PLA_Type_ComplexMatrix2D; @@ -13,12 +10,12 @@ INTVAL __PLA_Type_ComplexMatrix2D; static void normalize_lazy_transpose(PARROT_INTERP, PMC * self) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); if (IS_TRANSPOSED(attrs->flags)) { const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL size = rows_size * cols_size; - FLOATVAL * const new_s = ALLOCATE_STORAGE(size); + FLOATVAL * const new_s = ALLOCATE_STORAGE_ComplexMatrix2D(size); FLOATVAL * const old_s = attrs->storage; INTVAL i, j; @@ -71,7 +68,7 @@ convert_to_ComplexMatrix2D(PARROT_INTERP, PMC * p, INTVAL forcecopy) static void resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); /* Store the old values */ const INTVAL old_rows = attrs->rows; const INTVAL old_cols = attrs->cols; @@ -82,7 +79,7 @@ resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) const INTVAL new_rows = INDEX_MAX(old_rows, row + 1); const INTVAL new_cols = INDEX_MAX(old_cols, col + 1); const INTVAL newsize = new_rows * new_cols; - FLOATVAL * new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * new_s = ALLOCATE_STORAGE_ComplexMatrix2D(newsize); INTVAL i, j; @@ -105,7 +102,7 @@ static void init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, INTVAL cols_size, PMC * values) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); INTVAL num = 0; const INTVAL init_elems = VTABLE_elements(interp, values); const INTVAL total_elems = rows_size * cols_size; @@ -120,7 +117,7 @@ init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, static PMC * get_complex_pmc_at_xy(PARROT_INTERP, PMC *self, INTVAL rows, INTVAL cols) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; PMC * newcomplex; @@ -143,7 +140,7 @@ static void set_complex_pmc_at_xy(PARROT_INTERP, PMC * self, PMC * value, INTVAL row, INTVAL col) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); INTVAL rows_size = attrs->rows; INTVAL cols_size = attrs->cols; FLOATVAL real, imag; @@ -165,7 +162,7 @@ static void set_scalar_at_xy(PARROT_INTERP, PMC * self, FLOATVAL value, INTVAL row, INTVAL col) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); INTVAL rows_size = attrs->rows; INTVAL cols_size = attrs->cols; const INTVAL flags = attrs->flags; @@ -185,7 +182,7 @@ set_scalar_at_xy(PARROT_INTERP, PMC * self, FLOATVAL value, INTVAL row, static void add_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -202,7 +199,7 @@ add_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) static void add_scalar_complex(PARROT_INTERP, PMC * self, PMC *v, INTVAL sub) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -232,7 +229,7 @@ add_scalar_complex(PARROT_INTERP, PMC * self, PMC *v, INTVAL sub) static void multiply_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -250,7 +247,7 @@ multiply_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) static void multiply_scalar_complex(PARROT_INTERP, PMC * self, PMC * v) { - DECLATTRS(self, attrs); + DECLATTRS_ComplexMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -270,13 +267,33 @@ multiply_scalar_complex(PARROT_INTERP, PMC * self, PMC * v) } } +static void +multiply_matrices(PARROT_INTERP, FLOATVAL alpha_r, FLOATVAL alpha_i, PMC * A, + PMC * B, FLOATVAL beta_r, FLOATVAL beta_i, PMC * C) +{ + DECLATTRS_ComplexMatrix2D(A, attrs_a); + DECLATTRS_ComplexMatrix2D(B, attrs_b); + DECLATTRS_ComplexMatrix2D(C, attrs_c); + if (attrs_c->rows != attrs_a->rows) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": A, C indices do not match in gemm"); + if (attrs_c->cols != attrs_b->cols) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": B, C indices do not match in gemm"); + if (attrs_b->rows != attrs_a->cols) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": A, B indeces do not match in gemm"); + call_zgemm(alpha_r, alpha_i, attrs_a->flags, attrs_a->storage, attrs_a->rows, attrs_a->cols, + attrs_b->flags, attrs_b->storage, attrs_b->cols, beta_r, beta_i, attrs_c->storage); +} + /* item-by-item addition or subtraction A = A + B */ static void add_matrices(PARROT_INTERP, PMC * A, PMC * B, INTVAL sub) { - DECLATTRS(A, attrs_a); - DECLATTRS(B, attrs_b); + DECLATTRS_ComplexMatrix2D(A, attrs_a); + DECLATTRS_ComplexMatrix2D(B, attrs_b); const INTVAL rows = attrs_a->rows; const INTVAL cols = attrs_a->cols; FLOATVAL * const s_a = attrs_a->storage; @@ -330,7 +347,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix */ VTABLE void init() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); attrs->storage = NULL; attrs->rows = 0; attrs->cols = 0; @@ -339,7 +356,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE void destroy() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; if (s) mem_sys_free(s); @@ -360,7 +377,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix */ VTABLE FLOATVAL get_number_keyed(PMC * key) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; INTVAL rows, cols; @@ -375,7 +392,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE FLOATVAL get_number_keyed_int(INTVAL key) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL totalsize = attrs->rows * attrs->cols; FLOATVAL real, imag; if (key >= totalsize || key < 0) { @@ -398,7 +415,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE STRING * get_string_keyed(PMC * key) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; INTVAL rows, cols; @@ -415,7 +432,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE STRING * get_string_keyed_int(INTVAL key) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL real, imag; const INTVAL totalsize = attrs->rows * attrs->cols; if (key >= totalsize || totalsize < 0) { @@ -434,7 +451,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE PMC * get_pmc_keyed_int(INTVAL key) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL row, col; intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); return get_complex_pmc_at_xy(INTERP, SELF, row, col); @@ -457,7 +474,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL row, col; intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); set_complex_pmc_at_xy(INTERP, SELF, value, row, col); @@ -470,7 +487,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL row, col; intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); set_scalar_at_xy(INTERP, SELF, value, row, col); @@ -491,7 +508,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE void set_string_keyed_int(INTVAL key, STRING * value) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL row, col; PMC * const item = Parrot_pmc_new(INTERP, enum_class_Complex); VTABLE_set_string_native(INTERP, item, value); @@ -507,7 +524,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix */ VTABLE STRING *get_string() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL rows, cols; PMC * const builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder); STRING * const newline = Parrot_str_new(INTERP, "\n", 1); @@ -541,7 +558,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE PMC * get_attr_str(STRING * idx) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) { PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer); VTABLE_set_integer_native(INTERP, rows, attrs->rows); @@ -562,14 +579,14 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix VTABLE PMC * clone() { PMC * const c = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS(SELF, old_atts); - DECLATTRS(c, new_atts); + DECLATTRS_ComplexMatrix2D(SELF, old_atts); + DECLATTRS_ComplexMatrix2D(c, new_atts); INTVAL rows, cols; INTVAL const rows_size = old_atts->rows; INTVAL const cols_size = old_atts->cols; INTVAL const newsize = rows_size * cols_size; FLOATVAL * const old_s = old_atts->storage; - FLOATVAL * const new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * const new_s = ALLOCATE_STORAGE_ComplexMatrix2D(newsize); for (rows = 0; rows < rows_size; ++rows) { for (cols = 0; cols < cols_size; ++cols) { R_ITEM_XY_ROWMAJOR(new_s, rows_size, cols_size, rows, cols) = @@ -587,8 +604,8 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix VTABLE INTVAL is_equal(PMC * other) { if (other->vtable->base_type == SELF->vtable->base_type) { - DECLATTRS(SELF, self_attrs); - DECLATTRS(other, other_attrs); + DECLATTRS_ComplexMatrix2D(SELF, self_attrs); + DECLATTRS_ComplexMatrix2D(other, other_attrs); const INTVAL self_rows = self_attrs->rows; const INTVAL self_cols = self_attrs->cols; const INTVAL self_flags = self_attrs->flags; @@ -632,7 +649,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix */ VTABLE void freeze(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL const rows = attrs->rows; INTVAL const cols = attrs->cols; INTVAL const flags = attrs->flags; @@ -652,7 +669,7 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix } VTABLE void thaw(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL const rows = VTABLE_shift_integer(INTERP, info); INTVAL const cols = VTABLE_shift_integer(INTERP, info); INTVAL const flags = VTABLE_shift_integer(INTERP, info); @@ -865,8 +882,8 @@ Add the integer value to every element in the matrix. */ MULTI PMC *multiply(ComplexMatrix2D *value, PMC *dest) { - DECLATTRS(SELF, selfattr); - DECLATTRS(value, valattr); + DECLATTRS_ComplexMatrix2D(SELF, selfattr); + DECLATTRS_ComplexMatrix2D(value, valattr); const INTVAL new_rows = selfattr->rows; const INTVAL new_cols = valattr->cols; @@ -877,7 +894,7 @@ Add the integer value to every element in the matrix. dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); resize_matrix(INTERP, dest, new_rows - 1, new_cols - 1); - call_zgemm(INTERP, 1.0, 0.0, SELF, value, 0.0, 0.0, dest); + multiply_matrices(INTERP, 1.0, 0.0, SELF, value, 0.0, 0.0, dest); return dest; } @@ -928,7 +945,7 @@ Add the integer value to every element in the matrix. MULTI void i_multiply(ComplexMatrix2D* value) { PMC * const temp = VTABLE_clone(INTERP, SELF); - call_zgemm(INTERP, 1.0, 0.0, temp, value, 0.0, 0.0, SELF); + multiply_matrices(INTERP, 1.0, 0.0, temp, value, 0.0, 0.0, SELF); } MULTI void i_multiply(Complex *value) { @@ -993,7 +1010,7 @@ sizes, growing the matrix if needed. INTVAL cols_size :optional, INTVAL has_cols_size :opt_flag ) { /* TODO: Value here is going to be a Complex PMC. Handle that */ - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * s = attrs->storage; INTVAL const curr_rows_size = attrs->rows; INTVAL const curr_cols_size = attrs->cols; @@ -1027,7 +1044,7 @@ sizes, growing the matrix if needed. METHOD item_at(INTVAL row, INTVAL col, PMC * value :optional, INTVAL has_value :opt_flag) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; if (row < 0 || col < 0 || row >= rows || col >= cols) { @@ -1055,7 +1072,7 @@ Transposes the matrix. */ METHOD transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL tmp = 0; INTVAL transposed = IS_TRANSPOSED(attrs->flags); @@ -1081,11 +1098,11 @@ than the transpose() method. */ METHOD mem_transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL newsize = rows_size * cols_size; - FLOATVAL * new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * new_s = ALLOCATE_STORAGE_ComplexMatrix2D(newsize); FLOATVAL * old_s = attrs->storage; INTVAL i, j; @@ -1112,7 +1129,7 @@ than the transpose() method. */ METHOD conjugate() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL newsize = rows_size * cols_size; @@ -1139,7 +1156,7 @@ value with the return value of the called function. */ METHOD iterate_function_inplace(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; INTVAL i, j; @@ -1155,7 +1172,7 @@ value with the return value of the called function. } METHOD iterate_function_external(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); PMC * const new_matrix = Parrot_pmc_new(INTERP, SELF->vtable->base_type); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; @@ -1187,7 +1204,7 @@ value with the return value of the called function. METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, INTVAL cols_size) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1221,8 +1238,8 @@ value with the return value of the called function. } METHOD set_block(INTVAL rows_idx, INTVAL cols_idx, PMC * blck) { - DECLATTRS(SELF, self_attrs); - DECLATTRS(blck, blck_attrs); + DECLATTRS_ComplexMatrix2D(SELF, self_attrs); + DECLATTRS_ComplexMatrix2D(blck, blck_attrs); FLOATVAL * self_s = self_attrs->storage; FLOATVAL * const blck_s = blck_attrs->storage; INTVAL self_rows = self_attrs->rows; @@ -1276,7 +1293,7 @@ Calculates the matrix equation: C = convert_to_ComplexMatrix2D(interp, C, 1); get_complex_value_from_pmc(interp, alpha, &alpha_r, &alpha_i); get_complex_value_from_pmc(interp, beta, &beta_r, &beta_i); - call_zgemm(INTERP, alpha_r, alpha_i, A, B, beta_r, beta_i, C); + multiply_matrices(INTERP, alpha_r, alpha_i, A, B, beta_r, beta_i, C); RETURN(PMC* C); } @@ -1299,7 +1316,7 @@ Swap two rows */ METHOD row_combine(INTVAL srcidx, INTVAL destidx, FLOATVAL gain) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1317,7 +1334,7 @@ Swap two rows } METHOD row_scale(INTVAL idx, FLOATVAL gain) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1333,7 +1350,7 @@ Swap two rows } METHOD row_swap(INTVAL idx_a, INTVAL idx_b) { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1373,7 +1390,7 @@ Get a PMCMatrix2D from the current matrix */ METHOD convert_to_number_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_NumMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); @@ -1394,7 +1411,7 @@ Get a PMCMatrix2D from the current matrix } METHOD convert_to_pmc_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_ComplexMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_PMCMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index b3a1649..769edf1 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -1,9 +1,5 @@ #include "pla.h" - -#define ALLOCATE_STORAGE(s) (FLOATVAL *)mem_sys_allocate_zeroed(s * sizeof (FLOATVAL)) #define PLATYPENAME "NumMatrix2D" -#define DECLATTRS(p, a) Parrot_NumMatrix2D_attributes * const (a) = \ - (Parrot_NumMatrix2D_attributes *)((p)->data) INTVAL __PLA_Type_NumMatrix2D; @@ -21,7 +17,7 @@ INTVAL __PLA_Type_NumMatrix2D; static void resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) { - DECLATTRS(self, attrs); + DECLATTRS_NumMatrix2D(self, attrs); /* Store the old values */ const INTVAL old_rows = attrs->rows; const INTVAL old_cols = attrs->cols; @@ -32,7 +28,7 @@ resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) const INTVAL new_rows = INDEX_MAX(old_rows, row + 1); const INTVAL new_cols = INDEX_MAX(old_cols, col + 1); const INTVAL newsize = new_rows * new_cols; - FLOATVAL * new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); INTVAL i, j; for (i = 0; i < old_rows; i++) { @@ -48,18 +44,37 @@ resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) mem_sys_free(old_s); } +static void +multiply_matrices(PARROT_INTERP, FLOATVAL alpha, PMC * A, PMC * B, FLOATVAL beta, PMC * C) +{ + DECLATTRS_NumMatrix2D(A, attrs_a); + DECLATTRS_NumMatrix2D(B, attrs_b); + DECLATTRS_NumMatrix2D(C, attrs_c); + if (attrs_c->rows != attrs_a->rows) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": A, C indices do not match in gemm"); + if (attrs_c->cols != attrs_b->cols) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": B, C indices do not match in gemm"); + if (attrs_b->rows != attrs_a->cols) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": A, B indeces do not match in gemm"); + call_dgemm(alpha, attrs_a->flags, attrs_a->storage, attrs_a->rows, attrs_a->cols, + attrs_b->flags, attrs_b->storage, attrs_b->cols, beta, attrs_c->storage); +} + /* If the matrix is lazily transposed, actually transpose the physical memory layout. This is necessary for calculations, especially BLAS calculations, which aren't lazy-transpose-aware. */ static void normalize_lazy_transpose(PARROT_INTERP, PMC * self) { - DECLATTRS(self, attrs); + DECLATTRS_NumMatrix2D(self, attrs); if (IS_TRANSPOSED(attrs->flags)) { const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL size = rows_size * cols_size; - FLOATVAL * const new_s = ALLOCATE_STORAGE(size); + FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(size); FLOATVAL * const old_s = attrs->storage; INTVAL i, j; @@ -100,7 +115,7 @@ static void init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, INTVAL cols_size, PMC * values) { - DECLATTRS(self, attrs); + DECLATTRS_NumMatrix2D(self, attrs); FLOATVAL * s; INTVAL self_rows, self_cols, i, j, num = 0; const INTVAL init_elems = VTABLE_elements(interp, values); @@ -125,7 +140,7 @@ init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, static void add_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) { - DECLATTRS(self, attrs); + DECLATTRS_NumMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -142,7 +157,7 @@ add_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) static void multiply_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) { - DECLATTRS(self, attrs); + DECLATTRS_NumMatrix2D(self, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; FLOATVAL * const s = attrs->storage; @@ -160,8 +175,8 @@ multiply_scalar_float(PARROT_INTERP, PMC * self, FLOATVAL v) static void add_matrices(PARROT_INTERP, PMC * A, PMC * B, INTVAL sub) { - DECLATTRS(A, attrs_a); - DECLATTRS(B, attrs_b); + DECLATTRS_NumMatrix2D(A, attrs_a); + DECLATTRS_NumMatrix2D(B, attrs_b); const INTVAL rows = attrs_a->rows; const INTVAL cols = attrs_a->cols; FLOATVAL * const s_a = attrs_a->storage; @@ -217,7 +232,7 @@ Destrow the matrix and free it's allocated storage */ VTABLE void init() { - DECLATTRS(SELF, a); + DECLATTRS_NumMatrix2D(SELF, a); a->storage = NULL; a->rows = 0; a->cols = 0; @@ -226,7 +241,7 @@ Destrow the matrix and free it's allocated storage } VTABLE void destroy() { - DECLATTRS(SELF, a); + DECLATTRS_NumMatrix2D(SELF, a); FLOATVAL * const s = a->storage; if (s) mem_sys_free(s); @@ -257,7 +272,7 @@ elements. */ VTABLE FLOATVAL get_number_keyed(PMC * key) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; INTVAL rows, cols; @@ -312,7 +327,7 @@ Nth number. The array is arranged in memory row by row. */ VTABLE FLOATVAL get_number_keyed_int(INTVAL key) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL total_size = attrs->rows * attrs->cols; if (key >= total_size) { Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, @@ -361,7 +376,7 @@ must have two elements. */ VTABLE void set_number_keyed(PMC * key, FLOATVAL value) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); INTVAL rows, cols, rows_size = attrs->rows, cols_size = attrs->cols; GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols); if (rows >= rows_size || cols >= cols_size) { @@ -384,7 +399,7 @@ must have two elements. } VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL total_size = attrs->rows * attrs->cols; if (key >= total_size) { Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, @@ -414,7 +429,7 @@ Get a string representation of the matrix. */ VTABLE STRING *get_string() { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); INTVAL i, j; PMC * const builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder); STRING * const newline = Parrot_str_new(INTERP, "\n", 1); @@ -606,8 +621,8 @@ Add the integer value to every element in the matrix. */ MULTI PMC *multiply(NumMatrix2D *value, PMC *dest) { - DECLATTRS(SELF, selfattr); - DECLATTRS(value, valattr); + DECLATTRS_NumMatrix2D(SELF, selfattr); + DECLATTRS_NumMatrix2D(value, valattr); const INTVAL new_rows = selfattr->rows; const INTVAL new_cols = valattr->cols; @@ -618,7 +633,7 @@ Add the integer value to every element in the matrix. dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF)); resize_matrix(INTERP, dest, new_rows - 1, new_cols - 1); - call_dgemm(INTERP, 1.0, SELF, value, 0.0, dest); + multiply_matrices(INTERP, 1.0, SELF, value, 0.0, dest); return dest; } @@ -663,7 +678,7 @@ Add the integer value to every element in the matrix. MULTI void i_multiply(NumMatrix2D* value) { PMC * const temp = VTABLE_clone(INTERP, SELF); - call_dgemm(INTERP, 1.0, temp, value, 0.0, SELF); + multiply_matrices(INTERP, 1.0, temp, value, 0.0, SELF); } MULTI void i_multiply(DEFAULT* value) { @@ -698,7 +713,7 @@ Add the integer value to every element in the matrix. */ VTABLE PMC * get_attr_str(STRING * idx) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) { PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer); VTABLE_set_integer_native(INTERP, rows, attrs->rows); @@ -727,11 +742,11 @@ Add the integer value to every element in the matrix. VTABLE PMC * clone() { PMC * const c = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS(SELF, old_atts); - DECLATTRS(c, new_atts); + DECLATTRS_NumMatrix2D(SELF, old_atts); + DECLATTRS_NumMatrix2D(c, new_atts); INTVAL const newsize = old_atts->rows * old_atts->cols; FLOATVAL * const old_s = old_atts->storage; - FLOATVAL * const new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); memcpy(new_s, old_s, newsize * sizeof(FLOATVAL)); memcpy(new_atts, old_atts, sizeof(Parrot_NumMatrix2D_attributes)); new_atts->storage = new_s; @@ -748,8 +763,8 @@ Add the integer value to every element in the matrix. VTABLE INTVAL is_equal(PMC * other) { if (other->vtable->base_type == SELF->vtable->base_type) { - DECLATTRS(SELF, self_attrs); - DECLATTRS(other, other_attrs); + DECLATTRS_NumMatrix2D(SELF, self_attrs); + DECLATTRS_NumMatrix2D(other, other_attrs); const INTVAL self_rows = self_attrs->rows; const INTVAL self_cols = self_attrs->cols; const INTVAL self_flags = self_attrs->flags; @@ -789,7 +804,7 @@ Add the integer value to every element in the matrix. */ VTABLE void freeze(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); INTVAL const rows = attrs->rows; INTVAL const cols = attrs->cols; INTVAL const flags = attrs->flags; @@ -807,7 +822,7 @@ Add the integer value to every element in the matrix. } VTABLE void thaw(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); INTVAL const rows = VTABLE_shift_integer(INTERP, info); INTVAL const cols = VTABLE_shift_integer(INTERP, info); INTVAL const flags = VTABLE_shift_integer(INTERP, info); @@ -861,7 +876,7 @@ sizes, growing the matrix if needed. INTVAL rows_size :optional, INTVAL has_rows_size :opt_flag, INTVAL cols_size :optional, INTVAL has_cols_size :opt_flag ) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); FLOATVAL * s = attrs->storage; INTVAL const curr_rows_size = attrs->rows; INTVAL const curr_cols_size = attrs->cols; @@ -896,7 +911,7 @@ sizes, growing the matrix if needed. METHOD item_at(INTVAL row, INTVAL col, FLOATVAL value :optional, INTVAL has_value :opt_flag) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; if (row >= rows || col >= cols || row < 0 || col < 0) { @@ -921,7 +936,7 @@ Transposes the matrix lazily. */ METHOD transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); INTVAL transposed = IS_TRANSPOSED(attrs->flags); SWAP_XY(attrs); @@ -946,11 +961,11 @@ than the transpose() method. */ METHOD mem_transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; const INTVAL newsize = rows * cols; - FLOATVAL * const new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); FLOATVAL * const old_s = attrs->storage; INTVAL i, j; @@ -983,13 +998,13 @@ computation to a new matrix. Return the new matrix of results. */ METHOD iterate_function_inplace(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; const INTVAL newsize = rows * cols; const INTVAL flags = attrs->flags; FLOATVAL * const old_s = attrs->storage; - FLOATVAL * const new_s = ALLOCATE_STORAGE(newsize); + FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); INTVAL i, j; if (newsize == 0 || old_s == NULL) @@ -1009,7 +1024,7 @@ computation to a new matrix. Return the new matrix of results. } METHOD iterate_function_external(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); PMC * const new_matrix = Parrot_pmc_new(INTERP, SELF->vtable->base_type); Parrot_NumMatrix2D_attributes * new_attrs; const INTVAL rows = attrs->rows; @@ -1077,7 +1092,7 @@ with data in order. METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, INTVAL cols_size) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1094,7 +1109,7 @@ with data in order. PLATYPENAME ": Can not get block with negative size"); else { PMC * const new_matrix = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS(new_matrix, new_attrs); + DECLATTRS_NumMatrix2D(new_matrix, new_attrs); FLOATVAL * new_s; resize_matrix(INTERP, new_matrix, rows_size - 1, cols_size - 1); new_s = new_attrs->storage; @@ -1109,8 +1124,8 @@ with data in order. } METHOD set_block(INTVAL rows_idx, INTVAL cols_idx, PMC * blck) { - DECLATTRS(SELF, self_attrs); - DECLATTRS(blck, blck_attrs); + DECLATTRS_NumMatrix2D(SELF, self_attrs); + DECLATTRS_NumMatrix2D(blck, blck_attrs); FLOATVAL * self_s = self_attrs->storage; FLOATVAL * const blck_s = blck_attrs->storage; INTVAL self_rows = self_attrs->rows; @@ -1159,7 +1174,7 @@ Calculates the matrix equation: A = convert_to_NumMatrix2D(interp, A, 0); B = convert_to_NumMatrix2D(interp, B, 0); C = convert_to_NumMatrix2D(interp, C, 1); - call_dgemm(INTERP, alpha, A, B, beta, C); + multiply_matrices(INTERP, alpha, A, B, beta, C); RETURN(PMC* C); } @@ -1182,7 +1197,7 @@ Swap two rows */ METHOD row_combine(INTVAL srcidx, INTVAL destidx, FLOATVAL gain) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1198,7 +1213,7 @@ Swap two rows } METHOD row_scale(INTVAL idx, FLOATVAL gain) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1214,7 +1229,7 @@ Swap two rows METHOD row_swap(INTVAL idx_a, INTVAL idx_b) { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); FLOATVAL * const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -1256,7 +1271,7 @@ Get a PMCMatrix2D from the current matrix } METHOD convert_to_complex_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_ComplexMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); @@ -1271,7 +1286,7 @@ Get a PMCMatrix2D from the current matrix } METHOD convert_to_pmc_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_NumMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_PMCMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); diff --git a/src/pmc/pmcmatrix2d.pmc b/src/pmc/pmcmatrix2d.pmc index 6fc44c2..b9cf7a9 100644 --- a/src/pmc/pmcmatrix2d.pmc +++ b/src/pmc/pmcmatrix2d.pmc @@ -1,9 +1,6 @@ #include "pla.h" -#define ALLOCATE_STORAGE(s) (PMC **)mem_sys_allocate_zeroed(s * sizeof (PMC *)) #define PLATYPENAME "PMCMatrix2D" -#define DECLATTRS(p, a) Parrot_PMCMatrix2D_attributes * const (a) = \ - (Parrot_PMCMatrix2D_attributes *)((p)->data) INTVAL __PLA_Type_PMCMatrix2D; @@ -21,7 +18,7 @@ INTVAL __PLA_Type_PMCMatrix2D; static void resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) { - DECLATTRS(self, attrs); + DECLATTRS_PMCMatrix2D(self, attrs); /* Store the old values */ const INTVAL old_rows = attrs->rows; const INTVAL old_cols = attrs->cols; @@ -32,7 +29,7 @@ resize_matrix(PARROT_INTERP, PMC * self, INTVAL row, INTVAL col) const INTVAL new_rows = INDEX_MAX(old_rows, row + 1); const INTVAL new_cols = INDEX_MAX(old_cols, col + 1); const INTVAL newsize = new_rows * new_cols; - PMC ** new_s = ALLOCATE_STORAGE(newsize); + PMC ** new_s = ALLOCATE_STORAGE_PMCMatrix2D(newsize); INTVAL i, j; for (i = 0; i < old_rows; i++) { @@ -59,7 +56,7 @@ static void init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, INTVAL cols_size, PMC * values) { - DECLATTRS(self, attrs); + DECLATTRS_PMCMatrix2D(self, attrs); PMC ** s; INTVAL self_rows, self_cols, i, j, num = 0; const INTVAL init_elems = VTABLE_elements(interp, values); @@ -86,12 +83,12 @@ init_from_pmc_array(PARROT_INTERP, PMC * self, INTVAL rows_size, static void normalize_lazy_transpose(PARROT_INTERP, PMC * self) { - DECLATTRS(self, attrs); + DECLATTRS_PMCMatrix2D(self, attrs); if (IS_TRANSPOSED(attrs->flags)) { const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL size = rows_size * cols_size; - PMC ** const new_s = ALLOCATE_STORAGE(size); + PMC ** const new_s = ALLOCATE_STORAGE_PMCMatrix2D(size); PMC ** const old_s = attrs->storage; INTVAL i, j; @@ -119,7 +116,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { } VTABLE void init() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); attrs->storage = NULL; attrs->rows = 0; attrs->cols = 0; @@ -129,14 +126,14 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { } VTABLE void destroy() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC ** const s = attrs->storage; if (s) mem_sys_free(s); } VTABLE void mark() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC ** s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -152,7 +149,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { /* Get VTABLEs */ VTABLE PMC * get_pmc_keyed(PMC * key) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL cols, rows, cols_size, rows_size; cols_size = attrs->cols; rows_size = attrs->rows; @@ -164,7 +161,7 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { } VTABLE PMC * get_pmc_keyed_int(INTVAL key) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL total_size = attrs->cols * attrs->rows; if (key >= total_size || key < 0) { Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, @@ -208,7 +205,7 @@ TODO: Update all these to follow HLL mappings */ VTABLE void set_pmc_keyed(PMC * key, PMC * value) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL cols, rows, cols_size, rows_size; cols_size = attrs->cols; rows_size = attrs->rows; @@ -222,7 +219,7 @@ TODO: Update all these to follow HLL mappings } VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL total_size = attrs->cols * attrs->rows; if (key >= total_size || key < 0) { Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, @@ -268,7 +265,7 @@ TODO: Update all these to follow HLL mappings } VTABLE STRING *get_string() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL rows, cols; PMC * builder = Parrot_pmc_new(INTERP, enum_class_StringBuilder); STRING * const strend = Parrot_str_new(INTERP, "}", 1); @@ -300,7 +297,7 @@ TODO: Update all these to follow HLL mappings /* TODO: Update this to account for transpositions */ VTABLE PMC * get_attr_str(STRING * idx) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) { PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer); VTABLE_set_integer_native(INTERP, rows, attrs->rows); @@ -320,8 +317,8 @@ TODO: Update all these to follow HLL mappings } VTABLE INTVAL is_equal(PMC *other) { - DECLATTRS(SELF, attrs); - DECLATTRS(other, oattr); + DECLATTRS_PMCMatrix2D(SELF, attrs); + DECLATTRS_PMCMatrix2D(other, oattr); PMC ** const s = attrs->storage; PMC ** const o = oattr->storage; const INTVAL sflags = attrs->flags; @@ -354,8 +351,8 @@ TODO: Update all these to follow HLL mappings VTABLE PMC* clone() { PMC * const other = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS(SELF, attrs); - DECLATTRS(other, oattr); + DECLATTRS_PMCMatrix2D(SELF, attrs); + DECLATTRS_PMCMatrix2D(other, oattr); PMC ** s, ** o; INTVAL self_rows, self_cols, i, j, o_rows, o_cols; @@ -390,7 +387,7 @@ TODO: Update all these to follow HLL mappings */ VTABLE void freeze(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL const rows = attrs->rows; INTVAL const cols = attrs->cols; INTVAL const flags = attrs->flags; @@ -408,7 +405,7 @@ TODO: Update all these to follow HLL mappings } VTABLE void thaw(PMC *info) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL const rows = VTABLE_shift_integer(INTERP, info); INTVAL const cols = VTABLE_shift_integer(INTERP, info); INTVAL const flags = VTABLE_shift_integer(INTERP, info); @@ -456,7 +453,7 @@ sizes, growing the matrix if needed. INTVAL x_size :optional, INTVAL has_rows_size :opt_flag, INTVAL y_size :optional, INTVAL has_cols_size :opt_flag ) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC ** s = attrs->storage; INTVAL const curr_rows_size = attrs->rows; INTVAL const curr_cols_size = attrs->cols; @@ -495,7 +492,7 @@ sizes, growing the matrix if needed. METHOD item_at(INTVAL row, INTVAL col, PMC * value :optional, INTVAL has_value :opt_flag) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; const INTVAL flags = attrs->flags; @@ -522,7 +519,7 @@ Transposes the matrix. */ METHOD transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL tmp = 0; INTVAL transposed = IS_TRANSPOSED(attrs->flags); @@ -548,11 +545,11 @@ than the transpose() method. */ METHOD mem_transpose() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL newsize = rows_size * cols_size; - PMC ** new_s = ALLOCATE_STORAGE(newsize); + PMC ** new_s = ALLOCATE_STORAGE_PMCMatrix2D(newsize); PMC ** old_s = attrs->storage; INTVAL i, j; @@ -580,12 +577,12 @@ value with the return value of the called function. */ METHOD iterate_function_inplace(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL newsize = rows_size * cols_size; PMC ** old_s = attrs->storage; - PMC ** new_s = ALLOCATE_STORAGE(newsize); + PMC ** new_s = ALLOCATE_STORAGE_PMCMatrix2D(newsize); INTVAL i, j; if (newsize == 0 || old_s == NULL) @@ -605,9 +602,9 @@ value with the return value of the called function. } METHOD iterate_function_external(PMC * func, PMC * args :slurpy) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC * const new_matrix = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS(new_matrix, new_attrs); + DECLATTRS_PMCMatrix2D(new_matrix, new_attrs); const INTVAL rows_size = attrs->rows; const INTVAL cols_size = attrs->cols; const INTVAL newsize = rows_size * cols_size; @@ -636,7 +633,7 @@ value with the return value of the called function. METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, INTVAL cols_size) { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC ** const s = attrs->storage; const INTVAL rows = attrs->rows; const INTVAL cols = attrs->cols; @@ -668,8 +665,8 @@ value with the return value of the called function. } METHOD set_block(INTVAL rows_idx, INTVAL cols_idx, PMC * blck) { - DECLATTRS(SELF, self_attrs); - DECLATTRS(blck, blck_attrs); + DECLATTRS_PMCMatrix2D(SELF, self_attrs); + DECLATTRS_PMCMatrix2D(blck, blck_attrs); PMC ** self_s = self_attrs->storage; PMC ** const blck_s = blck_attrs->storage; INTVAL self_rows = self_attrs->rows; @@ -721,7 +718,7 @@ Get a PMCMatrix2D from the current matrix */ METHOD convert_to_number_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_NumMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); @@ -736,7 +733,7 @@ Get a PMCMatrix2D from the current matrix } METHOD convert_to_complex_matrix() { - DECLATTRS(SELF, attrs); + DECLATTRS_PMCMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_ComplexMatrix2D); const INTVAL totalsize = attrs->rows * attrs->cols; PMC * const meth = VTABLE_find_method(INTERP, d, CONST_STRING(INTERP, "resize")); From b39eb159cf208c0581a8ef72e05b8da9499ded5d Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Tue, 24 Aug 2010 10:13:45 -0400 Subject: [PATCH 2/8] Allow binding to the regular (FORTRAN) libblas-3.so. In this case, we don't have cblas.h, so we don't probe for that file in setup.nqp, and we have to define our own bindings in pla_blas.h. Notice that these bindings are different from the bindings provided by cblas/atlas --- setup.nqp | 54 ++++++++++++++++++----------- src/include/pla_blas.h | 62 ++++++++++++++-------------------- src/include/pla_matrix_types.h | 1 - src/lib/pla_blas.c | 55 +++++++++++++++++++++++++----- 4 files changed, 106 insertions(+), 66 deletions(-) diff --git a/setup.nqp b/setup.nqp index 8ec6995..58fe19c 100755 --- a/setup.nqp +++ b/setup.nqp @@ -31,8 +31,8 @@ sub MAIN(@argv) { $mode := @argv[0]; } if $mode eq "build" { - probe_for_cblas(%PLA); find_blas(%PLA); + probe_for_cblas_h(%PLA); find_lapack(%PLA); } if $mode eq "test" { @@ -69,15 +69,18 @@ sub setup_PLA_keys(%PLA) { %PLA{'inst_lib'} := new_array(); %PLA{'pir_pir'} := new_hash(); %PLA{'pir_pir'}{'t/testlib/pla_test.pir'} := new_array(); + %PLA{'need_cblas_h'} := 0; } # -sub probe_for_cblas(%PLA) { - if probe_include("cblas.h", :verbose(1)) { - pir::say("Cannot find cblas.h\nPlease install libatlas-base-dev"); - pir::exit__vI(1); - } else { - %PLA{'dynpmc_cflags_list'}.push("-D_PLA_HAVE_CBLAS_H"); +sub probe_for_cblas_h(%PLA) { + if %PLA{'need_cblas_h'} { + if probe_include("cblas.h", :verbose(1)) { + pir::say("Cannot find cblas.h. This is required if you are using CBLAS or ATLAS"); + pir::exit(1); + } else { + %PLA{'dynpmc_cflags_list'}.push("-D_PLA_HAVE_CBLAS_H"); + } } } @@ -86,19 +89,7 @@ sub find_blas(%PLA) { my $osname := %config{'osname'}; my $found_blas := 0; if $osname eq 'linux' { - my %searches; - %searches{'/usr/lib/libblas.so'} := ['-lblas', '-D_PLA_HAVE_ATLAS']; - %searches{'/usr/lib/atlas/libcblas.so'} := ['-L/usr/lib/atlas -lcblas', '-D_PLA_HAVE_ATLAS']; - for %searches { - my $searchloc := $_; - my $test_ldd := pir::spawnw__IS('ldd ' ~ $searchloc); - if $test_ldd == 0 { - $found_blas := 1; - %PLA{'dynpmc_ldflags_list'}.push(%searches{$searchloc}[0]); - %PLA{'dynpmc_cflags_list'}.push(%searches{$searchloc}[1]); - return; - } - } + $found_blas := find_blas_linux(%PLA); } else { pir::say("Only Linux is currently supported"); @@ -110,6 +101,29 @@ sub find_blas(%PLA) { } } +sub find_blas_linux(%PLA) { + my $found_blas := 0; + my %searches; + # TODO: We should search in /usr/lib and /usr/local/lib for each + %searches{'/usr/lib/libblas-3.so'} := ['-lblas-3', '-D_PLA_HAVE_BLAS', 0]; + %searches{'/usr/lib/libblas.so'} := ['-lblas', '-D_PLA_HAVE_ATLAS', 1]; + %searches{'/usr/lib/atlas/libcblas.so'} := ['-L/usr/lib/atlas -lcblas', '-D_PLA_HAVE_ATLAS', 1]; + for %searches { + my $searchloc := $_; + my $test_ldd := pir::spawnw__IS('ldd ' ~ $searchloc); + if $test_ldd == 0 { + $found_blas := 1; + my @options := %searches{$searchloc}; + %PLA{'dynpmc_ldflags_list'}.push(@options[0]); + %PLA{'dynpmc_cflags_list'}.push(@options[1]); + %PLA{'need_cblas_h'} := @options[2]; + pir::say("=== PLA: Using BLAS library $searchloc"); + return $found_blas; + } + } + return $found_blas; +} + sub find_lapack(%PLA) { my %config := get_config(); my $osname := %config{'osname'}; diff --git a/src/include/pla_blas.h b/src/include/pla_blas.h index e1e5b1e..e1a8813 100644 --- a/src/include/pla_blas.h +++ b/src/include/pla_blas.h @@ -5,59 +5,47 @@ need to manually write bindings for that */ #ifdef _PLA_HAVE_CBLAS_H # include -# define dgemm cblas_dgemm -# define zgemm cblas_zgemm +# define PLA_HAVE_CBLAS +# define IS_TRANSPOSED_BLAS(flags) (IS_TRANSPOSED(flags) ? CblasTrans : CblasNoTrans) #else +# define IS_TRANSPOSED_BLAS(flags) (IS_TRANSPOSED(flags) ? "T" : "N") +# ifdef PLA_HAVE_CBLAS +# undef PLA_HAVE_CBLAS +# endif /* Define manual mappings to the BLAS library here, and map them to the same function names that would be used by ATLAS/cblas.h */ -/* Using the same names for these enums as cblas.h does, so that we can be - transparent between the two */ -typedef enum CBLAS_ORDER_ { - CblasRowMajor = 101, - CblasColMajor=102 -} CBLAS_ORDER; - -typedef enum CBLAS_TRANSPOSE_ { - CblasNoTrans = 111, - CblasTrans = 112, - CblasConjTrans = 113 -} CBLAS_TRANSPOSE; - extern void dgemm_( - const CBLAS_ORDER Order, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const int M, - const int N, - const int K, - const double alpha, + const void *TransA, + const void *TransB, + const void *M, + const void *N, + const void *K, + const double *alpha, const double *A, - const int lda, + const void *lda, const double *B, - const int ldb, - const double beta, + const void *ldb, + const double *beta, double *C, - const int ldc + const void *ldc ); -#define dgemm dgemm_ extern void zgemm_( - const CBLAS_ORDER Order, - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const int M, - const int N, - const int K, + const void *TransA, + const void *TransB, + const void *M, + const void *N, + const void *K, const void *alpha, const void *A, - const int lda, + const void *lda, const void *B, - const int ldb, + const void *ldb, const void *beta, void *C, - const int ldc + const void *ldc ); # endif /* _PLA_HAVE_CBLAS_H */ @@ -78,4 +66,6 @@ void call_zgemm( FLOATVAL * C ); + + #endif /* _PLA_BLAS_H_ */ diff --git a/src/include/pla_matrix_types.h b/src/include/pla_matrix_types.h index 356d666..12b08c7 100644 --- a/src/include/pla_matrix_types.h +++ b/src/include/pla_matrix_types.h @@ -178,6 +178,5 @@ do { \ #define IS_DIAGONAL(flags) ((((flags) & (FLAG_DIAGONAL)) == FLAG_DIAGONAL)) #define IS_TRIDIAGONAL(flags) (((flags) & (FLAG_TRIDIAGONAL))) #define IS_TRANSPOSED(flags) (((flags) & (FLAG_TRANSPOSED))) -#define IS_TRANSPOSED_BLAS(flags) (IS_TRANSPOSED(flags) ? CblasTrans : CblasNoTrans) #endif /* _PLA_MATRIX_TYPES_H_ */ diff --git a/src/lib/pla_blas.c b/src/lib/pla_blas.c index 5b8ba6e..0d69fa8 100644 --- a/src/lib/pla_blas.c +++ b/src/lib/pla_blas.c @@ -4,16 +4,17 @@ A, B, and C are all NumMatrix2D. */ void call_dgemm(FLOATVAL alpha, - INTVAL flags_A, FLOATVAL * A, INTVAL rows_A, INTVAL cols_A, - INTVAL flags_B, FLOATVAL * B, INTVAL cols_B, + INTVAL flags_a, FLOATVAL * A, INTVAL rows_a, INTVAL cols_a, + INTVAL flags_b, FLOATVAL * B, INTVAL cols_b, FLOATVAL beta, FLOATVAL * C) { - const INTVAL M = rows_A; - const INTVAL N = cols_B; - const INTVAL K = cols_A; - dgemm(CblasRowMajor, - IS_TRANSPOSED_BLAS(flags_A), - IS_TRANSPOSED_BLAS(flags_B), + const INTVAL M = rows_a; + const INTVAL N = cols_b; + const INTVAL K = cols_a; +#ifdef PLA_HAVE_CBLAS + cblas_dgemm(CblasRowMajor, + IS_TRANSPOSED_BLAS(flags_a), + IS_TRANSPOSED_BLAS(flags_b), M, N, K, @@ -26,6 +27,23 @@ call_dgemm(FLOATVAL alpha, C, M ); +#else + dgemm_( + IS_TRANSPOSED_BLAS(flags_a), + IS_TRANSPOSED_BLAS(flags_b), + &M, + &N, + &K, + &alpha, + A, + &M, + B, + &N, + &beta, + C, + &M + ); +#endif } /* Wrapper to call the zdgemm function from BLAS with PMC arguments. Assumes @@ -46,7 +64,9 @@ call_zgemm(FLOATVAL alpha_r, FLOATVAL alpha_i, alpha_p[1] = alpha_i; beta_p[0] = beta_r; beta_p[1] = beta_i; - zgemm(CblasRowMajor, + +#ifdef PLA_HAVE_CBLAS + cblas_zgemm(CblasRowMajor, IS_TRANSPOSED_BLAS(flags_a), IS_TRANSPOSED_BLAS(flags_b), M, @@ -61,5 +81,22 @@ call_zgemm(FLOATVAL alpha_r, FLOATVAL alpha_i, C, M ); +#else + zgemm_( + IS_TRANSPOSED_BLAS(flags_a), + IS_TRANSPOSED_BLAS(flags_b), + &M, + &N, + &K, + alpha_p, + A, + &M, + B, + &N, + beta_p, + C, + &M + ); +#endif } From c20c635c98d61a5e9e7fc3c66cdf6188f919d44b Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 09:25:22 -0400 Subject: [PATCH 3/8] start improving POD for the ComplexMatrix2D type. --- src/pmc/complexmatrix2d.pmc | 354 ++++++++++++++++++++++++++++-------- 1 file changed, 279 insertions(+), 75 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index 849b445..a6cd652 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -46,7 +46,8 @@ convert_to_ComplexMatrix2D(PARROT_INTERP, PMC * p, INTVAL forcecopy) Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS, PLATYPENAME ": cannot convert unknown PMC type"); else { - PMC * const meth = VTABLE_find_method(interp, p, CONST_STRING(interp, "convert_to_complex_matrix")); + STRING * const converter = CONST_STRING(interp, "convert_to_complex_matrix"); + PMC * const meth = VTABLE_find_method(interp, p, converter); PMC * dest = PMCNULL; Parrot_ext_call(interp, meth, "Pi->P", p, &dest); return dest; @@ -289,6 +290,7 @@ multiply_matrices(PARROT_INTERP, FLOATVAL alpha_r, FLOATVAL alpha_i, PMC * A, /* item-by-item addition or subtraction A = A + B */ +// TODO: Support adding other types of matrices here, also. static void add_matrices(PARROT_INTERP, PMC * A, PMC * B, INTVAL sub) { @@ -342,6 +344,14 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix =item* init +Initialize the new PMC + +=item* destroy + +Destroy the PMC and free all associated memory + +=back + =cut */ @@ -364,14 +374,44 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix /* +=head2 Keyed lookup VTABLEs + +In each of these cases, the specified Key PMC must have exactly two elements +to specify a location in the matrix. + +Attempting to retrieve a value outside the boundaries of the matrix will throw +an OUT_OF_BOUNDS exception. + +=over 4 + =item* get_number_keyed +Get a floating point value at the location specified by the key. + +The floating point value is calculated as the magnitude of the complex value +at the point in the matrix. + =item* get_integer_keyed +Get an integer value at the location specified by the key. + +The integer value is the magnitude of the complex value at the specified +location, cast from a floating point to an integer value. + =item* get_string_keyed +Get the string representation of the complex value at the point specified by +the key. + +The returned string has the same format as is used by the Parrot built-in +Complex PMC type. + =item* get_pmc_keyed +Get a Complex PMC from the point specified by the key. + +=back + =cut */ @@ -391,29 +431,11 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix return sqrt(real * real + imag + imag); } - VTABLE FLOATVAL get_number_keyed_int(INTVAL key) { - DECLATTRS_ComplexMatrix2D(SELF, attrs); - const INTVAL totalsize = attrs->rows * attrs->cols; - FLOATVAL real, imag; - if (key >= totalsize || key < 0) { - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, - PLATYPENAME ": Index out of bounds."); - } - real = attrs->storage[key * 2]; - imag = attrs->storage[key * 2 + 1]; - return sqrt(real * real + imag * imag); - } - VTABLE INTVAL get_integer_keyed(PMC * key) { const FLOATVAL f = VTABLE_get_number_keyed(INTERP, SELF, key); return (INTVAL)f; } - VTABLE INTVAL get_integer_keyed_int(INTVAL key) { - const FLOATVAL f = VTABLE_get_number_keyed_int(INTERP, SELF, key); - return (INTVAL)f; - } - VTABLE STRING * get_string_keyed(PMC * key) { DECLATTRS_ComplexMatrix2D(SELF, attrs); const INTVAL rows_size = attrs->rows; @@ -431,6 +453,65 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix return Parrot_sprintf_c(INTERP, "%vg%+vgi", real, imag); } + VTABLE PMC * get_pmc_keyed(PMC * key) { + INTVAL rows, cols; + GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols); + return get_complex_pmc_at_xy(INTERP, SELF, rows, cols); + } + +/* + +=head2 Integer-Keyed Lookup VTABLES + +These VTABLEs treat the matrix, which is a contiguous region in memory, as a +linear array of values. The matrix data is stored by rows. + +These routines are used for low-level access. Attempting to access a value +outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. + +=item* get_number_keyed_int + +Get a floating point number, the magnitude of the complex value, at the +specified location in the array + +=item* get_integer_keyed_int + +Get an integer, cast from the magnitude of the complex value, at the specified +location in the array + +=item* get_string_keyed_int + +Get a string representation of the value at the specified point. Stringification +is done the same as Parrot's Complex PMC type. + +=item* get_pmc_keyed_int + +Get a Complex PMC from the value at the specified point. + +=back + +=cut + +*/ + + VTABLE FLOATVAL get_number_keyed_int(INTVAL key) { + DECLATTRS_ComplexMatrix2D(SELF, attrs); + const INTVAL totalsize = attrs->rows * attrs->cols; + FLOATVAL real, imag; + if (key >= totalsize || key < 0) { + Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": Index out of bounds."); + } + real = attrs->storage[key * 2]; + imag = attrs->storage[key * 2 + 1]; + return sqrt(real * real + imag * imag); + } + + VTABLE INTVAL get_integer_keyed_int(INTVAL key) { + const FLOATVAL f = VTABLE_get_number_keyed_int(INTERP, SELF, key); + return (INTVAL)f; + } + VTABLE STRING * get_string_keyed_int(INTVAL key) { DECLATTRS_ComplexMatrix2D(SELF, attrs); FLOATVAL real, imag; @@ -444,12 +525,6 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix return Parrot_sprintf_c(INTERP, "%vg%+vgi", real, imag); } - VTABLE PMC * get_pmc_keyed(PMC * key) { - INTVAL rows, cols; - GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols); - return get_complex_pmc_at_xy(INTERP, SELF, rows, cols); - } - VTABLE PMC * get_pmc_keyed_int(INTVAL key) { DECLATTRS_ComplexMatrix2D(SELF, attrs); INTVAL row, col; @@ -459,10 +534,39 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix /* +=head2 Keyed Setter VTABLES + +These VTABLEs insert new values into the matrix at a point specified by the +Key PMC. The Key PMC must have exactly two elements. If the matrix is not large +enough to accomodate the specified location, it will be grown with zero-padding +so that it is at least large enough to hold the specified point and all existing +data. + +=over 4 + =item* set_pmc_keyed +Set the value at the specified location to the complex value represented by the +given PMC. Different PMC types have different behaviors in this operation. + +=item* set_number_keyed + +Set the value at the specified location to have a real value given by the +number, and 0 for the complex value. + =item* set_string_keyed +Set the value at the specified location to the value represented by the string. +The string is parsed by creating a temporary Complex PMC type, so all the same +rules for that type apply to the input string format. + +=item* set_integer_keyed + +Set the value at the specified location to have a real value given by the +integer, and 0 for the complex value. + +=back + =cut */ @@ -473,26 +577,12 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix set_complex_pmc_at_xy(INTERP, SELF, value, rows, cols); } - VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { - DECLATTRS_ComplexMatrix2D(SELF, attrs); - INTVAL row, col; - intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); - set_complex_pmc_at_xy(INTERP, SELF, value, row, col); - } - VTABLE void set_number_keyed(PMC * key, FLOATVAL value) { INTVAL rows, cols; GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols); set_scalar_at_xy(INTERP, SELF, value, rows, cols); } - VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { - DECLATTRS_ComplexMatrix2D(SELF, attrs); - INTVAL row, col; - intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); - set_scalar_at_xy(INTERP, SELF, value, row, col); - } - VTABLE void set_string_keyed(PMC * key, STRING * value) { PMC * const item = Parrot_pmc_new(INTERP, enum_class_Complex); VTABLE_set_string_native(INTERP, item, value); @@ -503,6 +593,48 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix VTABLE_set_number_keyed(INTERP, SELF, key, (FLOATVAL)value); } +/* + +=head2 Integer-Keyed Setter VTABLEs + +These VTABLEs treat the matrix as a linear array in memory and allowed fast +lookup based on the integer offset of values in the array. These are low-level +routines and are not intended for general use. + +Unlike the PMC-keyed VTABLEs, these routines will not automatically grow the +matrix if an index is provided which is outside the boundaries of the matrix. +In that case, an OUT_OF_BOUNDS exception will be thrown. + +=over 4 + +=item* set_pmc_keyed_int + +=item* set_number_keyed_int + +=item* set_integer_keyed_int + +=item* set_string_keyed_int + +=back + +=cut + +*/ + + VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { + DECLATTRS_ComplexMatrix2D(SELF, attrs); + INTVAL row, col; + intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); + set_complex_pmc_at_xy(INTERP, SELF, value, row, col); + } + + VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { + DECLATTRS_ComplexMatrix2D(SELF, attrs); + INTVAL row, col; + intkey_to_coords(INTERP, attrs->rows, attrs->cols, key, &row, &col); + set_scalar_at_xy(INTERP, SELF, value, row, col); + } + VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) { VTABLE_set_number_keyed_int(INTERP, SELF, key, (FLOATVAL)value); } @@ -517,8 +649,20 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix /* +=head2 Miscellaneous VTABLEs + +=over 4 + =item* get_string +=item* get_attr_string + +=item* clone + +=item* is_equal + +=back + =cut */ @@ -640,10 +784,16 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix /* +=head2 Serialization/Deserialization VTABLEs + +=over 4 + =item* freeze =item* thaw +=back + =cut */ @@ -694,10 +844,16 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix /* +=head2 Addition VTABLEs + +=over 4 + =item* add(ComplexMatrix2D) Add two matrices together, element-by-element. +=item* add(Complex) + =item* add(DEFAULT) Take the number representation of the argument PMC and add it to every element @@ -711,6 +867,8 @@ Add the float value to every element in the matrix. Add the integer value to every element in the matrix. +=back + =cut */ @@ -748,14 +906,22 @@ Add the integer value to every element in the matrix. /* +=head2 In-Place Addition VTABLEs + +=over 4 + =item* i_add(ComplexMatrix2D) +=item* i_add(Complex) + =item* i_add(DEFAULT) =item* i_add_int =item* i_add_float +=back + =cut */ @@ -783,10 +949,16 @@ Add the integer value to every element in the matrix. /* +=head2 Subtraction VTABLEs + +=over 4 + =item* subtract(ComplexMatrix2D) Add two matrices together, element-by-element. +=item* subtract(Complex) + =item* subtract(DEFAULT) Take the number representation of the argument PMC and add it to every element @@ -800,6 +972,8 @@ Add the float value to every element in the matrix. Add the integer value to every element in the matrix. +=back + =cut */ @@ -838,14 +1012,22 @@ Add the integer value to every element in the matrix. /* +=head2 In-Place Subtraction VTABLEs + +=over 4 + =item* i_subtract(ComplexMatrix2D) +=item* i_subtract(Complex) + =item* i_subtract(DEFAULT) =item* i_subtract_int =item* i_subtract_float +=back + =cut */ @@ -873,10 +1055,22 @@ Add the integer value to every element in the matrix. /* +=head2 Multiplication VTABLEs + +=over 4 + =item* multiply(ComplexMatrix2D) +=item* multiply(Complex) + =item* multiply(DEFAULT) +=item* multiply_int + +=item* multiply_float + +=back + =cut */ @@ -911,16 +1105,6 @@ Add the integer value to every element in the matrix. return dest; } -/* - -=item* multiply_int - -=item* multiply_float - -=cut - -*/ - VTABLE PMC *multiply_int(INTVAL v, PMC * dest) { dest = VTABLE_clone(INTERP, SELF); multiply_scalar_float(INTERP, dest, (FLOATVAL)v); @@ -935,10 +1119,22 @@ Add the integer value to every element in the matrix. /* -=item* i_multiply(NumMatrix2D) +=head2 In-Place Multiplication VTABLEs + +=over 4 + +=item* i_multiply(ComplexMatrix2D) + +=item* i_multiply(Complex) =item* i_multiply(DEFAULT) +=item* i_multiply_int + +=item* i_multiply_float + +=back + =cut */ @@ -957,16 +1153,6 @@ Add the integer value to every element in the matrix. multiply_scalar_float(INTERP, SELF, v); } -/* - -=item i_multiply_int - -=item i_multiply_float - -=cut - -*/ - VTABLE void i_multiply_int(INTVAL v) { multiply_scalar_float(INTERP, SELF, (FLOATVAL)v); } @@ -978,13 +1164,11 @@ Add the integer value to every element in the matrix. /* -=back - =head1 METHODS =over 4 -=item resize() +=item* resize() =cut @@ -996,7 +1180,7 @@ Add the integer value to every element in the matrix. /* -=item fill() +=item* fill() Fill the matrix with a single value. if sizes are provided, fill to those sizes, growing the matrix if needed. @@ -1036,7 +1220,7 @@ sizes, growing the matrix if needed. /* -=item item_at() +=item* item_at() =cut @@ -1063,7 +1247,7 @@ sizes, growing the matrix if needed. /* -=item transpose() +=item* transpose() Transposes the matrix. @@ -1088,7 +1272,7 @@ Transposes the matrix. /* -=item mem_transpose() +=item* mem_transpose() Transposes the actual data storage of the matrix. More expensive up-front than the transpose() method. @@ -1122,7 +1306,7 @@ than the transpose() method. /* -=item conjugate +=item* conjugate =cut @@ -1146,11 +1330,13 @@ than the transpose() method. /* -=item iterate_function_inplace() +=item* iterate_function_inplace() Calls a function for every element in the array, replacing the current value with the return value of the called function. +=item* iterate_function_external() + =cut */ @@ -1192,6 +1378,16 @@ value with the return value of the called function. RETURN(PMC * new_matrix); } +/* + +=item* initialize_from_array + +=item* initialize_from_args + +=cut + +*/ + METHOD initialize_from_array(INTVAL rows_size, INTVAL cols_size, PMC *values) { init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); @@ -1202,6 +1398,14 @@ value with the return value of the called function. init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); } +/* + +=item* get_block + +=item* set_block + +*/ + METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, INTVAL cols_size) { DECLATTRS_ComplexMatrix2D(SELF, attrs); @@ -1299,15 +1503,15 @@ Calculates the matrix equation: /* -=item row_combine(srcidx, destidx, gain) +=item* row_combine(srcidx, destidx, gain) add a multiple of the source row to the destination row. -=item row_scale(idx, gain) +=item* row_scale(idx, gain) Multiply all elements in the row by a gain factor. -=item row_swap(idx_a, idx_b) +=item* row_swap(idx_a, idx_b) Swap two rows @@ -1373,15 +1577,15 @@ Swap two rows /* -=item convert_to_number_matrix +=item* convert_to_number_matrix Get a NumMatrix2D from the current matrix -=item convert_to_complex_matrix +=item* convert_to_complex_matrix Get a ComplexMatrix2D from the current matrix -=item convert_to_pmc_matrix +=item* convert_to_pmc_matrix Get a PMCMatrix2D from the current matrix From 973a792b5e725dc7b8beee89dd39d1cf0116e3b6 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 09:57:26 -0400 Subject: [PATCH 4/8] finish the documentation for ComplexMatrix2D.pmc --- src/pmc/complexmatrix2d.pmc | 141 ++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 14 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index a6cd652..67ddddd 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -597,7 +597,7 @@ integer, and 0 for the complex value. =head2 Integer-Keyed Setter VTABLEs -These VTABLEs treat the matrix as a linear array in memory and allowed fast +These VTABLEs treat the matrix as a linear array in memory and allow fast lookup based on the integer offset of values in the array. These are low-level routines and are not intended for general use. @@ -609,12 +609,23 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =item* set_pmc_keyed_int +Set a PMC at the specified location. The rules for extracting a complex value +out of the input PMC are the same as used for set_pmc_keyed() + =item* set_number_keyed_int +Set the complex value at the specified location to the given real value. The +complex part of the value will be 0. + =item* set_integer_keyed_int +Set the complex value at the specified location to the given real value. The +complex part of the value will be 0 + =item* set_string_keyed_int +Convert the string to a Complex PMC, and set that at the specified location. + =back =cut @@ -655,12 +666,20 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =item* get_string +Get a string representation of the matrix, suitable for printing to the console + =item* get_attr_string +Get a named attribute. The name can be one of "rows", "cols", or "size". + =item* clone +Clone the matrix + =item* is_equal +Determine if two matrices are equal in size and composition. + =back =cut @@ -790,8 +809,13 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =item* freeze +Freeze the PMC for serialization to a string suitable for long-term storage in +a file. + =item* thaw +Thaw a serialized PMC + =back =cut @@ -854,6 +878,8 @@ Add two matrices together, element-by-element. =item* add(Complex) +Add a complex value to each element of the matrix + =item* add(DEFAULT) Take the number representation of the argument PMC and add it to every element @@ -912,14 +938,24 @@ Add the integer value to every element in the matrix. =item* i_add(ComplexMatrix2D) +Add a matrix into SELF + =item* i_add(Complex) +Add a Complex value to every element of SELF + =item* i_add(DEFAULT) +Add the numeric value of the given PMC to every element of SELF + =item* i_add_int +Add the integer value to every element of SELF + =item* i_add_float +Add the floating-point value to every element of SELF + =back =cut @@ -955,22 +991,26 @@ Add the integer value to every element in the matrix. =item* subtract(ComplexMatrix2D) -Add two matrices together, element-by-element. +Perform the matrix operation + + C = SELF - A =item* subtract(Complex) +Subtract a complex value from each element of the matrix + =item* subtract(DEFAULT) -Take the number representation of the argument PMC and add it to every element -in the matrix. +Take the number representation of the argument PMC and subtract it from every +element in the matrix. =item* subtract_float -Add the float value to every element in the matrix. +Subtract the float value from every element in the matrix. =item* subtract_int -Add the integer value to every element in the matrix. +Subtract the integer value from every element in the matrix. =back @@ -1018,14 +1058,28 @@ Add the integer value to every element in the matrix. =item* i_subtract(ComplexMatrix2D) +Perform the matrix operation + + SELF = SELF - A + =item* i_subtract(Complex) +Substract a complex value from each element of the matrix + =item* i_subtract(DEFAULT) +Subtract the numeric value of the PMC from the real part of each element in the +matrix + =item* i_subtract_int +Subtract the integer value from the real part of each element in the matrix + =item* i_subtract_float +Subtract the floating point value from the real part of each element in the +matrix + =back =cut @@ -1061,14 +1115,26 @@ Add the integer value to every element in the matrix. =item* multiply(ComplexMatrix2D) +Perform the matrix operation + + C = SELF × A + =item* multiply(Complex) +Multiply each element in the matrix by the complex value + =item* multiply(DEFAULT) +Multiply each element in the matrix by the numeric value of the PMC + =item* multiply_int +Multiply each element in the matrix by the integer + =item* multiply_float +Multiply each element in the matrix by the floating point number + =back =cut @@ -1125,14 +1191,26 @@ Add the integer value to every element in the matrix. =item* i_multiply(ComplexMatrix2D) +Perform the matrix operation + + SELF = SELF × A + =item* i_multiply(Complex) +Multiply every element in SELF by the complex value + =item* i_multiply(DEFAULT) +Multiply every element in SELF by the numeric value of the PMC + =item* i_multiply_int +Multiply every element in SELF by the integer + =item* i_multiply_float +Multiply every element in SELF by the floating point number + =back =cut @@ -1170,6 +1248,11 @@ Add the integer value to every element in the matrix. =item* resize() +Resize the matrix to include at least the specified number of rows and columns. + +Resizing the matrix never causes the matrix to shrink. If you need a subset of +the matrix, use get_block instead. + =cut */ @@ -1183,7 +1266,8 @@ Add the integer value to every element in the matrix. =item* fill() Fill the matrix with a single value. if sizes are provided, fill to those -sizes, growing the matrix if needed. +sizes, growing the matrix if needed. Elements outside the specified area are +unaffected. Calling fill() never causes the matrix to shrink. =cut @@ -1222,6 +1306,8 @@ sizes, growing the matrix if needed. =item* item_at() +Return a single Complex PMC from the item at the specified coordinates + =cut */ @@ -1249,7 +1335,10 @@ sizes, growing the matrix if needed. =item* transpose() -Transposes the matrix. +Transposes the matrix lazily. This operation is O(n). Some operations, such as +mathematical operations do not work on a matrix which has been lazily +transposed, so those operations will force the matrix memory to be eagerly +transposed. =cut @@ -1275,7 +1364,8 @@ Transposes the matrix. =item* mem_transpose() Transposes the actual data storage of the matrix. More expensive up-front -than the transpose() method. +than the transpose() method, but the resulting memory structure is more suitable +for use in certain mathematical operations. =cut @@ -1308,6 +1398,8 @@ than the transpose() method. =item* conjugate +Convert the matrix to the complex conjugate of itself. + =cut */ @@ -1332,11 +1424,14 @@ than the transpose() method. =item* iterate_function_inplace() -Calls a function for every element in the array, replacing the current +Calls a function for every element in the matrix, replacing the current value with the return value of the called function. =item* iterate_function_external() +Calls a function for every element in the matrix, creating a new matrix with +the returned values of the called function. + =cut */ @@ -1382,8 +1477,12 @@ value with the return value of the called function. =item* initialize_from_array +Initialize the matrix using a list of values from an array. + =item* initialize_from_args +Initialize the matrix using values from a variadic (slurpy) argument list. + =cut */ @@ -1402,8 +1501,15 @@ value with the return value of the called function. =item* get_block +Get a specified sub-block of the matrix. If the bounds of the sub-block are +outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. + =item* set_block +Set a block in the matrix, growing it if needed. + +=cut + */ METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, @@ -1486,6 +1592,10 @@ Calculates the matrix equation: Z = aAB + bC +The matrices must all be ComplexMatrix2D, or must be convertable to it. The +matrix SELF is not used in the calculation, but the result matrix will have the +same type as SELF. + =cut */ @@ -1505,7 +1615,7 @@ Calculates the matrix equation: =item* row_combine(srcidx, destidx, gain) -add a multiple of the source row to the destination row. +Add a multiple of the source row to the destination row. =item* row_scale(idx, gain) @@ -1579,15 +1689,18 @@ Swap two rows =item* convert_to_number_matrix -Get a NumMatrix2D from the current matrix +Get a NumMatrix2D from the current matrix. If the matrix is already a +NumMatrix2D, return a clone. =item* convert_to_complex_matrix -Get a ComplexMatrix2D from the current matrix +Get a ComplexMatrix2D from the current matrix. If the matrix is already a +ComplexMatrix2D, return a clone. =item* convert_to_pmc_matrix -Get a PMCMatrix2D from the current matrix +Get a PMCMatrix2D from the current matrix. If the matrix is already a +PMCMatrix2D, return a clone. =cut From 0d73c5bf0b1d5d21a68240955a4f96fd9d016637 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 11:10:26 -0400 Subject: [PATCH 5/8] update documentation in NumMatrix2D, and make some fixes/improvements back to ComplexMatrix2D --- src/pmc/complexmatrix2d.pmc | 14 +- src/pmc/nummatrix2d.pmc | 511 +++++++++++++++++++++++------------- 2 files changed, 333 insertions(+), 192 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index 67ddddd..fe72ebd 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -340,6 +340,8 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix =head1 VTABLEs +=head System VTABLEs + =over 4 =item* init @@ -469,6 +471,8 @@ linear array of values. The matrix data is stored by rows. These routines are used for low-level access. Attempting to access a value outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. +=over 4 + =item* get_number_keyed_int Get a floating point number, the magnitude of the complex value, at the @@ -1615,15 +1619,19 @@ same type as SELF. =item* row_combine(srcidx, destidx, gain) -Add a multiple of the source row to the destination row. +add a multiple of the source row to the destination row. If either of the row +indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is +thrown. =item* row_scale(idx, gain) -Multiply all elements in the row by a gain factor. +Multiply all elements in the row by a gain factor. If the row index is outside +the bounds of the matrix and OUT_OF_BOUNDS exception is thrown. =item* row_swap(idx_a, idx_b) -Swap two rows +Swap two rows. If either of the row indices are outside the bounds of the +matrix, an OUT_OF_BOUNDS exception is thrown. =cut diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index 769edf1..90263f8 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -217,6 +217,8 @@ pmclass NumMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix { =head1 VTABLEs +=head2 System VTABLEs + =over 4 =item* init @@ -227,6 +229,8 @@ Create a new NumMatrix2D Destrow the matrix and free it's allocated storage +=back + =cut */ @@ -249,6 +253,16 @@ Destrow the matrix and free it's allocated storage /* +=head2 Keyed Lookup VTABLEs + +In each of these cases, the specified Key PMC must have exactly two elements +to specify a location in the matrix. + +Attempting to retrieve a value outside the boundaries of the matrix will throw +an OUT_OF_BOUNDS exception. + +=over 4 + =item* get_number_keyed Get the number at the location X, Y. The key must have two elements. @@ -267,6 +281,8 @@ have two elements. Get a Float PMC of the number at the location X, Y. The key must have two elements. +=back + =cut */ @@ -302,6 +318,16 @@ elements. /* +=head2 Integer-Keyed Lookup VTABLES + +These VTABLEs treat the matrix, which is a contiguous region in memory, as a +linear array of values. The matrix data is stored by rows. + +These routines are used for low-level access. Attempting to access a value +outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. + +=over 4 + =item* get_number_keyed_int Treating the matrix memory block like a C array, get the Nth number. The @@ -355,6 +381,16 @@ Nth number. The array is arranged in memory row by row. /* +=head2 Keyed Setter VTABLES + +These VTABLEs insert new values into the matrix at a point specified by the +Key PMC. The Key PMC must have exactly two elements. If the matrix is not large +enough to accomodate the specified location, it will be grown with zero-padding +so that it is at least large enough to hold the specified point and all existing +data. + +=over 4 + =item* set_number_keyed Set the number at position (X, Y), growing the matrix if necessary and padding @@ -398,6 +434,45 @@ must have two elements. VTABLE_set_number_keyed(INTERP, SELF, key, v); } +/* + +=head2 Integer-Keyed Setter VTABLEs + +These VTABLEs treat the matrix as a linear array in memory and allow fast +lookup based on the integer offset of values in the array. These are low-level +routines and are not intended for general use. + +Unlike the PMC-keyed VTABLEs, these routines will not automatically grow the +matrix if an index is provided which is outside the boundaries of the matrix. +In that case, an OUT_OF_BOUNDS exception will be thrown. + +=over 4 + +=item* set_pmc_keyed_int + +Set a PMC at the specified location. The rules for extracting a complex value +out of the input PMC are the same as used for set_pmc_keyed() + +=item* set_number_keyed_int + +Set the complex value at the specified location to the given real value. The +complex part of the value will be 0. + +=item* set_integer_keyed_int + +Set the complex value at the specified location to the given real value. The +complex part of the value will be 0 + +=item* set_string_keyed_int + +Convert the string to a Complex PMC, and set that at the specified location. + +=back + +=cut + +*/ + VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { DECLATTRS_NumMatrix2D(SELF, attrs); const INTVAL total_size = attrs->rows * attrs->cols; @@ -417,12 +492,32 @@ must have two elements. VTABLE_set_number_keyed_int(INTERP, SELF, key, f); } + /* TODO: set_string_keyed_int */ + /* +=head2 Miscellaneous VTABLEs + +=over 4 + =item* get_string -Get a string representation of the matrix. +Get a string representation of the matrix, suitable for printing to the console + +=item* get_attr_string + +Get a named attribute. The name can be one of "rows", "cols", or "size". + +=item* clone + +Clone the matrix + +=item* is_equal + +Determine if two matrices are equal in size and composition. + +=back =cut @@ -452,11 +547,141 @@ Get a string representation of the matrix. return VTABLE_get_string(INTERP, builder); } + VTABLE PMC * get_attr_str(STRING * idx) { + DECLATTRS_NumMatrix2D(SELF, attrs); + if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) { + PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer); + VTABLE_set_integer_native(INTERP, rows, attrs->rows); + return rows; + } + else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "cols"))) { + PMC * const cols = Parrot_pmc_new(INTERP, enum_class_Integer); + VTABLE_set_integer_native(INTERP, cols, attrs->cols); + return cols; + } + else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "size"))) { + PMC * const size = Parrot_pmc_new(INTERP, enum_class_Integer); + VTABLE_set_integer_native(INTERP, size, attrs->cols * attrs->rows); + return size; + } + return PMCNULL; + } + + VTABLE PMC * clone() { + PMC * const c = Parrot_pmc_new(INTERP, SELF->vtable->base_type); + DECLATTRS_NumMatrix2D(SELF, old_atts); + DECLATTRS_NumMatrix2D(c, new_atts); + INTVAL const newsize = old_atts->rows * old_atts->cols; + FLOATVAL * const old_s = old_atts->storage; + FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); + memcpy(new_s, old_s, newsize * sizeof(FLOATVAL)); + memcpy(new_atts, old_atts, sizeof(Parrot_NumMatrix2D_attributes)); + new_atts->storage = new_s; + return c; + } + + VTABLE INTVAL is_equal(PMC * other) { + if (other->vtable->base_type == SELF->vtable->base_type) { + DECLATTRS_NumMatrix2D(SELF, self_attrs); + DECLATTRS_NumMatrix2D(other, other_attrs); + const INTVAL self_rows = self_attrs->rows; + const INTVAL self_cols = self_attrs->cols; + const INTVAL self_flags = self_attrs->flags; + const INTVAL other_rows = other_attrs->rows; + const INTVAL other_cols = other_attrs->cols; + const INTVAL other_flags = other_attrs->flags; + FLOATVAL * const self_s = self_attrs->storage; + FLOATVAL * const other_s = other_attrs->storage; + INTVAL i, j; + + if (self_rows != other_rows || self_cols != other_cols) + return 0; + + for (i = 0; i < self_rows; i++) { + for (j = 0; j < self_cols; j++) { + const FLOATVAL self_value = + ITEM_XY(self_s, self_flags, self_rows, self_cols, i, j); + const FLOATVAL other_value = + ITEM_XY(other_s, other_flags, other_rows, other_cols, i, j); + if (!floats_are_equal(self_value, other_value)) + return 0; + } + } + return 1; + } + return 0; + } + /* -=item* add(NumMatrix) +=head2 Serialization/Deserialization VTABLEs -Add two matrices together, element-by-element. +=over 4 + +=item* freeze + +Freeze the PMC for serialization to a string suitable for long-term storage in +a file. + +=item* thaw + +Thaw a serialized PMC + +=back + +=cut + +*/ + + VTABLE void freeze(PMC *info) { + DECLATTRS_NumMatrix2D(SELF, attrs); + INTVAL const rows = attrs->rows; + INTVAL const cols = attrs->cols; + INTVAL const flags = attrs->flags; + INTVAL i, j; + FLOATVAL * const s = attrs->storage; + VTABLE_push_integer(INTERP, info, rows); + VTABLE_push_integer(INTERP, info, cols); + VTABLE_push_integer(INTERP, info, flags); + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + const FLOATVAL f = ITEM_XY(s, flags, rows, cols, i, j); + VTABLE_push_float(INTERP, info, f); + } + } + } + + VTABLE void thaw(PMC *info) { + DECLATTRS_NumMatrix2D(SELF, attrs); + INTVAL const rows = VTABLE_shift_integer(INTERP, info); + INTVAL const cols = VTABLE_shift_integer(INTERP, info); + INTVAL const flags = VTABLE_shift_integer(INTERP, info); + INTVAL i, j; + FLOATVAL * s; + attrs->rows = 0; + attrs->cols = 0; + attrs->storage = NULL; + attrs->flags = 0; + resize_matrix(INTERP, SELF, rows - 1, cols - 1); + s = attrs->storage; + attrs->flags = flags; + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + const FLOATVAL f = VTABLE_shift_float(INTERP, info); + ITEM_XY(s, flags, rows, cols, i, j) = f; + } + } + } + +/* + +=head2 Addition VTABLEs + +=over 4 + +=item* add(NumMatrix2D) + +Add two matrices together, element-by-element =item* add(DEFAULT) @@ -471,6 +696,8 @@ Add the float value to every element in the matrix. Add the integer value to every element in the matrix. +=back + =cut */ @@ -502,6 +729,10 @@ Add the integer value to every element in the matrix. /* +=head2 In-Place Addition VTABLEs + +=over 4 + =item* i_add(NumMatrix2D) =item* i_add(DEFAULT) @@ -510,6 +741,8 @@ Add the integer value to every element in the matrix. =item* i_add_float +=back + =cut */ @@ -533,6 +766,10 @@ Add the integer value to every element in the matrix. /* +=head2 Subtraction VTABLEs + +=over 4 + =item* subtract(NumMatrix) Add two matrices together, element-by-element. @@ -550,6 +787,8 @@ Add the float value to every element in the matrix. Add the integer value to every element in the matrix. +=back + =cut */ @@ -581,6 +820,10 @@ Add the integer value to every element in the matrix. /* +=head2 In-Place Subtraction VTABLES + +=over 4 + =item* i_subtract(NumMatrix2D) =item* i_subtract(DEFAULT) @@ -589,6 +832,8 @@ Add the integer value to every element in the matrix. =item* i_subtract_float +=back + =cut */ @@ -612,10 +857,20 @@ Add the integer value to every element in the matrix. /* +=head2 Multiplication VTABLEs + +=over 4 + =item* multiply(NumMatrix2D) =item* multiply(DEFAULT) +=item* multiply_int + +=item* multiply_float + +=back + =cut */ @@ -644,16 +899,6 @@ Add the integer value to every element in the matrix. return dest; } -/* - -=item* multiply_int - -=item* multiply_float - -=cut - -*/ - VTABLE PMC *multiply_int(INTVAL v, PMC * dest) { dest = VTABLE_clone(INTERP, SELF); multiply_scalar_float(INTERP, dest, (FLOATVAL)v); @@ -668,10 +913,20 @@ Add the integer value to every element in the matrix. /* +=head2 In-Place Multiplication VTABLEs + +=over 4 + =item* i_multiply(NumMatrix2D) =item* i_multiply(DEFAULT) +=item* i_multiply_int + +=item* i_multiply_float + +=back + =cut */ @@ -686,16 +941,6 @@ Add the integer value to every element in the matrix. multiply_scalar_float(INTERP, SELF, v); } -/* - -=item i_multiply_int - -=item i_multiply_float - -=cut - -*/ - VTABLE void i_multiply_int(INTVAL v) { multiply_scalar_float(INTERP, SELF, (FLOATVAL)v); } @@ -704,144 +949,6 @@ Add the integer value to every element in the matrix. multiply_scalar_float(INTERP, SELF, v); } -/* - -=item* get_attr_str - -=cut - -*/ - - VTABLE PMC * get_attr_str(STRING * idx) { - DECLATTRS_NumMatrix2D(SELF, attrs); - if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "rows"))) { - PMC * const rows = Parrot_pmc_new(INTERP, enum_class_Integer); - VTABLE_set_integer_native(INTERP, rows, attrs->rows); - return rows; - } - else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "cols"))) { - PMC * const cols = Parrot_pmc_new(INTERP, enum_class_Integer); - VTABLE_set_integer_native(INTERP, cols, attrs->cols); - return cols; - } - else if (Parrot_str_equal(INTERP, idx, CONST_STRING(INTERP, "size"))) { - PMC * const size = Parrot_pmc_new(INTERP, enum_class_Integer); - VTABLE_set_integer_native(INTERP, size, attrs->cols * attrs->rows); - return size; - } - return PMCNULL; - } - -/* - -=item* clone - -=cut - -*/ - - VTABLE PMC * clone() { - PMC * const c = Parrot_pmc_new(INTERP, SELF->vtable->base_type); - DECLATTRS_NumMatrix2D(SELF, old_atts); - DECLATTRS_NumMatrix2D(c, new_atts); - INTVAL const newsize = old_atts->rows * old_atts->cols; - FLOATVAL * const old_s = old_atts->storage; - FLOATVAL * const new_s = ALLOCATE_STORAGE_NumMatrix2D(newsize); - memcpy(new_s, old_s, newsize * sizeof(FLOATVAL)); - memcpy(new_atts, old_atts, sizeof(Parrot_NumMatrix2D_attributes)); - new_atts->storage = new_s; - return c; - } - -/* - -=item* is_equal - -=cut - -*/ - - VTABLE INTVAL is_equal(PMC * other) { - if (other->vtable->base_type == SELF->vtable->base_type) { - DECLATTRS_NumMatrix2D(SELF, self_attrs); - DECLATTRS_NumMatrix2D(other, other_attrs); - const INTVAL self_rows = self_attrs->rows; - const INTVAL self_cols = self_attrs->cols; - const INTVAL self_flags = self_attrs->flags; - const INTVAL other_rows = other_attrs->rows; - const INTVAL other_cols = other_attrs->cols; - const INTVAL other_flags = other_attrs->flags; - FLOATVAL * const self_s = self_attrs->storage; - FLOATVAL * const other_s = other_attrs->storage; - INTVAL i, j; - - if (self_rows != other_rows || self_cols != other_cols) - return 0; - - for (i = 0; i < self_rows; i++) { - for (j = 0; j < self_cols; j++) { - const FLOATVAL self_value = - ITEM_XY(self_s, self_flags, self_rows, self_cols, i, j); - const FLOATVAL other_value = - ITEM_XY(other_s, other_flags, other_rows, other_cols, i, j); - if (!floats_are_equal(self_value, other_value)) - return 0; - } - } - return 1; - } - return 0; - } - -/* - -=item* freeze - -=item* thaw - -=cut - -*/ - - VTABLE void freeze(PMC *info) { - DECLATTRS_NumMatrix2D(SELF, attrs); - INTVAL const rows = attrs->rows; - INTVAL const cols = attrs->cols; - INTVAL const flags = attrs->flags; - INTVAL i, j; - FLOATVAL * const s = attrs->storage; - VTABLE_push_integer(INTERP, info, rows); - VTABLE_push_integer(INTERP, info, cols); - VTABLE_push_integer(INTERP, info, flags); - for (i = 0; i < rows; i++) { - for (j = 0; j < cols; j++) { - const FLOATVAL f = ITEM_XY(s, flags, rows, cols, i, j); - VTABLE_push_float(INTERP, info, f); - } - } - } - - VTABLE void thaw(PMC *info) { - DECLATTRS_NumMatrix2D(SELF, attrs); - INTVAL const rows = VTABLE_shift_integer(INTERP, info); - INTVAL const cols = VTABLE_shift_integer(INTERP, info); - INTVAL const flags = VTABLE_shift_integer(INTERP, info); - INTVAL i, j; - FLOATVAL * s; - attrs->rows = 0; - attrs->cols = 0; - attrs->storage = NULL; - attrs->flags = 0; - resize_matrix(INTERP, SELF, rows - 1, cols - 1); - s = attrs->storage; - attrs->flags = flags; - for (i = 0; i < rows; i++) { - for (j = 0; j < cols; j++) { - const FLOATVAL f = VTABLE_shift_float(INTERP, info); - ITEM_XY(s, flags, rows, cols, i, j) = f; - } - } - } /* @@ -851,7 +958,12 @@ Add the integer value to every element in the matrix. =over 4 -=item resize() +=item* resize() + +Resize the matrix to include at least the specified number of rows and columns. + +Resizing the matrix never causes the matrix to shrink. If you need a subset of +the matrix, use get_block instead. =cut @@ -863,10 +975,11 @@ Add the integer value to every element in the matrix. /* -=item fill() +=item* fill() Fill the matrix with a single value. if sizes are provided, fill to those -sizes, growing the matrix if needed. +sizes, growing the matrix if needed. Elements outside the specified area are +unaffected. Calling fill() never causes the matrix to shrink. =cut @@ -902,7 +1015,9 @@ sizes, growing the matrix if needed. /* -=item item_at() +=item* item_at() + +Return a single Complex PMC from the item at the specified coordinates =cut @@ -927,9 +1042,12 @@ sizes, growing the matrix if needed. /* -=item transpose() +=item* transpose() -Transposes the matrix lazily. +Transposes the matrix lazily. This operation is O(n). Some operations, such as +mathematical operations do not work on a matrix which has been lazily +transposed, so those operations will force the matrix memory to be eagerly +transposed. =cut @@ -951,10 +1069,11 @@ Transposes the matrix lazily. /* -=item mem_transpose() +=item* mem_transpose() Transposes the actual data storage of the matrix. More expensive up-front -than the transpose() method. +than the transpose() method, but the resulting memory structure is more suitable +for use in certain mathematical operations. =cut @@ -983,12 +1102,12 @@ than the transpose() method. /* -=item iterate_function_inplace() +=item* iterate_function_inplace() Calls a function for every element in the matrix, replacing the current value with the return value of the called function. -=item iterate_function_external() +=item* iterate_function_external() Calls a function for every element in the matrix, adding the result of each computation to a new matrix. Return the new matrix of results. @@ -1056,12 +1175,12 @@ computation to a new matrix. Return the new matrix of results. /* -=item initialize_from_array() +=item* initialize_from_array() Initialize matrix values from a linear array, filling each row with data in order. -=item initialize_from_args() +=item* initialize_from_args() Initialize matrix values from an array of function arguments, filling each row with data in order. @@ -1082,9 +1201,14 @@ with data in order. /* -=item get_block +=item* get_block -=item set_block +Get a specified sub-block of the matrix. If the bounds of the sub-block are +outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. + +=item* set_block + +Set a block in the matrix, growing it if needed. =cut @@ -1166,6 +1290,10 @@ Calculates the matrix equation: Z = aAB + bC +The matrices must all be NumMatrix2D, or must be convertable to it. The +matrix SELF is not used in the calculation, but the result matrix will have the +same type as SELF. + =cut */ @@ -1180,17 +1308,21 @@ Calculates the matrix equation: /* -=item row_combine(srcidx, destidx, gain) +=item* row_combine(srcidx, destidx, gain) -add a multiple of the source row to the destination row. +add a multiple of the source row to the destination row. If either of the row +indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is +thrown. -=item row_scale(idx, gain) +=item* row_scale(idx, gain) -Multiply all elements in the row by a gain factor. +Multiply all elements in the row by a gain factor. If the row index is outside +the bounds of the matrix and OUT_OF_BOUNDS exception is thrown. -=item row_swap(idx_a, idx_b) +=item* row_swap(idx_a, idx_b) -Swap two rows +Swap two rows. If either of the row indices are outside the bounds of the +matrix, an OUT_OF_BOUNDS exception is thrown. =cut @@ -1248,17 +1380,20 @@ Swap two rows /* -=item convert_to_number_matrix +=item* convert_to_number_matrix -Get a NumMatrix2D from the current matrix +Get a NumMatrix2D from the current matrix. If the matrix is already a +NumMatrix2D, return a clone. -=item convert_to_complex_matrix +=item* convert_to_complex_matrix -Get a ComplexMatrix2D from the current matrix +Get a ComplexMatrix2D from the current matrix. If the matrix is already a +ComplexMatrix2D, return a clone. -=item convert_to_pmc_matrix +=item* convert_to_pmc_matrix -Get a PMCMatrix2D from the current matrix +Get a PMCMatrix2D from the current matrix. If the matrix is already a +PMCMatrix2D, return a clone. =cut @@ -1300,8 +1435,6 @@ Get a PMCMatrix2D from the current matrix RETURN(PMC * d); } - - /* =back From 3cc1c0d02edb657c2e80b3e264f7aeef38df115e Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 11:59:42 -0400 Subject: [PATCH 6/8] ...and documentation for PMCMatrix2D --- src/pmc/complexmatrix2d.pmc | 4 +- src/pmc/nummatrix2d.pmc | 6 +- src/pmc/pmcmatrix2d.pmc | 383 ++++++++++++++++++++++++++++++------ 3 files changed, 329 insertions(+), 64 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index fe72ebd..1318f20 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -1339,7 +1339,7 @@ Return a single Complex PMC from the item at the specified coordinates =item* transpose() -Transposes the matrix lazily. This operation is O(n). Some operations, such as +Transposes the matrix lazily. This operation is O(1). Some operations, such as mathematical operations do not work on a matrix which has been lazily transposed, so those operations will force the matrix memory to be eagerly transposed. @@ -1367,7 +1367,7 @@ transposed. =item* mem_transpose() -Transposes the actual data storage of the matrix. More expensive up-front +Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method, but the resulting memory structure is more suitable for use in certain mathematical operations. diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index 90263f8..e8a86a8 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -1017,7 +1017,7 @@ unaffected. Calling fill() never causes the matrix to shrink. =item* item_at() -Return a single Complex PMC from the item at the specified coordinates +Return a single Float PMC from the item at the specified coordinates =cut @@ -1044,7 +1044,7 @@ Return a single Complex PMC from the item at the specified coordinates =item* transpose() -Transposes the matrix lazily. This operation is O(n). Some operations, such as +Transposes the matrix lazily. This operation is O(1). Some operations, such as mathematical operations do not work on a matrix which has been lazily transposed, so those operations will force the matrix memory to be eagerly transposed. @@ -1071,7 +1071,7 @@ transposed. =item* mem_transpose() -Transposes the actual data storage of the matrix. More expensive up-front +Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method, but the resulting memory structure is more suitable for use in certain mathematical operations. diff --git a/src/pmc/pmcmatrix2d.pmc b/src/pmc/pmcmatrix2d.pmc index b9cf7a9..ab03710 100644 --- a/src/pmc/pmcmatrix2d.pmc +++ b/src/pmc/pmcmatrix2d.pmc @@ -115,6 +115,32 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { __PLA_Type_PMCMatrix2D = entry; } +/* + +=head1 VTABLEs + +=head System VTABLEs + +=over 4 + +=item* init + +Initialize the new PMC + +=item* destroy + +Destroy the PMC and free all associated memory + +=item* mark + +Mark the contents of the matrix for GC + +=back + +=cut + +*/ + VTABLE void init() { DECLATTRS_PMCMatrix2D(SELF, attrs); attrs->storage = NULL; @@ -146,7 +172,39 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { } } -/* Get VTABLEs */ +/* + +=head2 Keyed Lookup VTABLEs + +In each of these cases, the specified Key PMC must have exactly two elements +to specify a location in the matrix. + +Attempting to retrieve a value outside the boundaries of the matrix will throw +an OUT_OF_BOUNDS exception. + +=over 4 + +=item* get_number_keyed + +Get the PMC at the location X, Y. + +=item* get_integer_keyed + +Get the integer from the PMC at the location X, Y. + +=item* get_string_keyed + +Get a string representation of the PMC at the location X, Y. + +=item* get_pmc_keyed + +Get a PMC at the location X, Y. + +=back + +=cut + +*/ VTABLE PMC * get_pmc_keyed(PMC * key) { DECLATTRS_PMCMatrix2D(SELF, attrs); @@ -160,6 +218,53 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { return ITEM_XY(attrs->storage, attrs->flags, rows_size, cols_size, rows, cols); } + VTABLE INTVAL get_integer_keyed(PMC * key) { + PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); + return VTABLE_get_integer(INTERP, item); + } + + VTABLE FLOATVAL get_number_keyed(PMC * key) { + PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); + return VTABLE_get_number(INTERP, item); + } + + VTABLE STRING * get_string_keyed(PMC * key) { + PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); + return VTABLE_get_string(INTERP, item); + } + +/* + +=head2 Integer-Keyed Lookup VTABLES + +These VTABLEs treat the matrix, which is a contiguous region in memory, as a +linear array of values. The matrix data is stored by rows. + +These routines are used for low-level access. Attempting to access a value +outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. + +=over 4 + +=item* get_number_keyed_int + +Get a floating point number from the PMC at the specified location. + +=item* get_integer_keyed_int + +Get an integer from the PMC at the specifed location. + +=item* get_string_keyed_int + +Get the string representation of the PMC at the specified location. + +=item* get_pmc_keyed_int + +Get the PMC at the specified location + +=cut + +*/ + VTABLE PMC * get_pmc_keyed_int(INTVAL key) { DECLATTRS_PMCMatrix2D(SELF, attrs); const INTVAL total_size = attrs->cols * attrs->rows; @@ -170,31 +275,16 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { return attrs->storage[key]; } - VTABLE INTVAL get_integer_keyed(PMC * key) { - PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); - return VTABLE_get_integer(INTERP, item); - } - VTABLE INTVAL get_integer_keyed_int(INTVAL key) { PMC * const item = VTABLE_get_pmc_keyed_int(INTERP, SELF, key); return VTABLE_get_integer(INTERP, item); } - VTABLE FLOATVAL get_number_keyed(PMC * key) { - PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); - return VTABLE_get_number(INTERP, item); - } - VTABLE FLOATVAL get_number_keyed_int(INTVAL key) { PMC * const item = VTABLE_get_pmc_keyed_int(INTERP, SELF, key); return VTABLE_get_number(INTERP, item); } - VTABLE STRING * get_string_keyed(PMC * key) { - PMC * const item = VTABLE_get_pmc_keyed(INTERP, SELF, key); - return VTABLE_get_string(INTERP, item); - } - VTABLE STRING * get_string_keyed_int(INTVAL key) { PMC * const item = VTABLE_get_pmc_keyed_int(INTERP, SELF, key); return VTABLE_get_string(INTERP, item); @@ -202,6 +292,40 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { /* Set VTABLEs TODO: Update all these to follow HLL mappings +*/ +/* + +=head2 Keyed Setter VTABLES + +These VTABLEs insert new values into the matrix at a point specified by the +Key PMC. The Key PMC must have exactly two elements. If the matrix is not large +enough to accomodate the specified location, it will be grown with zero-padding +so that it is at least large enough to hold the specified point and all existing +data. + +=over 4 + +=item* set_number_keyed + +Create a Float PMC with the specified value, and insert it at the specified +location + +=item* set_integer_keyed + +Create an Integer PMC with the specified value, and insert it at the specified +location + +=item* set_pmc_keyed + +Set the PMC at the specified location. + +=item* set_string_keyed + +Create a String PMC with the specified value, and insert it at the specified +location + +=cut + */ VTABLE void set_pmc_keyed(PMC * key, PMC * value) { @@ -218,52 +342,113 @@ TODO: Update all these to follow HLL mappings ITEM_XY(attrs->storage, attrs->flags, rows_size, cols_size, rows, cols) = value; } - VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { - DECLATTRS_PMCMatrix2D(SELF, attrs); - const INTVAL total_size = attrs->cols * attrs->rows; - if (key >= total_size || key < 0) { - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, - PLATYPENAME ": indices out of bounds."); - } - attrs->storage[key] = value; - } - VTABLE void set_integer_keyed(PMC * key, INTVAL value) { PMC * const item = Parrot_pmc_new(INTERP, enum_class_Integer); VTABLE_set_integer_native(INTERP, item, value); VTABLE_set_pmc_keyed(INTERP, SELF, key, item); } - VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) { - PMC * const item = Parrot_pmc_new(INTERP, enum_class_Integer); - VTABLE_set_integer_native(INTERP, item, value); - VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item); - } - VTABLE void set_number_keyed(PMC * key, FLOATVAL value) { PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float); VTABLE_set_number_native(INTERP, item, value); VTABLE_set_pmc_keyed(INTERP, SELF, key, item); } - VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { - PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float); - VTABLE_set_number_native(INTERP, item, value); - VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item); - } - VTABLE void set_string_keyed(PMC * key, STRING * value) { PMC * const item = Parrot_pmc_new(INTERP, enum_class_String); VTABLE_set_string_native(INTERP, item, value); VTABLE_set_pmc_keyed(INTERP, SELF, key, item); } +/* + +=head2 Integer-Keyed Setter VTABLEs + +These VTABLEs treat the matrix as a linear array in memory and allow fast +lookup based on the integer offset of values in the array. These are low-level +routines and are not intended for general use. + +Unlike the PMC-keyed VTABLEs, these routines will not automatically grow the +matrix if an index is provided which is outside the boundaries of the matrix. +In that case, an OUT_OF_BOUNDS exception will be thrown. + +=over 4 + +=item* set_pmc_keyed_int + +Set a PMC at the specified location. + +=item* set_number_keyed_int + +Create a Float PMC with the specified value, and insert it at the specified +location + +=item* set_integer_keyed_int + +Create an Integer PMC with the specified value, and insert it at the specified +location + +=item* set_string_keyed_int + +Create a String PMC with the specified value, and insert it at the specified +location + +=back + +=cut + +*/ + + VTABLE void set_pmc_keyed_int(INTVAL key, PMC * value) { + DECLATTRS_PMCMatrix2D(SELF, attrs); + const INTVAL total_size = attrs->cols * attrs->rows; + if (key >= total_size || key < 0) { + Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS, + PLATYPENAME ": indices out of bounds."); + } + attrs->storage[key] = value; + } + VTABLE void set_string_keyed_int(INTVAL key, STRING * value) { PMC * const item = Parrot_pmc_new(INTERP, enum_class_String); VTABLE_set_string_native(INTERP, item, value); VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item); } + VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) { + PMC * const item = Parrot_pmc_new(INTERP, enum_class_Float); + VTABLE_set_number_native(INTERP, item, value); + VTABLE_set_pmc_keyed_int(INTERP, SELF, key, item); + } + +/* + +=head2 Miscellaneous VTABLEs + +=over 4 + +=item* get_string + +Get a string representation of the matrix, suitable for printing to the console + +=item* get_attr_string + +Get a named attribute. The name can be one of "rows", "cols", or "size". + +=item* clone + +Clone the matrix + +=item* is_equal + +Determine if two matrices are equal in size and composition. + +=back + +=cut + +*/ + VTABLE STRING *get_string() { DECLATTRS_PMCMatrix2D(SELF, attrs); INTVAL rows, cols; @@ -378,10 +563,21 @@ TODO: Update all these to follow HLL mappings /* +=head2 Serialization/Deserialization VTABLEs + +=over 4 + =item* freeze +Freeze the PMC for serialization to a string suitable for long-term storage in +a file. + =item* thaw +Thaw a serialized PMC + +=back + =cut */ @@ -426,13 +622,24 @@ TODO: Update all these to follow HLL mappings } } - METHOD initialize_from_array(INTVAL rows_size, INTVAL cols_size, PMC *values) { - init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); - } +/* - METHOD initialize_from_args(INTVAL rows_size, INTVAL cols_size, PMC *values :slurpy) { - init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); - } +=back + +=head1 METHODS + +=over 4 + +=item* resize() + +Resize the matrix to include at least the specified number of rows and columns. + +Resizing the matrix never causes the matrix to shrink. If you need a subset of +the matrix, use get_block instead. + +=cut + +*/ METHOD resize(INTVAL rows, INTVAL cols) { resize_matrix(INTERP, SELF, rows - 1, cols - 1); @@ -440,10 +647,11 @@ TODO: Update all these to follow HLL mappings /* -=item fill() +=item* fill() Fill the matrix with a single value. if sizes are provided, fill to those -sizes, growing the matrix if needed. +sizes, growing the matrix if needed. Elements outside the specified area are +unaffected. Calling fill() never causes the matrix to shrink. =cut @@ -484,7 +692,9 @@ sizes, growing the matrix if needed. /* -=item item_at() +=item* item_at() + +Return a single PMC at the specified coordinates =cut @@ -510,9 +720,9 @@ sizes, growing the matrix if needed. /* -=item transpose() +=item* transpose() -Transposes the matrix. +Transposes the matrix lazily. This operation is O(1). =cut @@ -535,9 +745,9 @@ Transposes the matrix. /* -=item mem_transpose() +=item* mem_transpose() -Transposes the actual data storage of the matrix. More expensive up-front +Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method. =cut @@ -567,11 +777,16 @@ than the transpose() method. /* -=item iterate_function_inplace() +=item* iterate_function_inplace() -Calls a function for every element in the array, replacing the current +Calls a function for every element in the matrix, replacing the current value with the return value of the called function. +=item* iterate_function_external() + +Calls a function for every element in the matrix, adding the result of each +computation to a new matrix. Return the new matrix of results. + =cut */ @@ -631,6 +846,45 @@ value with the return value of the called function. RETURN(PMC * new_matrix); } +/* + +=item* initialize_from_array() + +Initialize matrix values from a linear array, filling each row with data +in order. + +=item* initialize_from_args() + +Initialize matrix values from an array of function arguments, filling each row +with data in order. + +=cut + +*/ + + METHOD initialize_from_array(INTVAL rows_size, INTVAL cols_size, PMC *values) { + init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); + } + + METHOD initialize_from_args(INTVAL rows_size, INTVAL cols_size, PMC *values :slurpy) { + init_from_pmc_array(INTERP, SELF, rows_size, cols_size, values); + } + +/* + +=item* get_block + +Get a specified sub-block of the matrix. If the bounds of the sub-block are +outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. + +=item* set_block + +Set a block in the matrix, growing it if needed. + +=cut + +*/ + METHOD get_block(INTVAL rows_idx, INTVAL cols_idx, INTVAL rows_size, INTVAL cols_size) { DECLATTRS_PMCMatrix2D(SELF, attrs); @@ -701,22 +955,26 @@ value with the return value of the called function. /* -=item convert_to_number_matrix +=item* convert_to_number_matrix -Get a NumMatrix2D from the current matrix +Get a NumMatrix2D from the current matrix. If the matrix is already a +NumMatrix2D, return a clone. -=item convert_to_complex_matrix +=item* convert_to_complex_matrix -Get a ComplexMatrix2D from the current matrix +Get a ComplexMatrix2D from the current matrix. If the matrix is already a +ComplexMatrix2D, return a clone. -=item convert_to_pmc_matrix +=item* convert_to_pmc_matrix -Get a PMCMatrix2D from the current matrix +Get a PMCMatrix2D from the current matrix. If the matrix is already a +PMCMatrix2D, return a clone. =cut */ + METHOD convert_to_number_matrix() { DECLATTRS_PMCMatrix2D(SELF, attrs); PMC * const d = Parrot_pmc_new(INTERP, __PLA_Type_NumMatrix2D); @@ -753,5 +1011,12 @@ Get a PMCMatrix2D from the current matrix RETURN(PMC * d); } +/* + +=back + +=end + +*/ } From c2e4804981b3f0867f3372d3c0695341167e7d1e Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 12:37:21 -0400 Subject: [PATCH 7/8] add html_pod to the output of the build. Also, fix up some of the pod files to actually pass podcheck --- setup.nqp | 7 ++ src/pmc/complexmatrix2d.pmc | 150 ++++++++++++++++++------------------ src/pmc/nummatrix2d.pmc | 138 +++++++++++++++++---------------- src/pmc/pmcmatrix2d.pmc | 88 ++++++++++----------- 4 files changed, 197 insertions(+), 186 deletions(-) diff --git a/setup.nqp b/setup.nqp index 58fe19c..a61e227 100755 --- a/setup.nqp +++ b/setup.nqp @@ -44,6 +44,7 @@ sub MAIN(@argv) { setup_testlib(%PLA); setup_nqp_bootstrapper(%PLA); setup_dynpmc_flags(%PLA); + setup_docs(%PLA); setup(@argv, %PLA); } @@ -249,4 +250,10 @@ sub setup_nqp_bootstrapper(%PLA) { %PLA{'inst_lib'}.push('pla_nqp.pbc'); } +sub setup_docs(%PLA) { + %PLA{'html_pod'}{'docs/nummatrix2d.html'} := 'src/pmc/nummatrix2d.pmc'; + %PLA{'html_pod'}{'docs/pmcmatrix2d.html'} := 'src/pmc/pmcmatrix2d.pmc'; + %PLA{'html_pod'}{'docs/complexmatrix2d.html'} := 'src/pmc/complexmatrix2d.pmc'; +} + diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index 1318f20..c7fd255 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -340,15 +340,15 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix =head1 VTABLEs -=head System VTABLEs +=head2 System VTABLEs =over 4 -=item* init +=item * init Initialize the new PMC -=item* destroy +=item * destroy Destroy the PMC and free all associated memory @@ -386,21 +386,21 @@ an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed +=item * get_number_keyed Get a floating point value at the location specified by the key. The floating point value is calculated as the magnitude of the complex value at the point in the matrix. -=item* get_integer_keyed +=item * get_integer_keyed Get an integer value at the location specified by the key. The integer value is the magnitude of the complex value at the specified location, cast from a floating point to an integer value. -=item* get_string_keyed +=item * get_string_keyed Get the string representation of the complex value at the point specified by the key. @@ -408,7 +408,7 @@ the key. The returned string has the same format as is used by the Parrot built-in Complex PMC type. -=item* get_pmc_keyed +=item * get_pmc_keyed Get a Complex PMC from the point specified by the key. @@ -473,22 +473,22 @@ outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed_int +=item * get_number_keyed_int Get a floating point number, the magnitude of the complex value, at the specified location in the array -=item* get_integer_keyed_int +=item * get_integer_keyed_int Get an integer, cast from the magnitude of the complex value, at the specified location in the array -=item* get_string_keyed_int +=item * get_string_keyed_int Get a string representation of the value at the specified point. Stringification is done the same as Parrot's Complex PMC type. -=item* get_pmc_keyed_int +=item * get_pmc_keyed_int Get a Complex PMC from the value at the specified point. @@ -548,23 +548,23 @@ data. =over 4 -=item* set_pmc_keyed +=item * set_pmc_keyed Set the value at the specified location to the complex value represented by the given PMC. Different PMC types have different behaviors in this operation. -=item* set_number_keyed +=item * set_number_keyed Set the value at the specified location to have a real value given by the number, and 0 for the complex value. -=item* set_string_keyed +=item * set_string_keyed Set the value at the specified location to the value represented by the string. The string is parsed by creating a temporary Complex PMC type, so all the same rules for that type apply to the input string format. -=item* set_integer_keyed +=item * set_integer_keyed Set the value at the specified location to have a real value given by the integer, and 0 for the complex value. @@ -611,22 +611,22 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =over 4 -=item* set_pmc_keyed_int +=item * set_pmc_keyed_int Set a PMC at the specified location. The rules for extracting a complex value out of the input PMC are the same as used for set_pmc_keyed() -=item* set_number_keyed_int +=item * set_number_keyed_int Set the complex value at the specified location to the given real value. The complex part of the value will be 0. -=item* set_integer_keyed_int +=item * set_integer_keyed_int Set the complex value at the specified location to the given real value. The complex part of the value will be 0 -=item* set_string_keyed_int +=item * set_string_keyed_int Convert the string to a Complex PMC, and set that at the specified location. @@ -668,19 +668,19 @@ Convert the string to a Complex PMC, and set that at the specified location. =over 4 -=item* get_string +=item * get_string Get a string representation of the matrix, suitable for printing to the console -=item* get_attr_string +=item * get_attr_string Get a named attribute. The name can be one of "rows", "cols", or "size". -=item* clone +=item * clone Clone the matrix -=item* is_equal +=item * is_equal Determine if two matrices are equal in size and composition. @@ -811,12 +811,12 @@ Determine if two matrices are equal in size and composition. =over 4 -=item* freeze +=item * freeze Freeze the PMC for serialization to a string suitable for long-term storage in a file. -=item* thaw +=item * thaw Thaw a serialized PMC @@ -876,24 +876,24 @@ Thaw a serialized PMC =over 4 -=item* add(ComplexMatrix2D) +=item * add(ComplexMatrix2D) Add two matrices together, element-by-element. -=item* add(Complex) +=item * add(Complex) Add a complex value to each element of the matrix -=item* add(DEFAULT) +=item * add(DEFAULT) Take the number representation of the argument PMC and add it to every element in the matrix. -=item* add_float +=item * add_float Add the float value to every element in the matrix. -=item* add_int +=item * add_int Add the integer value to every element in the matrix. @@ -940,23 +940,23 @@ Add the integer value to every element in the matrix. =over 4 -=item* i_add(ComplexMatrix2D) +=item * i_add(ComplexMatrix2D) Add a matrix into SELF -=item* i_add(Complex) +=item * i_add(Complex) Add a Complex value to every element of SELF -=item* i_add(DEFAULT) +=item * i_add(DEFAULT) Add the numeric value of the given PMC to every element of SELF -=item* i_add_int +=item * i_add_int Add the integer value to every element of SELF -=item* i_add_float +=item * i_add_float Add the floating-point value to every element of SELF @@ -993,26 +993,26 @@ Add the floating-point value to every element of SELF =over 4 -=item* subtract(ComplexMatrix2D) +=item * subtract(ComplexMatrix2D) Perform the matrix operation C = SELF - A -=item* subtract(Complex) +=item * subtract(Complex) Subtract a complex value from each element of the matrix -=item* subtract(DEFAULT) +=item * subtract(DEFAULT) Take the number representation of the argument PMC and subtract it from every element in the matrix. -=item* subtract_float +=item * subtract_float Subtract the float value from every element in the matrix. -=item* subtract_int +=item * subtract_int Subtract the integer value from every element in the matrix. @@ -1060,26 +1060,26 @@ Subtract the integer value from every element in the matrix. =over 4 -=item* i_subtract(ComplexMatrix2D) +=item * i_subtract(ComplexMatrix2D) Perform the matrix operation SELF = SELF - A -=item* i_subtract(Complex) +=item * i_subtract(Complex) Substract a complex value from each element of the matrix -=item* i_subtract(DEFAULT) +=item * i_subtract(DEFAULT) Subtract the numeric value of the PMC from the real part of each element in the matrix -=item* i_subtract_int +=item * i_subtract_int Subtract the integer value from the real part of each element in the matrix -=item* i_subtract_float +=item * i_subtract_float Subtract the floating point value from the real part of each element in the matrix @@ -1117,25 +1117,25 @@ matrix =over 4 -=item* multiply(ComplexMatrix2D) +=item * multiply(ComplexMatrix2D) Perform the matrix operation C = SELF × A -=item* multiply(Complex) +=item * multiply(Complex) Multiply each element in the matrix by the complex value -=item* multiply(DEFAULT) +=item * multiply(DEFAULT) Multiply each element in the matrix by the numeric value of the PMC -=item* multiply_int +=item * multiply_int Multiply each element in the matrix by the integer -=item* multiply_float +=item * multiply_float Multiply each element in the matrix by the floating point number @@ -1193,25 +1193,25 @@ Multiply each element in the matrix by the floating point number =over 4 -=item* i_multiply(ComplexMatrix2D) +=item * i_multiply(ComplexMatrix2D) Perform the matrix operation SELF = SELF × A -=item* i_multiply(Complex) +=item * i_multiply(Complex) Multiply every element in SELF by the complex value -=item* i_multiply(DEFAULT) +=item * i_multiply(DEFAULT) Multiply every element in SELF by the numeric value of the PMC -=item* i_multiply_int +=item * i_multiply_int Multiply every element in SELF by the integer -=item* i_multiply_float +=item * i_multiply_float Multiply every element in SELF by the floating point number @@ -1250,7 +1250,7 @@ Multiply every element in SELF by the floating point number =over 4 -=item* resize() +=item * resize() Resize the matrix to include at least the specified number of rows and columns. @@ -1267,7 +1267,7 @@ the matrix, use get_block instead. /* -=item* fill() +=item * fill() Fill the matrix with a single value. if sizes are provided, fill to those sizes, growing the matrix if needed. Elements outside the specified area are @@ -1308,7 +1308,7 @@ unaffected. Calling fill() never causes the matrix to shrink. /* -=item* item_at() +=item * item_at() Return a single Complex PMC from the item at the specified coordinates @@ -1337,7 +1337,7 @@ Return a single Complex PMC from the item at the specified coordinates /* -=item* transpose() +=item * transpose() Transposes the matrix lazily. This operation is O(1). Some operations, such as mathematical operations do not work on a matrix which has been lazily @@ -1365,7 +1365,7 @@ transposed. /* -=item* mem_transpose() +=item * mem_transpose() Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method, but the resulting memory structure is more suitable @@ -1400,7 +1400,7 @@ for use in certain mathematical operations. /* -=item* conjugate +=item * conjugate Convert the matrix to the complex conjugate of itself. @@ -1426,12 +1426,12 @@ Convert the matrix to the complex conjugate of itself. /* -=item* iterate_function_inplace() +=item * iterate_function_inplace() Calls a function for every element in the matrix, replacing the current value with the return value of the called function. -=item* iterate_function_external() +=item * iterate_function_external() Calls a function for every element in the matrix, creating a new matrix with the returned values of the called function. @@ -1479,11 +1479,11 @@ the returned values of the called function. /* -=item* initialize_from_array +=item * initialize_from_array Initialize the matrix using a list of values from an array. -=item* initialize_from_args +=item * initialize_from_args Initialize the matrix using values from a variadic (slurpy) argument list. @@ -1503,12 +1503,12 @@ Initialize the matrix using values from a variadic (slurpy) argument list. /* -=item* get_block +=item * get_block Get a specified sub-block of the matrix. If the bounds of the sub-block are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. -=item* set_block +=item * set_block Set a block in the matrix, growing it if needed. @@ -1590,7 +1590,7 @@ Set a block in the matrix, growing it if needed. /* -=item* gemm +=item * gemm Calculates the matrix equation: @@ -1617,18 +1617,18 @@ same type as SELF. /* -=item* row_combine(srcidx, destidx, gain) +=item * row_combine(srcidx, destidx, gain) add a multiple of the source row to the destination row. If either of the row indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. -=item* row_scale(idx, gain) +=item * row_scale(idx, gain) Multiply all elements in the row by a gain factor. If the row index is outside the bounds of the matrix and OUT_OF_BOUNDS exception is thrown. -=item* row_swap(idx_a, idx_b) +=item * row_swap(idx_a, idx_b) Swap two rows. If either of the row indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. @@ -1695,17 +1695,17 @@ matrix, an OUT_OF_BOUNDS exception is thrown. /* -=item* convert_to_number_matrix +=item * convert_to_number_matrix Get a NumMatrix2D from the current matrix. If the matrix is already a NumMatrix2D, return a clone. -=item* convert_to_complex_matrix +=item * convert_to_complex_matrix Get a ComplexMatrix2D from the current matrix. If the matrix is already a ComplexMatrix2D, return a clone. -=item* convert_to_pmc_matrix +=item * convert_to_pmc_matrix Get a PMCMatrix2D from the current matrix. If the matrix is already a PMCMatrix2D, return a clone. @@ -1755,7 +1755,7 @@ PMCMatrix2D, return a clone. =back -=end +=cut */ } diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index e8a86a8..86d3a5e 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -221,11 +221,11 @@ pmclass NumMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix { =over 4 -=item* init +=item * init Create a new NumMatrix2D -=item* destroy +=item * destroy Destrow the matrix and free it's allocated storage @@ -263,20 +263,20 @@ an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed +=item * get_number_keyed Get the number at the location X, Y. The key must have two elements. -=item* get_integer_keyed +=item * get_integer_keyed Get the integer at the location X, Y. The key must have two elements. -=item* get_string_keyed +=item * get_string_keyed Get a string representation of the number at the location X, Y. The key must have two elements. -=item* get_pmc_keyed +=item * get_pmc_keyed Get a Float PMC of the number at the location X, Y. The key must have two elements. @@ -328,26 +328,28 @@ outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed_int +=item * get_number_keyed_int Treating the matrix memory block like a C array, get the Nth number. The array is arranged in memory row by row. -=item* get_integer_keyed_int +=item * get_integer_keyed_int Treating the matrix memory block like a C array, get the Nth integer. The array is arranged in memory row by row. -=item* get_string_keyed_int +=item * get_string_keyed_int Treating the matrix memory block like a C array, get the string representation of the Nth number. The array is arranged in memory row by row. -=item* get_pmc_keyed_int +=item * get_pmc_keyed_int Treating the matrix memory block like a C array, get a Float PMC for the Nth number. The array is arranged in memory row by row. +=back + =cut */ @@ -391,22 +393,24 @@ data. =over 4 -=item* set_number_keyed +=item * set_number_keyed Set the number at position (X, Y), growing the matrix if necessary and padding empty spaces with 0.0. The key must have two elements. -=item* set_integer_keyed +=item * set_integer_keyed Set the integer at position (X, Y), growing the matrix if necessary and padding empty spaces with 0.0. The key must have two elements. -=item* set_pmc_keyed +=item * set_pmc_keyed Get the numeric value from the PMC argument and set it at position (X, Y), growing the matrix if necessary and padding empty spaces with 0.0. The key must have two elements. +=back + =cut */ @@ -448,22 +452,22 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =over 4 -=item* set_pmc_keyed_int +=item * set_pmc_keyed_int Set a PMC at the specified location. The rules for extracting a complex value out of the input PMC are the same as used for set_pmc_keyed() -=item* set_number_keyed_int +=item * set_number_keyed_int Set the complex value at the specified location to the given real value. The complex part of the value will be 0. -=item* set_integer_keyed_int +=item * set_integer_keyed_int Set the complex value at the specified location to the given real value. The complex part of the value will be 0 -=item* set_string_keyed_int +=item * set_string_keyed_int Convert the string to a Complex PMC, and set that at the specified location. @@ -501,19 +505,19 @@ Convert the string to a Complex PMC, and set that at the specified location. =over 4 -=item* get_string +=item * get_string Get a string representation of the matrix, suitable for printing to the console -=item* get_attr_string +=item * get_attr_string Get a named attribute. The name can be one of "rows", "cols", or "size". -=item* clone +=item * clone Clone the matrix -=item* is_equal +=item * is_equal Determine if two matrices are equal in size and composition. @@ -618,12 +622,12 @@ Determine if two matrices are equal in size and composition. =over 4 -=item* freeze +=item * freeze Freeze the PMC for serialization to a string suitable for long-term storage in a file. -=item* thaw +=item * thaw Thaw a serialized PMC @@ -679,20 +683,20 @@ Thaw a serialized PMC =over 4 -=item* add(NumMatrix2D) +=item * add(NumMatrix2D) Add two matrices together, element-by-element -=item* add(DEFAULT) +=item * add(DEFAULT) Take the number representation of the argument PMC and add it to every element in the matrix. -=item* add_float +=item * add_float Add the float value to every element in the matrix. -=item* add_int +=item * add_int Add the integer value to every element in the matrix. @@ -733,13 +737,13 @@ Add the integer value to every element in the matrix. =over 4 -=item* i_add(NumMatrix2D) +=item * i_add(NumMatrix2D) -=item* i_add(DEFAULT) +=item * i_add(DEFAULT) -=item* i_add_int +=item * i_add_int -=item* i_add_float +=item * i_add_float =back @@ -770,20 +774,20 @@ Add the integer value to every element in the matrix. =over 4 -=item* subtract(NumMatrix) +=item * subtract(NumMatrix) Add two matrices together, element-by-element. -=item* subtract(DEFAULT) +=item * subtract(DEFAULT) Take the number representation of the argument PMC and add it to every element in the matrix. -=item* subtract_float +=item * subtract_float Add the float value to every element in the matrix. -=item* subtract_int +=item * subtract_int Add the integer value to every element in the matrix. @@ -824,13 +828,13 @@ Add the integer value to every element in the matrix. =over 4 -=item* i_subtract(NumMatrix2D) +=item * i_subtract(NumMatrix2D) -=item* i_subtract(DEFAULT) +=item * i_subtract(DEFAULT) -=item* i_subtract_int +=item * i_subtract_int -=item* i_subtract_float +=item * i_subtract_float =back @@ -861,13 +865,13 @@ Add the integer value to every element in the matrix. =over 4 -=item* multiply(NumMatrix2D) +=item * multiply(NumMatrix2D) -=item* multiply(DEFAULT) +=item * multiply(DEFAULT) -=item* multiply_int +=item * multiply_int -=item* multiply_float +=item * multiply_float =back @@ -917,13 +921,13 @@ Add the integer value to every element in the matrix. =over 4 -=item* i_multiply(NumMatrix2D) +=item * i_multiply(NumMatrix2D) -=item* i_multiply(DEFAULT) +=item * i_multiply(DEFAULT) -=item* i_multiply_int +=item * i_multiply_int -=item* i_multiply_float +=item * i_multiply_float =back @@ -952,13 +956,11 @@ Add the integer value to every element in the matrix. /* -=back - =head1 METHODS =over 4 -=item* resize() +=item * resize() Resize the matrix to include at least the specified number of rows and columns. @@ -975,7 +977,7 @@ the matrix, use get_block instead. /* -=item* fill() +=item * fill() Fill the matrix with a single value. if sizes are provided, fill to those sizes, growing the matrix if needed. Elements outside the specified area are @@ -1015,7 +1017,7 @@ unaffected. Calling fill() never causes the matrix to shrink. /* -=item* item_at() +=item * item_at() Return a single Float PMC from the item at the specified coordinates @@ -1042,7 +1044,7 @@ Return a single Float PMC from the item at the specified coordinates /* -=item* transpose() +=item * transpose() Transposes the matrix lazily. This operation is O(1). Some operations, such as mathematical operations do not work on a matrix which has been lazily @@ -1069,7 +1071,7 @@ transposed. /* -=item* mem_transpose() +=item * mem_transpose() Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method, but the resulting memory structure is more suitable @@ -1102,12 +1104,12 @@ for use in certain mathematical operations. /* -=item* iterate_function_inplace() +=item * iterate_function_inplace() Calls a function for every element in the matrix, replacing the current value with the return value of the called function. -=item* iterate_function_external() +=item * iterate_function_external() Calls a function for every element in the matrix, adding the result of each computation to a new matrix. Return the new matrix of results. @@ -1175,12 +1177,12 @@ computation to a new matrix. Return the new matrix of results. /* -=item* initialize_from_array() +=item * initialize_from_array() Initialize matrix values from a linear array, filling each row with data in order. -=item* initialize_from_args() +=item * initialize_from_args() Initialize matrix values from an array of function arguments, filling each row with data in order. @@ -1201,12 +1203,12 @@ with data in order. /* -=item* get_block +=item * get_block Get a specified sub-block of the matrix. If the bounds of the sub-block are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. -=item* set_block +=item * set_block Set a block in the matrix, growing it if needed. @@ -1284,7 +1286,7 @@ Set a block in the matrix, growing it if needed. /* -=item* gemm +=item * gemm Calculates the matrix equation: @@ -1308,18 +1310,18 @@ same type as SELF. /* -=item* row_combine(srcidx, destidx, gain) +=item * row_combine(srcidx, destidx, gain) add a multiple of the source row to the destination row. If either of the row indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. -=item* row_scale(idx, gain) +=item * row_scale(idx, gain) Multiply all elements in the row by a gain factor. If the row index is outside the bounds of the matrix and OUT_OF_BOUNDS exception is thrown. -=item* row_swap(idx_a, idx_b) +=item * row_swap(idx_a, idx_b) Swap two rows. If either of the row indices are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. @@ -1380,17 +1382,17 @@ matrix, an OUT_OF_BOUNDS exception is thrown. /* -=item* convert_to_number_matrix +=item * convert_to_number_matrix Get a NumMatrix2D from the current matrix. If the matrix is already a NumMatrix2D, return a clone. -=item* convert_to_complex_matrix +=item * convert_to_complex_matrix Get a ComplexMatrix2D from the current matrix. If the matrix is already a ComplexMatrix2D, return a clone. -=item* convert_to_pmc_matrix +=item * convert_to_pmc_matrix Get a PMCMatrix2D from the current matrix. If the matrix is already a PMCMatrix2D, return a clone. @@ -1439,7 +1441,7 @@ PMCMatrix2D, return a clone. =back -=end +=cut */ } diff --git a/src/pmc/pmcmatrix2d.pmc b/src/pmc/pmcmatrix2d.pmc index ab03710..170bf72 100644 --- a/src/pmc/pmcmatrix2d.pmc +++ b/src/pmc/pmcmatrix2d.pmc @@ -119,19 +119,19 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix { =head1 VTABLEs -=head System VTABLEs +=head2 System VTABLEs =over 4 -=item* init +=item * init Initialize the new PMC -=item* destroy +=item * destroy Destroy the PMC and free all associated memory -=item* mark +=item * mark Mark the contents of the matrix for GC @@ -184,19 +184,19 @@ an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed +=item * get_number_keyed Get the PMC at the location X, Y. -=item* get_integer_keyed +=item * get_integer_keyed Get the integer from the PMC at the location X, Y. -=item* get_string_keyed +=item * get_string_keyed Get a string representation of the PMC at the location X, Y. -=item* get_pmc_keyed +=item * get_pmc_keyed Get a PMC at the location X, Y. @@ -245,22 +245,24 @@ outside the bounds of the matrix will throw an OUT_OF_BOUNDS exception. =over 4 -=item* get_number_keyed_int +=item * get_number_keyed_int Get a floating point number from the PMC at the specified location. -=item* get_integer_keyed_int +=item * get_integer_keyed_int Get an integer from the PMC at the specifed location. -=item* get_string_keyed_int +=item * get_string_keyed_int Get the string representation of the PMC at the specified location. -=item* get_pmc_keyed_int +=item * get_pmc_keyed_int Get the PMC at the specified location +=back + =cut */ @@ -305,25 +307,27 @@ data. =over 4 -=item* set_number_keyed +=item * set_number_keyed Create a Float PMC with the specified value, and insert it at the specified location -=item* set_integer_keyed +=item * set_integer_keyed Create an Integer PMC with the specified value, and insert it at the specified location -=item* set_pmc_keyed +=item * set_pmc_keyed Set the PMC at the specified location. -=item* set_string_keyed +=item * set_string_keyed Create a String PMC with the specified value, and insert it at the specified location +=back + =cut */ @@ -374,21 +378,21 @@ In that case, an OUT_OF_BOUNDS exception will be thrown. =over 4 -=item* set_pmc_keyed_int +=item * set_pmc_keyed_int Set a PMC at the specified location. -=item* set_number_keyed_int +=item * set_number_keyed_int Create a Float PMC with the specified value, and insert it at the specified location -=item* set_integer_keyed_int +=item * set_integer_keyed_int Create an Integer PMC with the specified value, and insert it at the specified location -=item* set_string_keyed_int +=item * set_string_keyed_int Create a String PMC with the specified value, and insert it at the specified location @@ -427,19 +431,19 @@ location =over 4 -=item* get_string +=item * get_string Get a string representation of the matrix, suitable for printing to the console -=item* get_attr_string +=item * get_attr_string Get a named attribute. The name can be one of "rows", "cols", or "size". -=item* clone +=item * clone Clone the matrix -=item* is_equal +=item * is_equal Determine if two matrices are equal in size and composition. @@ -567,12 +571,12 @@ Determine if two matrices are equal in size and composition. =over 4 -=item* freeze +=item * freeze Freeze the PMC for serialization to a string suitable for long-term storage in a file. -=item* thaw +=item * thaw Thaw a serialized PMC @@ -624,13 +628,11 @@ Thaw a serialized PMC /* -=back - =head1 METHODS =over 4 -=item* resize() +=item * resize() Resize the matrix to include at least the specified number of rows and columns. @@ -647,7 +649,7 @@ the matrix, use get_block instead. /* -=item* fill() +=item * fill() Fill the matrix with a single value. if sizes are provided, fill to those sizes, growing the matrix if needed. Elements outside the specified area are @@ -692,7 +694,7 @@ unaffected. Calling fill() never causes the matrix to shrink. /* -=item* item_at() +=item * item_at() Return a single PMC at the specified coordinates @@ -720,7 +722,7 @@ Return a single PMC at the specified coordinates /* -=item* transpose() +=item * transpose() Transposes the matrix lazily. This operation is O(1). @@ -745,7 +747,7 @@ Transposes the matrix lazily. This operation is O(1). /* -=item* mem_transpose() +=item * mem_transpose() Transposes the actual data storage of the matrix. More expensive O(n) up-front than the transpose() method. @@ -777,12 +779,12 @@ than the transpose() method. /* -=item* iterate_function_inplace() +=item * iterate_function_inplace() Calls a function for every element in the matrix, replacing the current value with the return value of the called function. -=item* iterate_function_external() +=item * iterate_function_external() Calls a function for every element in the matrix, adding the result of each computation to a new matrix. Return the new matrix of results. @@ -848,12 +850,12 @@ computation to a new matrix. Return the new matrix of results. /* -=item* initialize_from_array() +=item * initialize_from_array() Initialize matrix values from a linear array, filling each row with data in order. -=item* initialize_from_args() +=item * initialize_from_args() Initialize matrix values from an array of function arguments, filling each row with data in order. @@ -872,12 +874,12 @@ with data in order. /* -=item* get_block +=item * get_block Get a specified sub-block of the matrix. If the bounds of the sub-block are outside the bounds of the matrix, an OUT_OF_BOUNDS exception is thrown. -=item* set_block +=item * set_block Set a block in the matrix, growing it if needed. @@ -955,17 +957,17 @@ Set a block in the matrix, growing it if needed. /* -=item* convert_to_number_matrix +=item * convert_to_number_matrix Get a NumMatrix2D from the current matrix. If the matrix is already a NumMatrix2D, return a clone. -=item* convert_to_complex_matrix +=item * convert_to_complex_matrix Get a ComplexMatrix2D from the current matrix. If the matrix is already a ComplexMatrix2D, return a clone. -=item* convert_to_pmc_matrix +=item * convert_to_pmc_matrix Get a PMCMatrix2D from the current matrix. If the matrix is already a PMCMatrix2D, return a clone. @@ -1015,7 +1017,7 @@ PMCMatrix2D, return a clone. =back -=end +=cut */ } From 0161a224ade8763b00e59f64187dedb92324ab35 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 1 Sep 2010 12:42:56 -0400 Subject: [PATCH 8/8] add headings to the POD so the generated HTML is more usable --- src/pmc/complexmatrix2d.pmc | 15 ++++++++++++- src/pmc/nummatrix2d.pmc | 45 ++++++++++++++++++++++++------------- src/pmc/pmcmatrix2d.pmc | 14 +++++++++++- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/pmc/complexmatrix2d.pmc b/src/pmc/complexmatrix2d.pmc index c7fd255..6c266cc 100644 --- a/src/pmc/complexmatrix2d.pmc +++ b/src/pmc/complexmatrix2d.pmc @@ -1,7 +1,20 @@ #include "pla.h" - #define PLATYPENAME "ComplexMatrix2D" +/* + +=head1 ComplexMatrix2D + +=head2 Description + +ComplexMatrix2D is a 2-dimensional complex-valued matrix type for the Parrot +Virtual Machine. It supports a variety of element-wise and matrix operations, +including bindings to the BLAS and LAPACK libraries. + +=cut + +*/ + INTVAL __PLA_Type_ComplexMatrix2D; /* If the matrix is lazily transposed, actually transpose the physical memory diff --git a/src/pmc/nummatrix2d.pmc b/src/pmc/nummatrix2d.pmc index 86d3a5e..11e59a2 100644 --- a/src/pmc/nummatrix2d.pmc +++ b/src/pmc/nummatrix2d.pmc @@ -1,6 +1,21 @@ #include "pla.h" #define PLATYPENAME "NumMatrix2D" +/* + +=head1 NumMatrix2D + +=head2 Description + +NumMatrix2D is a 2-dimensional real-valued matrix type for the Parrot Virtual +Machine. It supports a variety of element-wise and matrix operations, including +bindings to the BLAS and LAPACK libraries. + +=cut + +*/ + + INTVAL __PLA_Type_NumMatrix2D; /* Resize the matrix internal storage to be able to hold a point at position @@ -215,9 +230,9 @@ pmclass NumMatrix2D dynpmc auto_attrs provides matrix provides numericmatrix { /* -=head1 VTABLEs +=head2 VTABLEs -=head2 System VTABLEs +=head3 System VTABLEs =over 4 @@ -253,7 +268,7 @@ Destrow the matrix and free it's allocated storage /* -=head2 Keyed Lookup VTABLEs +=head3 Keyed Lookup VTABLEs In each of these cases, the specified Key PMC must have exactly two elements to specify a location in the matrix. @@ -318,7 +333,7 @@ elements. /* -=head2 Integer-Keyed Lookup VTABLES +=head3 Integer-Keyed Lookup VTABLES These VTABLEs treat the matrix, which is a contiguous region in memory, as a linear array of values. The matrix data is stored by rows. @@ -383,7 +398,7 @@ Nth number. The array is arranged in memory row by row. /* -=head2 Keyed Setter VTABLES +=head3 Keyed Setter VTABLES These VTABLEs insert new values into the matrix at a point specified by the Key PMC. The Key PMC must have exactly two elements. If the matrix is not large @@ -440,7 +455,7 @@ must have two elements. /* -=head2 Integer-Keyed Setter VTABLEs +=head3 Integer-Keyed Setter VTABLEs These VTABLEs treat the matrix as a linear array in memory and allow fast lookup based on the integer offset of values in the array. These are low-level @@ -501,7 +516,7 @@ Convert the string to a Complex PMC, and set that at the specified location. /* -=head2 Miscellaneous VTABLEs +=head3 Miscellaneous VTABLEs =over 4 @@ -618,7 +633,7 @@ Determine if two matrices are equal in size and composition. /* -=head2 Serialization/Deserialization VTABLEs +=head3 Serialization/Deserialization VTABLEs =over 4 @@ -679,7 +694,7 @@ Thaw a serialized PMC /* -=head2 Addition VTABLEs +=head3 Addition VTABLEs =over 4 @@ -733,7 +748,7 @@ Add the integer value to every element in the matrix. /* -=head2 In-Place Addition VTABLEs +=head3 In-Place Addition VTABLEs =over 4 @@ -770,7 +785,7 @@ Add the integer value to every element in the matrix. /* -=head2 Subtraction VTABLEs +=head3 Subtraction VTABLEs =over 4 @@ -824,7 +839,7 @@ Add the integer value to every element in the matrix. /* -=head2 In-Place Subtraction VTABLES +=head3 In-Place Subtraction VTABLES =over 4 @@ -861,7 +876,7 @@ Add the integer value to every element in the matrix. /* -=head2 Multiplication VTABLEs +=head3 Multiplication VTABLEs =over 4 @@ -917,7 +932,7 @@ Add the integer value to every element in the matrix. /* -=head2 In-Place Multiplication VTABLEs +=head3 In-Place Multiplication VTABLEs =over 4 @@ -956,7 +971,7 @@ Add the integer value to every element in the matrix. /* -=head1 METHODS +=head2 METHODS =over 4 diff --git a/src/pmc/pmcmatrix2d.pmc b/src/pmc/pmcmatrix2d.pmc index 170bf72..9a7e957 100644 --- a/src/pmc/pmcmatrix2d.pmc +++ b/src/pmc/pmcmatrix2d.pmc @@ -1,7 +1,19 @@ #include "pla.h" - #define PLATYPENAME "PMCMatrix2D" +/* + +=head1 PMCMatrix2D + +=head2 Description + +PMCMatrix2D is a 2-dimensional matrix-like container object for the Parrot +Virtual Machine. + +=cut + +*/ + INTVAL __PLA_Type_PMCMatrix2D; /* Resize the matrix internal storage to be able to hold a point at position