-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jot down a quick wrapper for NumMatrix2D for Rakudo. I haven't tested…
… it and have no reason to suspect that it's sane.
- Loading branch information
1 parent
b185b2c
commit 2694048
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | ||
} | ||
|
||
} |