Skip to content

Commit

Permalink
update the rakudo class, and add a short example file proving that at…
Browse files Browse the repository at this point in the history
… least some of it works
  • Loading branch information
Whiteknight committed Aug 15, 2010
1 parent 2694048 commit 3489a10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions examples/nummatrix2d.rakudo.pm
@@ -0,0 +1,6 @@
use v6;
use src::rakudo::nummatrix2d;

my $matrix = P6NumMatrix2D.new();
$matrix.fill(1.0, 2, 2);
say $matrix;
31 changes: 23 additions & 8 deletions src/rakudo/nummatrix2d.pm
@@ -1,14 +1,30 @@
class NumMatrix2D does Matrix {
class P6NumMatrix2D {

has $.matrix;

method new(:$matrix?) {
my $new = self.bless(*);
my $m = $matrix;
unless $matrix.defined {
$matrix = pir::new__PS("NumMatrix2D");
Q:PIR {
$P0 = get_root_global "PLALibrary"
unless null $P0 goto __PLA_have_library
$P0 = loadlib "linalg_group"
set_root_global "PLALibrary", $P0
unless null $P0 goto __PLA_have_library
die "cannot load linalg_group"
__PLA_have_library:
$P1 = root_new ["parrot";"NumMatrix2D"]
store_lex '$m', $P1
};
}
pir::setattribute__vpsp($new, "$!matrix", $matrix);
my $new = self.bless(*, matrix => $m);
return $new;
}

method Str() {
return ~$.matrix;
}

multi method get($row, $col) {
return self!matrix.item_at($row, $col);
}
Expand Down Expand Up @@ -37,14 +53,13 @@ class NumMatrix2D does Matrix {
}

method fill($value, *@coords) {
if +@coords == 0 { self!matrix.fill($value); }
elsif +@coords == 1 { self!matrix.fill($value, @coords[0]); }
elsif +@coords == 2 { self!matrix.fill($value, @coords[0], @coords[1]; }
if +@coords == 0 { $.matrix.fill($value); }
elsif +@coords == 1 { $.matrix.fill($value, @coords[0]); }
elsif +@coords == 2 { $.matrix.fill($value, @coords[0], @coords[1]); }
}

method transpose(:$mem?) {
if $mem.defined { self!matrix.mem_transpose(); }
else { self!matrix.transpose(); }
}

}

0 comments on commit 3489a10

Please sign in to comment.