Skip to content

Commit

Permalink
upgrade the is_equal vtable to handle lazily tranposed matrices. This…
Browse files Browse the repository at this point in the history
… isn't good for performance, but we can optimize later. Add tests for transpose and mem_transpose methods
  • Loading branch information
Whiteknight committed Nov 2, 2009
1 parent 1bcaec7 commit b844ab6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/pmc/nummatrix2d.pmc
Expand Up @@ -353,8 +353,10 @@ pmclass NumMatrix2D dynpmc auto_attrs {
if (other->vtable->base_type == SELF->vtable->base_type) {
Parrot_NumMatrix2D_attributes * const self_attrs = PARROT_NUMMATRIX2D(SELF);
Parrot_NumMatrix2D_attributes * const other_attrs = PARROT_NUMMATRIX2D(other);
const INTVAL self_is_transposed = IS_TRANSPOSED(self_attrs->flags);
const INTVAL self_x = self_attrs->x;
const INTVAL self_y = self_attrs->y;
const INTVAL other_is_transposed = IS_TRANSPOSED(other_attrs->flags);
const INTVAL other_x = other_attrs->x;
const INTVAL other_y = other_attrs->y;
FLOATVAL * const self_s = self_attrs->storage;
Expand All @@ -366,8 +368,12 @@ pmclass NumMatrix2D dynpmc auto_attrs {

for (y = 0; y < self_y; y++) {
for (x = 0; x < self_x; x++) {
const FLOATVAL self_value = ITEM_XY_ROWMAJOR(self_s, self_x, self_y, x, y);
const FLOATVAL other_value = ITEM_XY_ROWMAJOR(other_s, other_x, other_y, x, y);
const FLOATVAL self_value = self_is_transposed ?
ITEM_XY_COLMAJOR(self_s, self_x, self_y, x, y) :
ITEM_XY_ROWMAJOR(self_s, self_x, self_y, x, y);
const FLOATVAL other_value = other_is_transposed ?
ITEM_XY_COLMAJOR(other_s, other_x, other_y, x, y) :
ITEM_XY_ROWMAJOR(other_s, other_x, other_y, x, y);
if (self_value != other_value)
return 0;
}
Expand Down
69 changes: 66 additions & 3 deletions t/10-nummatrix.t
Expand Up @@ -18,7 +18,7 @@ sub MAIN () {
pla_library_loaded:
};

plan(61);
plan(65);

create_nummatrix2d();
vtable_set_number_keyed();
Expand Down Expand Up @@ -392,6 +392,69 @@ sub method_resize() {
}

sub method_fill() {}
sub method_transpose() {}
sub method_mem_transpose() {}

sub method_transpose() {
Q:PIR {
$P0 = new 'NumMatrix2D'
$P0[1;2] = 6.0
$P0[1;1] = 5.0
$P0[1;0] = 4.0
$P0[0;2] = 3.0
$P0[0;1] = 2.0
$P0[0;0] = 1.0
say "P0: "
say $P0
$P1 = new 'NumMatrix2D'
$P1[2;1] = 6.0
$P1[1;1] = 5.0
$P1[0;1] = 4.0
$P1[2;0] = 3.0
$P1[1;0] = 2.0
$P1[0;0] = 1.0
say "P1: "
say $P1
$P2 = clone $P0
$I0 = $P2 == $P0
ok($I0, "a clone is not transposed")
say "P2 as P0: "
say $P2
$P2.'transpose'()
$I0 = $P1 == $P2
ok($I0, "transpose does what it should")
say "P2 transposed: "
say $P2
}
}
sub method_mem_transpose() {
Q:PIR {
$P0 = new 'NumMatrix2D'
$P0[1;2] = 6.0
$P0[1;1] = 5.0
$P0[1;0] = 4.0
$P0[0;2] = 3.0
$P0[0;1] = 2.0
$P0[0;0] = 1.0
$P1 = new 'NumMatrix2D'
$P1[2;1] = 6.0
$P1[1;1] = 5.0
$P1[0;1] = 4.0
$P1[2;0] = 3.0
$P1[1;0] = 2.0
$P1[0;0] = 1.0
$P2 = clone $P0
$I0 = $P2 == $P0
ok($I0, "a clone is not mem_transposed")
$P2.'mem_transpose'()
$I0 = $P2 == $P1
ok($I0, "transpose does what it should")
}
}
sub method_iterate_function_inplace() {}

0 comments on commit b844ab6

Please sign in to comment.