Skip to content

Commit

Permalink
add cell() and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 8, 2009
1 parent 6fe5948 commit 95a1beb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions t/functions/cell.t
@@ -0,0 +1,10 @@
plan(6);
x = cell(2);
is(parrot_typeof(x), "PMCMatrix2D", "cell is PMCMatrix2D");
is(iscell(x), 1, "cell is cell");
is(columns(x), 2, "cell(n) is square, columns");
is(rows(x), 2, "cell(n) is square, rows");

y = cell(3, 4);
is(columns(y), 3, "cell(n, m) is rectangle, columns");
is(rows(y), 4, "cell(n, m) is rectangle, rows");
15 changes: 15 additions & 0 deletions toolbox/cell.m
@@ -0,0 +1,15 @@
function c = cell(y, x)
% Creates a new cell array.
% If one argument is provided, cell will be NxN square
% If two arguments are provided, cell will be NxM
if nargin == 1
x = y;
end
c = pir([".sub cell_helper"
" .param int y"
" .param int x"
" $P0 = new ['PMCMatrix2D']"
" $P0.'resize'(y, x)"
" .return($P0)"
".end"], y, x);
endfunction

0 comments on commit 95a1beb

Please sign in to comment.