Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix a bunch of tests that were failing after the recent changes. More…

… to fix still
  • Loading branch information...
commit 55ef25f047c594cc2ec75e1003ee295e24ac0bab 1 parent c4b1b92
@Whiteknight authored
View
2  src/builtins/ones.pir
@@ -13,7 +13,7 @@ Create an n x m matrix of ones.
.local pmc A
A = new 'NumMatrix2D'
- A.'fill'(1.0, cols, rows)
+ A.'fill'(1.0, rows, cols)
.return(A)
.end
View
2  src/builtins/zeros.pir
@@ -13,7 +13,7 @@ Create an n x m matrix of zeros.
# NumMatrix2D zero-fills by default
$P0 = new ['NumMatrix2D']
- $P0.'resize'(cols, rows)
+ $P0.'resize'(rows, cols)
.return($P0)
.end
View
88 src/internals/matrix.pir
@@ -176,94 +176,6 @@ Force all rows in matrix m to become String PMCs
.return(newarray)
.end
-=item !range_constructor_two
-
-Construct an array from a range of the form a:b
-
-=item !range_constructor_three
-
-Construct an array from a range of the form a:b:c
-
-=cut
-
-.sub '!range_constructor_two'
- .param pmc start
- .param pmc stop
- $N0 = start
- $N1 = stop
- if $N0 < $N1 goto positive_range
- if $N0 > $N1 goto negative_range
- .return(start)
- positive_range:
- .tailcall '!range_constructor_three'(start, 1, stop)
- negative_range:
- .tailcall '!range_constructor_three'(start, -1, stop)
-.end
-
-.sub '!range_constructor_three'
- .param pmc start
- .param pmc step
- .param pmc stop
- $N0 = start
- $N1 = step
- $N2 = stop
- if $N0 < $N2 goto expect_positive_step
- if $N0 > $N2 goto expect_negative_step
- .return(start)
- expect_positive_step:
- if $N1 <= 0 goto bad_step
- .tailcall '!range_constructor_positive'(start, step, stop)
- expect_negative_step:
- if $N1 >= 0 goto bad_step
- .tailcall '!range_constructor_negative'(start, step, stop)
- bad_step:
- _error_all("Step parameter is incorrect")
-.end
-
-# Actually construct the array. We know a few things right now: start and
-# stop are not equal. Start, stop, and step are all properly aligned so that
-# we won't loop infinitely looking for a value that we can't get.
-.sub '!range_constructor_positive'
- .param pmc start
- .param pmc step
- .param pmc stop
- .local pmc newarray
- newarray = new 'ResizablePMCArray'
- $N0 = start
- $N1 = step
- $N2 = stop
- loop_top:
- push newarray, $N0
- $N0 = $N0 + $N1
- if $N0 > $N2 goto loop_end
- goto loop_top
- loop_end:
- $I0 = elements newarray
- $P0 = new ['NumMatrix2D']
- $P0.'initialize_from_array'($I0, 1, newarray)
- .return($P0)
-.end
-
-.sub '!range_constructor_negative'
- .param pmc start
- .param pmc step
- .param pmc stop
- .local pmc newarray
- newarray = new 'ResizablePMCArray'
- $N0 = start
- $N1 = step
- $N2 = stop
- loop_top:
- push newarray, $N0
- $N0 = $N0 + $N1
- if $N0 < $N2 goto loop_end
- goto loop_top
- loop_end:
- $I0 = elements newarray
- $P0 = new ['NumMatrix2D']
- $P0.'initialize_from_array'($I0, 1, newarray)
- .return($P0)
-.end
=item !distribute_matrix_op(PMC a, PMC b, PMC op)
View
58 t/syntax/matrix.t
@@ -1,42 +1,34 @@
-disp("1..27");
+plan(27);
% First, test that we can index a matrix like a vector using the same semantics
% as Octave has
-function matrix_tester1(a, b, c)
- if a(b) == c
- printf("ok %d\n", b);
- else
- printf("not ok %d\n", b);
- end
-endfunction
-
foo = [1 2 3;4 5 6];
-matrix_tester1(foo, 1, 1);
-matrix_tester1(foo, 2, 4);
-matrix_tester1(foo, 3, 2);
-matrix_tester1(foo, 4, 5);
-matrix_tester1(foo, 5, 3);
-matrix_tester1(foo, 6, 6);
-
-% Test that we can index matrices using matrix indices
-function matrix_tester2(a, b)
- if a == b
- printf("ok %d\n", b + 6);
- else
- printf("not ok %d\n", b + 6);
- end
-endfunction
+is(foo(1), 1);
+is(foo(2), 2);
+is(foo(3), 3);
+is(foo(4), 4);
+is(foo(5), 5);
+is(foo(6), 6);
bar = [1 2 3;4 5 6;7 8 9];
-matrix_tester2(bar(1, 1), 1);
-matrix_tester2(bar(1, 2), 2);
-matrix_tester2(bar(1, 3), 3);
-matrix_tester2(bar(2, 1), 4);
-matrix_tester2(bar(2, 2), 5);
-matrix_tester2(bar(2, 3), 6);
-matrix_tester2(bar(3, 1), 7);
-matrix_tester2(bar(3, 2), 8);
-matrix_tester2(bar(3, 3), 9);
+bar(1, 1)
+bar(1, 2)
+bar(1, 3)
+bar(2, 1)
+bar(2, 2)
+bar(2, 3)
+bar(3, 1)
+bar(3, 2)
+bar(3, 3)
+is(bar(1, 1), 1);
+is(bar(1, 2), 2);
+is(bar(1, 3), 3);
+is(bar(2, 1), 4);
+is(bar(2, 2), 5);
+is(bar(2, 3), 6);
+is(bar(3, 1), 7);
+is(bar(3, 2), 8);
+is(bar(3, 3), 9);
% Relational operator tests
a = [1 2 3;4 5 6];
View
2  t/syntax/range.t
@@ -11,7 +11,7 @@ X = 1:2:10;
Y = [1 3 5 7 9];
is(X, Y, "three-argument range with non-unity step");
-X = 5:1
+X = 5:1;
Y = [5 4 3 2 1];
is(X, Y, "two-argument range with implied negative step");
View
4 t/syntax/varargin.t
@@ -4,9 +4,9 @@ function v = getvarargs(varargin)
v = varargin;
endfunction
-x = getvarargs(7, 8, 9)
+x = getvarargs(7, 8, 9);
is(parrot_typeof(x), "PMCMatrix2D", "varargin is a PMCMatrix2D");
ok(iscell(x), "varargin is a cell array");
is(x(1), 7, "varargin(1)");
is(x(2), 8, "varargin(2)");
-is(x(3), 9, "varargin(3)");
+is(x(3), 9, "varargin(3)");
View
86 t/syntax/vectors.t
@@ -1,52 +1,42 @@
-disp("1..19");
+plan(19);
% Test indexing into vectors
-function vector_tester(a, b, c)
- if a == b
- printf("ok %d\n", c);
- else
- printf("not ok %d\n", c);
- end
-endfunction
+
a = [1 2 3 4];
-vector_tester(a(1), 1, 1);
-vector_tester(a(2), 2, 2);
-vector_tester(a(3), 3, 3);
-vector_tester(a(4), 4, 4);
+is(a(1), 1);
+is(a(2), 2);
+is(a(3), 3);
+is(a(4), 4);
b = [1;2;3;4];
-vector_tester(b(1), 1, 5);
-vector_tester(b(2), 2, 6);
-vector_tester(b(3), 3, 7);
-vector_tester(b(4), 4, 8);
+is(b(1), 1);
+is(b(2), 2);
+is(b(3), 3);
+is(b(4), 4);
% Relational operator tests
a = [1 2 3];
b = [1 2 3];
c = [4 5 6];
-if a == b
- disp("ok 9");
-else
- disp("not ok 9");
-end
+is(a, b, "equal row vectors are equal);
if a == c
- disp("not ok 10");
+ ok(0, "inequal vectors are apparently equal");
else
- disp("ok 10");
+ ok(1, "equal column vectors are equal");
end
if a != b
- disp("not ok 11");
+ ok(0, "equal vectors are apparently inequal");
else
- disp("ok 11");
+ ok(1, "equal vectors are not inequal");
end
if a != c
- disp("ok 12");
+ ok(1, "inequal vectors are inequal");
else
- disp("not ok 12");
+ ok(0, "inequal vectors aren't inequal");
end
% Test the use of whitespace in specifying column vectors:
@@ -54,62 +44,34 @@ foo = [1
2
3];
bar = [1;2;3];
-if foo == bar
- disp("ok 13");
-else
- disp("not ok 13");
-end
+is(foo, bar, "matrix rows using different syntax);
% Test that we can assign to a row vector cell
y = [1 2 3];
y(3) = 4;
-if y == [1 2 4]
- disp("ok 14");
-else
- disp("not ok 14");
-endif
+is(y, [1 2 4]);
% Test that we can assign to a column vector cell
y = [1;2;3];
y(3) = 4;
-if y == [1;2;4]
- disp("ok 15");
-else
- disp("not ok 15");
-endif
+is(y, [1;2;4]);
% Test that assigning to a row vector causes autoextending
y = [1 2 3];
y(5) = 5;
-if y == [1 2 3 0 5]
- disp("ok 16");
-else
- disp("not ok 16");
-endif
+is(y, [1 2 3 0 5]);
% Test that assigning to a column vector causes autoextending
y = [1;2;3];
y(5) = 5;
-if y == [1;2;3;0;5]
- disp("ok 17");
-else
- disp("not ok 17");
-endif
+is(y, [1;2;3;0;5]);
% Test that a 1x1 matrix autoextends like a row vector
y = [1];
y(3) = 3;
-if y == [1 0 3]
- disp("ok 18");
-else
- disp("not ok 18");
-endif
+is(y, [1 0 3]);
% Test that row vectors autovivify when we assign to an index of them
_not_existing_vector(3) = 3;
-if _not_existing_vector == [0 0 3]
- disp("ok 19");
-else
- disp("not ok 19");
-endif
+is(_not_existing_vector, [0 0 3]);
View
6 toolbox/isscalar.m
@@ -1,8 +1,10 @@
function isscalar(A)
%% isscalar(A)
%% returns 1 if A is 1 x 1 matrix
- if columns(A) == 1 and rows(A) == 1
- return 1
+ if columns(A) == 1
+ if rows(A) == 1
+ return 1
+ end
end
return 0
endfunction
Please sign in to comment.
Something went wrong with that request. Please try again.