Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Whiteknight/parrot-linear-algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 7, 2009
2 parents e63fd33 + 3b4cd5a commit 76d299d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 79 deletions.
7 changes: 7 additions & 0 deletions PLATFORMS
Expand Up @@ -8,6 +8,13 @@ Ubuntu 9.04: Supported
sudo apt-get install libatlas-base-dev
+ C Compilers:

Ubuntu 9.10: Supported
+ Parrot: 1.8.0
+ BLAS: Atlas
sudo apt-get install libatlas3-base
sudo apt-get install libatlas-base-dev
+ C Compilers: gcc-4.4.1

Fedora 12: Supported
+ Parrot: 1.8.0
+ BLAS: Atlas
Expand Down
8 changes: 8 additions & 0 deletions src/pmc/complexmatrix2d.pmc
Expand Up @@ -223,6 +223,8 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix {

=item* set_pmc_keyed

=item* set_string_keyed

=cut

*/
Expand All @@ -232,6 +234,12 @@ pmclass ComplexMatrix2D dynpmc auto_attrs provides matrix {
GET_KEY_INDICES_ROWMAJOR(INTERP, key, rows, cols);
set_complex_pmc_at_xy(INTERP, SELF, value, rows, cols);
}

VTABLE void set_string_keyed(PMC * key, STRING * value) {
PMC * const item = pmc_new(INTERP, enum_class_Complex);
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}

/*

Expand Down
34 changes: 33 additions & 1 deletion src/pmc/pmcmatrix2d.pmc
Expand Up @@ -73,10 +73,20 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
GET_KEY_INDICES_ROWMAJOR(INTERP, key, x, y);
if (x >= x_size || y >= y_size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"NumMatrix2d: indices out of bounds");
"PMCMatrix2d: indices out of bounds");
return ITEM_XY_ROWMAJOR(attrs->storage, x_size, y_size, x, y);
}

VTABLE PMC * get_pmc_keyed_int(INTVAL key) {
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
const INTVAL total_size = attrs->x * attrs->y;
if (key >= total_size || key < 0) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"PMCMatrix2D: indices out of bounds.");
}
return attrs->storage[key];
}

VTABLE INTVAL get_integer_keyed(PMC * key) {
PMC * item = VTABLE_get_pmc_keyed(INTERP, SELF, key);
return VTABLE_get_integer(INTERP, item);
Expand Down Expand Up @@ -148,4 +158,26 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
pstr = Parrot_str_append(INTERP, pstr, newline);
return pstr;
}

METHOD initialize_from_array(INTVAL rows_size, INTVAL cols_size, PMC * values) {
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
PMC ** s;
INTVAL self_rows, self_cols, i, j, num = 0;
const INTVAL init_elems = VTABLE_elements(interp, values);

resize_matrix(interp, SELF, rows_size - 1, cols_size - 1);
self_rows = attrs->y;
self_cols = attrs->x;
s = attrs->storage;

for (i = 0; i < cols_size; i++) {
for (j = 0; j < rows_size; j++) {
PMC * const value = VTABLE_get_pmc_keyed_int(interp, values, num);
num++;
ITEM_XY_ROWMAJOR(s, self_rows, self_cols, j, i) = value;
if (num >= init_elems)
return;
}
}
}
}
5 changes: 4 additions & 1 deletion t/harness
Expand Up @@ -79,7 +79,10 @@ sub MAIN () {
}
}
if $total_failed {
say("FAILED " ~ $total_failed ~ '/' ~ ($total_passed+$total_failed));
say("FAILED " ~ $total_failed ~ '/' ~ ($total_passed+$total_failed));
Q:PIR {
exit 1
}
} elsif $failed_files {
say("FAILED " ~ $failed_files ~ " files, PASSED " ~ $total_passed ~ ' tests');
} else {
Expand Down
118 changes: 42 additions & 76 deletions t/pmc/complexmatrix2d.t
Expand Up @@ -26,6 +26,7 @@ sub MAIN () {
vtable_get_string_keyed();
vtable_get_pmc_keyed();
vtable_set_pmc_keyed();
vtable_set_string_keyed();
vtable_get_string();
vtable_get_attr_string();
vtable_clone();
Expand Down Expand Up @@ -68,6 +69,7 @@ sub vtable_get_integer_keyed() {}
sub vtable_get_string_keyed() {}
sub vtable_get_pmc_keyed() {}
sub vtable_set_pmc_keyed() {}
sub vtable_set_string_keyed() {}
sub vtable_get_string() {}
sub vtable_get_attr_string() {}
sub vtable_clone() {}
Expand All @@ -78,117 +80,81 @@ sub method_fill() {}
sub method_transpose() {
Q:PIR {
$P0 = new ['ComplexMatrix2D']
$P1 = new ['Complex']
$P1 = "1+1i"
$P0[0;0] = $P1
$P1 = "2+2i"
$P0[0;1] = $P1
$P1 = "3+3i"
$P0[1;0] = $P1
$P1 = "4+4i"
$P0[1;1] = $P1
$P0[0;0] = "1+1i"
$P0[0;1] = "2+2i"
$P0[1;0] = "3+3i"
$P0[1;1] = "4+4i"

$P2 = new ['ComplexMatrix2D']
$P1 = "1+1i"
$P2[0;0] = $P1
$P1 = "3+3i"
$P2[0;1] = $P1
$P1 = "2+2i"
$P2[1;0] = $P1
$P1 = "4+4i"
$P2[1;1] = $P1
$P1 = new ['ComplexMatrix2D']
$P1[0;0] = "1+1i"
$P1[0;1] = "3+3i"
$P1[1;0] = "2+2i"
$P1[1;1] = "4+4i"

$P0.'transpose'()
$I0 = $P0 == $P2
$I0 = $P0 == $P1
ok($I0, "can transpose a ComplexMatrix2D")
}
}

sub method_mem_transpose() {
Q:PIR {
$P0 = new ['ComplexMatrix2D']
$P1 = new ['Complex']
$P1 = "1+1i"
$P0[0;0] = $P1
$P1 = "2+2i"
$P0[0;1] = $P1
$P1 = "3+3i"
$P0[1;0] = $P1
$P1 = "4+4i"
$P0[1;1] = $P1
$P0[0;0] = "1+1i"
$P0[0;1] = "2+2i"
$P0[1;0] = "3+3i"
$P0[1;1] = "4+4i"
$P2 = new ['ComplexMatrix2D']
$P1 = "1+1i"
$P2[0;0] = $P1
$P1 = "3+3i"
$P2[0;1] = $P1
$P1 = "2+2i"
$P2[1;0] = $P1
$P1 = "4+4i"
$P2[1;1] = $P1
$P1 = new ['ComplexMatrix2D']
$P1[0;0] = "1+1i"
$P1[0;1] = "3+3i"
$P1[1;0] = "2+2i"
$P1[1;1] = "4+4i"
$P0.'mem_transpose'()
$I0 = $P0 == $P2
$I0 = $P0 == $P1
ok($I0, "can mem_transpose a ComplexMatrix2D")
}
}
sub method_conjugate() {
Q:PIR {
$P0 = new ['ComplexMatrix2D']
$P1 = new ['Complex']
$P1 = "1+1i"
$P0[0;0] = $P1
$P1 = "2+2i"
$P0[0;1] = $P1
$P1 = "3+3i"
$P0[1;0] = $P1
$P1 = "4+4i"
$P0[1;1] = $P1
$P0[0;0] = "1+1i"
$P0[0;1] = "2+2i"
$P0[1;0] = "3+3i"
$P0[1;1] = "4+4i"

$P2 = new ['ComplexMatrix2D']
$P1 = "1-1i"
$P2[0;0] = $P1
$P1 = "2-2i"
$P2[0;1] = $P1
$P1 = "3-3i"
$P2[1;0] = $P1
$P1 = "4-4i"
$P2[1;1] = $P1
$P1 = new ['ComplexMatrix2D']
$P1[0;0] = "1-1i"
$P1[0;1] = "2-2i"
$P1[1;0] = "3-3i"
$P1[1;1] = "4-4i"

$P0.'conjugate'()
$I0 = $P0 == $P2
$I0 = $P0 == $P1
ok($I0, "can conjugate a ComplexMatrix2D")
}
}

sub method_iterate_function_inplace() {
Q:PIR {
$P0 = new ['ComplexMatrix2D']
$P1 = new ['Complex']
$P1 = "1+1i"
$P0[0;0] = $P1
$P1 = "2+2i"
$P0[0;1] = $P1
$P1 = "3+3i"
$P0[1;0] = $P1
$P1 = "4+4i"
$P0[1;1] = $P1
$P0[0;0] = "1+1i"
$P0[0;1] = "2+2i"
$P0[1;0] = "3+3i"
$P0[1;1] = "4+4i"
$P2 = new ['ComplexMatrix2D']
$P1 = "3.5+1i"
$P2[0;0] = $P1
$P1 = "4.5+2i"
$P2[0;1] = $P1
$P1 = "5.5+3i"
$P2[1;0] = $P1
$P1 = "6.5+4i"
$P2[1;1] = $P1
$P1 = new ['ComplexMatrix2D']
$P1[0;0] = "3.5+1i"
$P1[0;1] = "4.5+2i"
$P1[1;0] = "5.5+3i"
$P1[1;1] = "6.5+4i"
.local pmc helper
helper = get_global "_iterate_inplace_helper"
$P0.'iterate_function_inplace'(helper)
$I0 = $P0 == $P2
$I0 = $P0 == $P1
ok($I0, "can iterate a function in place with no args")
}
}
Expand Down
4 changes: 3 additions & 1 deletion t/00-sanity.t → t/sanity.t
Expand Up @@ -19,11 +19,13 @@ sub MAIN () {
sub load_linalg_group() {
Q:PIR {
.local pmc pla
pla = loadlib "./dynext/linalg_group"
pla = loadlib "./linalg_group"
if pla goto has_linalg_group
ok(0, "loading linalg_group failed")
goto _end
has_linalg_group:
ok(1, "has linalg_group library available")
_end:
}
}

0 comments on commit 76d299d

Please sign in to comment.