Skip to content

Commit

Permalink
jot down a quick wrapper for NumMatrix2D for Rakudo. I haven't tested…
Browse files Browse the repository at this point in the history
… it and have no reason to suspect that it's sane.
  • Loading branch information
Whiteknight committed Aug 14, 2010
1 parent b185b2c commit 2694048
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/rakudo/nummatrix2d.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class NumMatrix2D does Matrix {

method new(:$matrix?) {
my $new = self.bless(*);
unless $matrix.defined {
$matrix = pir::new__PS("NumMatrix2D");
}
pir::setattribute__vpsp($new, "$!matrix", $matrix);
return $new;
}

multi method get($row, $col) {
return self!matrix.item_at($row, $col);
}

multi method get($row, $col, $rows, $cols) {
my $block = self.get_block($row, $col, $rows, $cols);
my $new = NumMatrix2D.new($block);
return $new;
}

method set($row, $col, $val) {
self!matrix.item_at($row, $col, $val);
}

method set($row, $col, $rows, $cols, $block) {
self!matrix.set_block($row, $col, $rows, $cols, $block);
}

method map(&block) {
my $matrix = self!iterate_function_external(
-> $me, $val, $row, $col {
&block($val);
});
my $new = NumMatrix2D.new($matrix);
return $new;
}

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]; }
}

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

}

0 comments on commit 2694048

Please sign in to comment.