comparison src/data.cc @ 14429:eff4a5933e28

Update %!tests in src/ directory with Octave coding conventions. * data.cc, defaults.cc, dirfns.cc, file-io.cc, graphics.cc, mappers.cc, oct-map.cc, octave.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-range.cc, ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov.cc, pr-output.cc, pt-binop.cc, pt-eval.cc, pt-idx.cc, pt-mat.cc, sighandlers.cc, strfns.cc, symtab.cc, syscalls.cc, sysdep.cc, toplev.cc, utils.cc, variables.cc: Update %!tests in src/ directory with Octave coding conventions.
author Rik <octave@nomad.inbox5.com>
date Sun, 04 Mar 2012 12:21:10 -0800
parents 8de863b7126b
children 5bd9e47e9277
comparison
equal deleted inserted replaced
14428:099bd779466c 14429:eff4a5933e28
130 { 130 {
131 ANY_ALL (all); 131 ANY_ALL (all);
132 } 132 }
133 133
134 /* 134 /*
135
136 %!test 135 %!test
137 %! x = ones (3); 136 %! x = ones (3);
138 %! x(1,1) = 0; 137 %! x(1,1) = 0;
139 %! assert((all (all (rand (3) + 1) == [1, 1, 1]) == 1 138 %! assert (all (all (rand (3) + 1) == [1, 1, 1]) == 1);
140 %! && all (all (x) == [0, 1, 1]) == 1 139 %! assert (all (all (x) == [0, 1, 1]) == 1);
141 %! && all (x, 1) == [0, 1, 1] 140 %! assert (all (x, 1) == [0, 1, 1]);
142 %! && all (x, 2) == [0; 1; 1])); 141 %! assert (all (x, 2) == [0; 1; 1]);
143 142
144 %!test 143 %!test
145 %! x = ones (3, 'single'); 144 %! x = ones (3, "single");
146 %! x(1,1) = 0; 145 %! x(1,1) = 0;
147 %! assert((all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1 146 %! assert (all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1);
148 %! && all (all (x) == [0, 1, 1]) == 1 147 %! assert (all (all (x) == [0, 1, 1]) == 1);
149 %! && all (x, 1) == [0, 1, 1] 148 %! assert (all (x, 1) == [0, 1, 1]);
150 %! && all (x, 2) == [0; 1; 1])); 149 %! assert (all (x, 2) == [0; 1; 1]);
151 150
152 %!error <Invalid call to all> all (); 151 %!error all ()
153 %!error <Invalid call to all> all (1, 2, 3); 152 %!error all (1, 2, 3)
154 153 */
155 */
156 154
157 DEFUN (any, args, , 155 DEFUN (any, args, ,
158 "-*- texinfo -*-\n\ 156 "-*- texinfo -*-\n\
159 @deftypefn {Built-in Function} {} any (@var{x})\n\ 157 @deftypefn {Built-in Function} {} any (@var{x})\n\
160 @deftypefnx {Built-in Function} {} any (@var{x}, @var{dim})\n\ 158 @deftypefnx {Built-in Function} {} any (@var{x}, @var{dim})\n\
186 { 184 {
187 ANY_ALL (any); 185 ANY_ALL (any);
188 } 186 }
189 187
190 /* 188 /*
191
192 %!test 189 %!test
193 %! x = zeros (3); 190 %! x = zeros (3);
194 %! x(3,3) = 1; 191 %! x(3,3) = 1;
195 %! assert((all (any (x) == [0, 0, 1]) == 1 192 %! assert (all (any (x) == [0, 0, 1]) == 1);
196 %! && all (any (ones (3)) == [1, 1, 1]) == 1 193 %! assert (all (any (ones (3)) == [1, 1, 1]) == 1);
197 %! && any (x, 1) == [0, 0, 1] 194 %! assert (any (x, 1) == [0, 0, 1]);
198 %! && any (x, 2) == [0; 0; 1])); 195 %! assert (any (x, 2) == [0; 0; 1]);
199 196
200 %!test 197 %!test
201 %! x = zeros (3,'single'); 198 %! x = zeros (3, "single");
202 %! x(3,3) = 1; 199 %! x(3,3) = 1;
203 %! assert((all (any (x) == [0, 0, 1]) == 1 200 %! assert (all (any (x) == [0, 0, 1]) == 1);
204 %! && all (any (ones (3, 'single')) == [1, 1, 1]) == 1 201 %! assert (all (any (ones (3, "single")) == [1, 1, 1]) == 1);
205 %! && any (x, 1) == [0, 0, 1] 202 %! assert (any (x, 1) == [0, 0, 1]);
206 %! && any (x, 2) == [0; 0; 1])); 203 %! assert (any (x, 2) == [0; 0; 1]);
207 204
208 %!error <Invalid call to any> any (); 205 %!error any ()
209 %!error <Invalid call to any> any (1, 2, 3); 206 %!error any (1, 2, 3)
210 207 */
211 */
212 208
213 // These mapping functions may also be useful in other places, eh? 209 // These mapping functions may also be useful in other places, eh?
214 210
215 DEFUN (atan2, args, , 211 DEFUN (atan2, args, ,
216 "-*- texinfo -*-\n\ 212 "-*- texinfo -*-\n\
281 %! rt2 = sqrt (2); 277 %! rt2 = sqrt (2);
282 %! rt3 = sqrt (3); 278 %! rt3 = sqrt (3);
283 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]; 279 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
284 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0]; 280 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0];
285 %! x = [1, 3, 1, 1, 1, 1, 3, 1]; 281 %! x = [1, 3, 1, 1, 1, 1, 3, 1];
286 %! assert(atan2 (y, x), v, sqrt (eps)); 282 %! assert (atan2 (y, x), v, sqrt (eps));
287 283
288 %!test 284 %!test
289 %! rt2 = sqrt (2); 285 %! rt2 = sqrt (2);
290 %! rt3 = sqrt (3); 286 %! rt3 = sqrt (3);
291 %! v = single([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]); 287 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
292 %! y = single([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]); 288 %! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]);
293 %! x = single([1, 3, 1, 1, 1, 1, 3, 1]); 289 %! x = single ([1, 3, 1, 1, 1, 1, 3, 1]);
294 %! assert(atan2 (y, x), v, sqrt (eps('single'))); 290 %! assert (atan2 (y, x), v, sqrt (eps ("single")));
295 291
296 %!error <Invalid call to atan2> atan2 (); 292 %!error atan2 ()
297 %!error <Invalid call to atan2> atan2 (1, 2, 3); 293 %!error atan2 (1, 2, 3)
298
299 */ 294 */
300 295
301 296
302 static octave_value 297 static octave_value
303 do_hypot (const octave_value& x, const octave_value& y) 298 do_hypot (const octave_value& x, const octave_value& y)
395 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2]) 390 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
396 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) 391 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
397 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4]) 392 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
398 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4]) 393 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
399 %!assert (size (hypot (1, 2)), [1, 1]) 394 %!assert (size (hypot (1, 2)), [1, 1])
400 %!assert (hypot (1:10, 1:10), sqrt(2) * [1:10], 16*eps) 395 %!assert (hypot (1:10, 1:10), sqrt (2) * [1:10], 16*eps)
401 %!assert (hypot (single(1:10), single(1:10)), single(sqrt(2) * [1:10])); 396 %!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10]))
402 */ 397 */
403 398
404 template<typename T, typename ET> 399 template<typename T, typename ET>
405 void 400 void
406 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e) 401 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e)
496 491
497 return retval; 492 return retval;
498 } 493 }
499 494
500 /* 495 /*
501 %!assert(log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2]); 496 %!assert (log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2])
502 %!assert(log2(Inf), Inf); 497 %!assert (log2 (Inf), Inf)
503 %!assert(isnan(log2(NaN))); 498 %!assert (isnan (log2 (NaN)))
504 %!assert(log2(4*i), 2 + log2(1*i)); 499 %!assert (log2 (4*i), 2 + log2 (1*i))
505 %!assert(log2(complex(0,Inf)), Inf + log2(i)); 500 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
506 501
507 %!test 502 %!test
508 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); 503 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
509 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]); 504 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]);
510 %! assert (e(1:2,:), [0,1;2,3]) 505 %! assert (e(1:2,:), [0,1;2,3]);
511 506
512 %!test 507 %!test
513 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf])); 508 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
514 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf])); 509 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
515 %! assert (e(1:2,:), [0,1; 2,3]); 510 %! assert (e(1:2,:), [0,1; 2,3]);
618 613
619 return retval; 614 return retval;
620 } 615 }
621 616
622 /* 617 /*
623 618 %!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1])
624 %!assert(rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]); 619 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1])
625 %!assert(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]); 620 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8 ([1, 0, 1; -1, 0, -1]))
626 %!error rem (); 621 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1]))
627 %!error rem (1, 2, 3); 622
628 %!error rem ([1, 2], [3, 4, 5]); 623 %!error rem (uint (8), int8 (5))
629 %!error rem (i, 1); 624 %!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5]))
630 %!assert(rem (uint8([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8([1, 0, 1; -1, 0, -1])); 625 %!error rem ()
631 %!assert(uint8(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8([1, 0, 1; -1, 0, -1])); 626 %!error rem (1, 2, 3)
632 %!error rem (uint(8),int8(5)); 627 %!error rem ([1, 2], [3, 4, 5])
633 %!error rem (uint8([1, 2]), uint8([3, 4, 5])); 628 %!error rem (i, 1)
634
635 */ 629 */
636 630
637 /* 631 /*
632
638 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2]) 633 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2])
639 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) 634 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
640 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4]) 635 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4])
641 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4]) 636 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4])
642 %!assert (size (fmod (1, 2)), [1, 1]) 637 %!assert (size (fmod (1, 2)), [1, 1])
752 return retval; 747 return retval;
753 } 748 }
754 749
755 /* 750 /*
756 ## empty input test 751 ## empty input test
757 %!assert (isempty(mod([], []))); 752 %!assert (isempty (mod ([], [])))
758 753
759 ## x mod y, y != 0 tests 754 ## x mod y, y != 0 tests
760 %!assert (mod(5, 3), 2); 755 %!assert (mod (5, 3), 2)
761 %!assert (mod(-5, 3), 1); 756 %!assert (mod (-5, 3), 1)
762 %!assert (mod(0, 3), 0); 757 %!assert (mod (0, 3), 0)
763 %!assert (mod([-5, 5, 0], [3, 3, 3]), [1, 2, 0]); 758 %!assert (mod ([-5, 5, 0], [3, 3, 3]), [1, 2, 0])
764 %!assert (mod([-5; 5; 0], [3; 3; 3]), [1; 2; 0]); 759 %!assert (mod ([-5; 5; 0], [3; 3; 3]), [1; 2; 0])
765 %!assert (mod([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0]); 760 %!assert (mod ([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0])
766 761
767 ## x mod 0 tests 762 ## x mod 0 tests
768 %!assert (mod(5, 0), 5); 763 %!assert (mod (5, 0), 5)
769 %!assert (mod(-5, 0), -5); 764 %!assert (mod (-5, 0), -5)
770 %!assert (mod([-5, 5, 0], [3, 0, 3]), [1, 5, 0]); 765 %!assert (mod ([-5, 5, 0], [3, 0, 3]), [1, 5, 0])
771 %!assert (mod([-5; 5; 0], [3; 0; 3]), [1; 5; 0]); 766 %!assert (mod ([-5; 5; 0], [3; 0; 3]), [1; 5; 0])
772 %!assert (mod([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0]); 767 %!assert (mod ([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0])
773 %!assert (mod([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3]); 768 %!assert (mod ([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3])
774 769
775 ## mixed scalar/matrix tests 770 ## mixed scalar/matrix tests
776 %!assert (mod([-5, 5; 0, 3], 0), [-5, 5; 0, 3]); 771 %!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3])
777 %!assert (mod([-5, 5; 0, 3], 3), [1, 2; 0, 0]); 772 %!assert (mod ([-5, 5; 0, 3], 3), [1, 2; 0, 0])
778 %!assert (mod(-5,[0,0; 0,0]), [-5, -5; -5, -5]); 773 %!assert (mod (-5, [0,0; 0,0]), [-5, -5; -5, -5])
779 %!assert (mod(-5,[3,0; 3,1]), [1, -5; 1, 0]); 774 %!assert (mod (-5, [3,0; 3,1]), [1, -5; 1, 0])
780 %!assert (mod(-5,[3,2; 3,1]), [1, 1; 1, 0]); 775 %!assert (mod (-5, [3,2; 3,1]), [1, 1; 1, 0])
781 776
782 ## integer types 777 ## integer types
783 %!assert (mod(uint8(5),uint8(4)),uint8(1)) 778 %!assert (mod (uint8 (5), uint8 (4)), uint8 (1))
784 %!assert (mod(uint8([1:5]),uint8(4)),uint8([1,2,3,0,1])) 779 %!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1]))
785 %!assert (mod(uint8([1:5]),uint8(0)),uint8([1:5])) 780 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5]))
786 %!error (mod(uint8(5),int8(4))) 781 %!error (mod (uint8 (5), int8 (4)))
787 782
788 ## mixed integer/real types 783 ## mixed integer/real types
789 %!assert (mod(uint8(5),4),uint8(1)) 784 %!assert (mod (uint8 (5), 4), uint8 (1))
790 %!assert (mod(5,uint8(4)),uint8(1)) 785 %!assert (mod (5, uint8 (4)), uint8 (1))
791 %!assert (mod(uint8([1:5]),4),uint8([1,2,3,0,1])) 786 %!assert (mod (uint8 ([1:5]), 4), uint8 ([1,2,3,0,1]))
792 787
793 ## non-integer real numbers 788 ## non-integer real numbers
794 %!assert (mod (2.1, 0.1), 0) 789 %!assert (mod (2.1, 0.1), 0)
795 %!assert (mod (2.1, 0.2), 0.1, eps) 790 %!assert (mod (2.1, 0.2), 0.1, eps)
796 */ 791 */
797 792
798 // FIXME Need to convert the reduction functions of this file for single precision 793 // FIXME: Need to convert the reduction functions of this file for single precision
799 794
800 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ 795 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \
801 (arg.is_ ## TYPE ## _type ()) \ 796 (arg.is_ ## TYPE ## _type ()) \
802 { \ 797 { \
803 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \ 798 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \
1066 { 1061 {
1067 DATA_REDUCTION (cumprod); 1062 DATA_REDUCTION (cumprod);
1068 } 1063 }
1069 1064
1070 /* 1065 /*
1071 1066 %!assert (cumprod ([1, 2, 3]), [1, 2, 6])
1072 %!assert (cumprod ([1, 2, 3]), [1, 2, 6]); 1067 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6])
1073 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6]); 1068 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i])
1074 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i]); 1069 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])
1075 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]); 1070
1076 1071 %!assert (cumprod (single ([1, 2, 3])), single ([1, 2, 6]))
1077 %!assert (cumprod (single([1, 2, 3])), single([1, 2, 6])); 1072 %!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6]))
1078 %!assert (cumprod (single([-1; -2; -3])), single([-1; 2; -6])); 1073 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])), single ([i, -1+2i, -1-8i, -4-32i]))
1079 %!assert (cumprod (single([i, 2+i, -3+2i, 4])), single([i, -1+2i, -1-8i, -4-32i])); 1074 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]))
1080 %!assert (cumprod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])); 1075
1081 1076 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15])
1082 %!error <Invalid call to cumprod> cumprod (); 1077 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20])
1083 1078
1084 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15]); 1079 %!assert (cumprod (single ([2, 3; 4, 5]), 1), single ([2, 3; 8, 15]))
1085 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20]); 1080 %!assert (cumprod (single ([2, 3; 4, 5]), 2), single ([2, 6; 4, 20]))
1086 1081
1087 %!assert (cumprod (single([2, 3; 4, 5]), 1), single([2, 3; 8, 15])); 1082 %!error cumprod ()
1088 %!assert (cumprod (single([2, 3; 4, 5]), 2), single([2, 6; 4, 20])); 1083 */
1089
1090 */
1091 1084
1092 DEFUN (cumsum, args, , 1085 DEFUN (cumsum, args, ,
1093 "-*- texinfo -*-\n\ 1086 "-*- texinfo -*-\n\
1094 @deftypefn {Built-in Function} {} cumsum (@var{x})\n\ 1087 @deftypefn {Built-in Function} {} cumsum (@var{x})\n\
1095 @deftypefnx {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ 1088 @deftypefnx {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\
1217 1210
1218 return retval; 1211 return retval;
1219 } 1212 }
1220 1213
1221 /* 1214 /*
1222 1215 %!assert (cumsum ([1, 2, 3]), [1, 3, 6])
1223 %!assert (cumsum ([1, 2, 3]), [1, 3, 6]); 1216 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6])
1224 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6]); 1217 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i])
1225 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i]); 1218 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])
1226 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]); 1219
1227 1220 %!assert (cumsum (single ([1, 2, 3])), single ([1, 3, 6]))
1228 %!assert (cumsum (single([1, 2, 3])), single([1, 3, 6])); 1221 %!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6]))
1229 %!assert (cumsum (single([-1; -2; -3])), single([-1; -3; -6])); 1222 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])), single ([i, 2+2i, -1+4i, 3+4i]))
1230 %!assert (cumsum (single([i, 2+i, -3+2i, 4])), single([i, 2+2i, -1+4i, 3+4i])); 1223 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]))
1231 %!assert (cumsum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])); 1224
1232 1225 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6])
1233 %!error <Invalid call to cumsum> cumsum (); 1226 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7])
1234 1227
1235 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6]); 1228 %!assert (cumsum (single ([1, 2; 3, 4]), 1), single ([1, 2; 4, 6]))
1236 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7]); 1229 %!assert (cumsum (single ([1, 2; 3, 4]), 2), single ([1, 3; 3, 7]))
1237 1230
1238 %!assert (cumsum (single([1, 2; 3, 4]), 1), single([1, 2; 4, 6])); 1231 %!error cumsum ()
1239 %!assert (cumsum (single([1, 2; 3, 4]), 2), single([1, 3; 3, 7])); 1232 */
1240
1241 */
1242 1233
1243 DEFUN (diag, args, , 1234 DEFUN (diag, args, ,
1244 "-*- texinfo -*-\n\ 1235 "-*- texinfo -*-\n\
1245 @deftypefn {Built-in Function} {@var{M} =} diag (@var{v})\n\ 1236 @deftypefn {Built-in Function} {@var{M} =} diag (@var{v})\n\
1246 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{k})\n\ 1237 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{k})\n\
1306 1297
1307 return retval; 1298 return retval;
1308 } 1299 }
1309 1300
1310 /* 1301 /*
1311 1302 %!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
1312 %!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]); 1303 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
1313 %!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]); 1304 %!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])
1314 %!assert(diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]); 1305 %!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])
1315 %!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]); 1306 %!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])
1316 %!assert(diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]); 1307
1317 1308 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
1318 %!assert(diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]); 1309 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3])
1319 %!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]); 1310 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3])
1320 %!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]); 1311 %!assert (diag (ones (1, 0), 2), zeros (2))
1321 %!assert(diag (ones(1, 0), 2), zeros (2)); 1312 %!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
1322 %!assert(diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]); 1313
1323 1314 %!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
1324 %!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3])); 1315 %!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
1325 %!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); 1316 %!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
1326 %!assert(diag (single([1; 2; 3]), 2), single([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])); 1317 %!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
1327 %!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); 1318 %!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
1328 %!assert(diag (single([1; 2; 3]),-2), single([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])); 1319
1329 1320 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
1330 %!assert(diag (single([1, 0, 0; 0, 2, 0; 0, 0, 3])), single([1; 2; 3])); 1321 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3]))
1331 %!assert(diag (single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single([1; 2; 3])); 1322 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3]))
1332 %!assert(diag (single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single([1; 2; 3])); 1323
1333 1324 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
1334 %!assert(diag (int8([1; 2; 3])), int8([1, 0, 0; 0, 2, 0; 0, 0, 3])); 1325 %!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
1335 %!assert(diag (int8([1; 2; 3]), 1), int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); 1326 %!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
1336 %!assert(diag (int8([1; 2; 3]), 2), int8([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])); 1327 %!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
1337 %!assert(diag (int8([1; 2; 3]),-1), int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); 1328 %!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
1338 %!assert(diag (int8([1; 2; 3]),-2), int8([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])); 1329
1339 1330 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
1340 %!assert(diag (int8([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8([1; 2; 3])); 1331 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3]))
1341 %!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3])); 1332 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3]))
1342 %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3])); 1333
1343 1334 ## Test input validation
1344 %% Test input validation 1335 %!error diag ()
1345 %!error <Invalid call to diag> diag (); 1336 %!error diag (1,2,3,4)
1346 %!error <Invalid call to diag> diag (1,2,3,4); 1337 %!error diag (ones (2), 3, 3)
1347 %!error diag (ones (2), 3, 3); 1338 %!error diag (1:3, -4, 3)
1348 %!error diag (1:3, -4, 3); 1339 */
1349
1350 */
1351 1340
1352 DEFUN (prod, args, , 1341 DEFUN (prod, args, ,
1353 "-*- texinfo -*-\n\ 1342 "-*- texinfo -*-\n\
1354 @deftypefn {Built-in Function} {} prod (@var{x})\n\ 1343 @deftypefn {Built-in Function} {} prod (@var{x})\n\
1355 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ 1344 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\
1360 { 1349 {
1361 DATA_REDUCTION (prod); 1350 DATA_REDUCTION (prod);
1362 } 1351 }
1363 1352
1364 /* 1353 /*
1365 1354 %!assert (prod ([1, 2, 3]), 6)
1366 %!assert (prod ([1, 2, 3]), 6); 1355 %!assert (prod ([-1; -2; -3]), -6)
1367 %!assert (prod ([-1; -2; -3]), -6); 1356 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i)
1368 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i); 1357 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i])
1369 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i]); 1358
1370 1359 %!assert (prod (single ([1, 2, 3])), single (6))
1371 %!assert (prod (single([1, 2, 3])), single(6)); 1360 %!assert (prod (single ([-1; -2; -3])), single (-6))
1372 %!assert (prod (single([-1; -2; -3])), single(-6)); 1361 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i))
1373 %!assert (prod (single([i, 2+i, -3+2i, 4])), single(-4 - 32i)); 1362 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([-1+i, -8+8i, -27+27i]))
1374 %!assert (prod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([-1+i, -8+8i, -27+27i])); 1363
1375 1364 %!assert (prod ([1, 2; 3, 4], 1), [3, 8])
1376 %!error <Invalid call to prod> prod (); 1365 %!assert (prod ([1, 2; 3, 4], 2), [2; 12])
1377 1366 %!assert (prod (zeros (1, 0)), 1)
1378 %!assert (prod ([1, 2; 3, 4], 1), [3, 8]); 1367 %!assert (prod (zeros (1, 0), 1), zeros (1, 0))
1379 %!assert (prod ([1, 2; 3, 4], 2), [2; 12]); 1368 %!assert (prod (zeros (1, 0), 2), 1)
1380 %!assert (prod (zeros (1, 0)), 1); 1369 %!assert (prod (zeros (0, 1)), 1)
1381 %!assert (prod (zeros (1, 0), 1), zeros (1, 0)); 1370 %!assert (prod (zeros (0, 1), 1), 1)
1382 %!assert (prod (zeros (1, 0), 2), 1); 1371 %!assert (prod (zeros (0, 1), 2), zeros (0, 1))
1383 %!assert (prod (zeros (0, 1)), 1); 1372 %!assert (prod (zeros (2, 0)), zeros (1, 0))
1384 %!assert (prod (zeros (0, 1), 1), 1); 1373 %!assert (prod (zeros (2, 0), 1), zeros (1, 0))
1385 %!assert (prod (zeros (0, 1), 2), zeros (0, 1)); 1374 %!assert (prod (zeros (2, 0), 2), [1; 1])
1386 %!assert (prod (zeros (2, 0)), zeros (1, 0)); 1375 %!assert (prod (zeros (0, 2)), [1, 1])
1387 %!assert (prod (zeros (2, 0), 1), zeros (1, 0)); 1376 %!assert (prod (zeros (0, 2), 1), [1, 1])
1388 %!assert (prod (zeros (2, 0), 2), [1; 1]); 1377 %!assert (prod (zeros (0, 2), 2), zeros (0, 1))
1389 %!assert (prod (zeros (0, 2)), [1, 1]); 1378
1390 %!assert (prod (zeros (0, 2), 1), [1, 1]); 1379 %!assert (prod (single ([1, 2; 3, 4]), 1), single ([3, 8]))
1391 %!assert (prod (zeros (0, 2), 2), zeros(0, 1)); 1380 %!assert (prod (single ([1, 2; 3, 4]), 2), single ([2; 12]))
1392 1381 %!assert (prod (zeros (1, 0, "single")), single (1))
1393 %!assert (prod (single([1, 2; 3, 4]), 1), single([3, 8])); 1382 %!assert (prod (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
1394 %!assert (prod (single([1, 2; 3, 4]), 2), single([2; 12])); 1383 %!assert (prod (zeros (1, 0, "single"), 2), single (1))
1395 %!assert (prod (zeros (1, 0, 'single')), single(1)); 1384 %!assert (prod (zeros (0, 1, "single")), single (1))
1396 %!assert (prod (zeros (1, 0, 'single'), 1), zeros (1, 0, 'single')); 1385 %!assert (prod (zeros (0, 1, "single"), 1), single (1))
1397 %!assert (prod (zeros (1, 0, 'single'), 2), single(1)); 1386 %!assert (prod (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
1398 %!assert (prod (zeros (0, 1, 'single')), single(1)); 1387 %!assert (prod (zeros (2, 0, "single")), zeros (1, 0, "single"))
1399 %!assert (prod (zeros (0, 1, 'single'), 1), single(1)); 1388 %!assert (prod (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
1400 %!assert (prod (zeros (0, 1, 'single'), 2), zeros (0, 1, 'single')); 1389 %!assert (prod (zeros (2, 0, "single"), 2), single ([1; 1]))
1401 %!assert (prod (zeros (2, 0, 'single')), zeros (1, 0, 'single')); 1390 %!assert (prod (zeros (0, 2, "single")), single ([1, 1]))
1402 %!assert (prod (zeros (2, 0, 'single'), 1), zeros (1, 0, 'single')); 1391 %!assert (prod (zeros (0, 2, "single"), 1), single ([1, 1]))
1403 %!assert (prod (zeros (2, 0, 'single'), 2), single([1; 1])); 1392 %!assert (prod (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
1404 %!assert (prod (zeros (0, 2, 'single')), single([1, 1])); 1393
1405 %!assert (prod (zeros (0, 2, 'single'), 1), single([1, 1])); 1394 %!error prod ()
1406 %!assert (prod (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); 1395 */
1407
1408 */
1409 1396
1410 static bool 1397 static bool
1411 all_scalar_1x1 (const octave_value_list& args) 1398 all_scalar_1x1 (const octave_value_list& args)
1412 { 1399 {
1413 int n_args = args.length (); 1400 int n_args = args.length ();
1873 { 1860 {
1874 return do_cat (args, -2, "horzcat"); 1861 return do_cat (args, -2, "horzcat");
1875 } 1862 }
1876 1863
1877 /* 1864 /*
1878 %% test concatenation with all zero matrices 1865 ## Test concatenation with all zero matrices
1879 %!assert(horzcat ('', 65*ones(1,10)), 'AAAAAAAAAA'); 1866 %!assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA");
1880 %!assert(horzcat (65*ones(1,10), ''), 'AAAAAAAAAA'); 1867 %!assert (horzcat (65*ones (1,10), ""), "AAAAAAAAAA");
1881 1868
1882 %!assert (class (horzcat (int64(1), int64(1))), 'int64') 1869 %!assert (class (horzcat (int64 (1), int64 (1))), "int64")
1883 %!assert (class (horzcat (int64(1), int32(1))), 'int64') 1870 %!assert (class (horzcat (int64 (1), int32 (1))), "int64")
1884 %!assert (class (horzcat (int64(1), int16(1))), 'int64') 1871 %!assert (class (horzcat (int64 (1), int16 (1))), "int64")
1885 %!assert (class (horzcat (int64(1), int8(1))), 'int64') 1872 %!assert (class (horzcat (int64 (1), int8 (1))), "int64")
1886 %!assert (class (horzcat (int64(1), uint64(1))), 'int64') 1873 %!assert (class (horzcat (int64 (1), uint64 (1))), "int64")
1887 %!assert (class (horzcat (int64(1), uint32(1))), 'int64') 1874 %!assert (class (horzcat (int64 (1), uint32 (1))), "int64")
1888 %!assert (class (horzcat (int64(1), uint16(1))), 'int64') 1875 %!assert (class (horzcat (int64 (1), uint16 (1))), "int64")
1889 %!assert (class (horzcat (int64(1), uint8(1))), 'int64') 1876 %!assert (class (horzcat (int64 (1), uint8 (1))), "int64")
1890 %!assert (class (horzcat (int64(1), single(1))), 'int64') 1877 %!assert (class (horzcat (int64 (1), single (1))), "int64")
1891 %!assert (class (horzcat (int64(1), double(1))), 'int64') 1878 %!assert (class (horzcat (int64 (1), double (1))), "int64")
1892 %!assert (class (horzcat (int64(1), cell(1))), 'cell') 1879 %!assert (class (horzcat (int64 (1), cell (1))), "cell")
1893 %!assert (class (horzcat (int64(1), true)), 'int64') 1880 %!assert (class (horzcat (int64 (1), true)), "int64")
1894 %!assert (class (horzcat (int64(1), 'a')), 'char') 1881 %!assert (class (horzcat (int64 (1), "a")), "char")
1895 1882
1896 %!assert (class (horzcat (int32(1), int64(1))), 'int32') 1883 %!assert (class (horzcat (int32 (1), int64 (1))), "int32")
1897 %!assert (class (horzcat (int32(1), int32(1))), 'int32') 1884 %!assert (class (horzcat (int32 (1), int32 (1))), "int32")
1898 %!assert (class (horzcat (int32(1), int16(1))), 'int32') 1885 %!assert (class (horzcat (int32 (1), int16 (1))), "int32")
1899 %!assert (class (horzcat (int32(1), int8(1))), 'int32') 1886 %!assert (class (horzcat (int32 (1), int8 (1))), "int32")
1900 %!assert (class (horzcat (int32(1), uint64(1))), 'int32') 1887 %!assert (class (horzcat (int32 (1), uint64 (1))), "int32")
1901 %!assert (class (horzcat (int32(1), uint32(1))), 'int32') 1888 %!assert (class (horzcat (int32 (1), uint32 (1))), "int32")
1902 %!assert (class (horzcat (int32(1), uint16(1))), 'int32') 1889 %!assert (class (horzcat (int32 (1), uint16 (1))), "int32")
1903 %!assert (class (horzcat (int32(1), uint8(1))), 'int32') 1890 %!assert (class (horzcat (int32 (1), uint8 (1))), "int32")
1904 %!assert (class (horzcat (int32(1), single(1))), 'int32') 1891 %!assert (class (horzcat (int32 (1), single (1))), "int32")
1905 %!assert (class (horzcat (int32(1), double(1))), 'int32') 1892 %!assert (class (horzcat (int32 (1), double (1))), "int32")
1906 %!assert (class (horzcat (int32(1), cell(1))), 'cell') 1893 %!assert (class (horzcat (int32 (1), cell (1))), "cell")
1907 %!assert (class (horzcat (int32(1), true)), 'int32') 1894 %!assert (class (horzcat (int32 (1), true)), "int32")
1908 %!assert (class (horzcat (int32(1), 'a')), 'char') 1895 %!assert (class (horzcat (int32 (1), "a")), "char")
1909 1896
1910 %!assert (class (horzcat (int16(1), int64(1))), 'int16') 1897 %!assert (class (horzcat (int16 (1), int64 (1))), "int16")
1911 %!assert (class (horzcat (int16(1), int32(1))), 'int16') 1898 %!assert (class (horzcat (int16 (1), int32 (1))), "int16")
1912 %!assert (class (horzcat (int16(1), int16(1))), 'int16') 1899 %!assert (class (horzcat (int16 (1), int16 (1))), "int16")
1913 %!assert (class (horzcat (int16(1), int8(1))), 'int16') 1900 %!assert (class (horzcat (int16 (1), int8 (1))), "int16")
1914 %!assert (class (horzcat (int16(1), uint64(1))), 'int16') 1901 %!assert (class (horzcat (int16 (1), uint64 (1))), "int16")
1915 %!assert (class (horzcat (int16(1), uint32(1))), 'int16') 1902 %!assert (class (horzcat (int16 (1), uint32 (1))), "int16")
1916 %!assert (class (horzcat (int16(1), uint16(1))), 'int16') 1903 %!assert (class (horzcat (int16 (1), uint16 (1))), "int16")
1917 %!assert (class (horzcat (int16(1), uint8(1))), 'int16') 1904 %!assert (class (horzcat (int16 (1), uint8 (1))), "int16")
1918 %!assert (class (horzcat (int16(1), single(1))), 'int16') 1905 %!assert (class (horzcat (int16 (1), single (1))), "int16")
1919 %!assert (class (horzcat (int16(1), double(1))), 'int16') 1906 %!assert (class (horzcat (int16 (1), double (1))), "int16")
1920 %!assert (class (horzcat (int16(1), cell(1))), 'cell') 1907 %!assert (class (horzcat (int16 (1), cell (1))), "cell")
1921 %!assert (class (horzcat (int16(1), true)), 'int16') 1908 %!assert (class (horzcat (int16 (1), true)), "int16")
1922 %!assert (class (horzcat (int16(1), 'a')), 'char') 1909 %!assert (class (horzcat (int16 (1), "a")), "char")
1923 1910
1924 %!assert (class (horzcat (int8(1), int64(1))), 'int8') 1911 %!assert (class (horzcat (int8 (1), int64 (1))), "int8")
1925 %!assert (class (horzcat (int8(1), int32(1))), 'int8') 1912 %!assert (class (horzcat (int8 (1), int32 (1))), "int8")
1926 %!assert (class (horzcat (int8(1), int16(1))), 'int8') 1913 %!assert (class (horzcat (int8 (1), int16 (1))), "int8")
1927 %!assert (class (horzcat (int8(1), int8(1))), 'int8') 1914 %!assert (class (horzcat (int8 (1), int8 (1))), "int8")
1928 %!assert (class (horzcat (int8(1), uint64(1))), 'int8') 1915 %!assert (class (horzcat (int8 (1), uint64 (1))), "int8")
1929 %!assert (class (horzcat (int8(1), uint32(1))), 'int8') 1916 %!assert (class (horzcat (int8 (1), uint32 (1))), "int8")
1930 %!assert (class (horzcat (int8(1), uint16(1))), 'int8') 1917 %!assert (class (horzcat (int8 (1), uint16 (1))), "int8")
1931 %!assert (class (horzcat (int8(1), uint8(1))), 'int8') 1918 %!assert (class (horzcat (int8 (1), uint8 (1))), "int8")
1932 %!assert (class (horzcat (int8(1), single(1))), 'int8') 1919 %!assert (class (horzcat (int8 (1), single (1))), "int8")
1933 %!assert (class (horzcat (int8(1), double(1))), 'int8') 1920 %!assert (class (horzcat (int8 (1), double (1))), "int8")
1934 %!assert (class (horzcat (int8(1), cell(1))), 'cell') 1921 %!assert (class (horzcat (int8 (1), cell (1))), "cell")
1935 %!assert (class (horzcat (int8(1), true)), 'int8') 1922 %!assert (class (horzcat (int8 (1), true)), "int8")
1936 %!assert (class (horzcat (int8(1), 'a')), 'char') 1923 %!assert (class (horzcat (int8 (1), "a")), "char")
1937 1924
1938 %!assert (class (horzcat (uint64(1), int64(1))), 'uint64') 1925 %!assert (class (horzcat (uint64 (1), int64 (1))), "uint64")
1939 %!assert (class (horzcat (uint64(1), int32(1))), 'uint64') 1926 %!assert (class (horzcat (uint64 (1), int32 (1))), "uint64")
1940 %!assert (class (horzcat (uint64(1), int16(1))), 'uint64') 1927 %!assert (class (horzcat (uint64 (1), int16 (1))), "uint64")
1941 %!assert (class (horzcat (uint64(1), int8(1))), 'uint64') 1928 %!assert (class (horzcat (uint64 (1), int8 (1))), "uint64")
1942 %!assert (class (horzcat (uint64(1), uint64(1))), 'uint64') 1929 %!assert (class (horzcat (uint64 (1), uint64 (1))), "uint64")
1943 %!assert (class (horzcat (uint64(1), uint32(1))), 'uint64') 1930 %!assert (class (horzcat (uint64 (1), uint32 (1))), "uint64")
1944 %!assert (class (horzcat (uint64(1), uint16(1))), 'uint64') 1931 %!assert (class (horzcat (uint64 (1), uint16 (1))), "uint64")
1945 %!assert (class (horzcat (uint64(1), uint8(1))), 'uint64') 1932 %!assert (class (horzcat (uint64 (1), uint8 (1))), "uint64")
1946 %!assert (class (horzcat (uint64(1), single(1))), 'uint64') 1933 %!assert (class (horzcat (uint64 (1), single (1))), "uint64")
1947 %!assert (class (horzcat (uint64(1), double(1))), 'uint64') 1934 %!assert (class (horzcat (uint64 (1), double (1))), "uint64")
1948 %!assert (class (horzcat (uint64(1), cell(1))), 'cell') 1935 %!assert (class (horzcat (uint64 (1), cell (1))), "cell")
1949 %!assert (class (horzcat (uint64(1), true)), 'uint64') 1936 %!assert (class (horzcat (uint64 (1), true)), "uint64")
1950 %!assert (class (horzcat (uint64(1), 'a')), 'char') 1937 %!assert (class (horzcat (uint64 (1), "a")), "char")
1951 1938
1952 %!assert (class (horzcat (uint32(1), int64(1))), 'uint32') 1939 %!assert (class (horzcat (uint32 (1), int64 (1))), "uint32")
1953 %!assert (class (horzcat (uint32(1), int32(1))), 'uint32') 1940 %!assert (class (horzcat (uint32 (1), int32 (1))), "uint32")
1954 %!assert (class (horzcat (uint32(1), int16(1))), 'uint32') 1941 %!assert (class (horzcat (uint32 (1), int16 (1))), "uint32")
1955 %!assert (class (horzcat (uint32(1), int8(1))), 'uint32') 1942 %!assert (class (horzcat (uint32 (1), int8 (1))), "uint32")
1956 %!assert (class (horzcat (uint32(1), uint64(1))), 'uint32') 1943 %!assert (class (horzcat (uint32 (1), uint64 (1))), "uint32")
1957 %!assert (class (horzcat (uint32(1), uint32(1))), 'uint32') 1944 %!assert (class (horzcat (uint32 (1), uint32 (1))), "uint32")
1958 %!assert (class (horzcat (uint32(1), uint16(1))), 'uint32') 1945 %!assert (class (horzcat (uint32 (1), uint16 (1))), "uint32")
1959 %!assert (class (horzcat (uint32(1), uint8(1))), 'uint32') 1946 %!assert (class (horzcat (uint32 (1), uint8 (1))), "uint32")
1960 %!assert (class (horzcat (uint32(1), single(1))), 'uint32') 1947 %!assert (class (horzcat (uint32 (1), single (1))), "uint32")
1961 %!assert (class (horzcat (uint32(1), double(1))), 'uint32') 1948 %!assert (class (horzcat (uint32 (1), double (1))), "uint32")
1962 %!assert (class (horzcat (uint32(1), cell(1))), 'cell') 1949 %!assert (class (horzcat (uint32 (1), cell (1))), "cell")
1963 %!assert (class (horzcat (uint32(1), true)), 'uint32') 1950 %!assert (class (horzcat (uint32 (1), true)), "uint32")
1964 %!assert (class (horzcat (uint32(1), 'a')), 'char') 1951 %!assert (class (horzcat (uint32 (1), "a")), "char")
1965 1952
1966 %!assert (class (horzcat (uint16(1), int64(1))), 'uint16') 1953 %!assert (class (horzcat (uint16 (1), int64 (1))), "uint16")
1967 %!assert (class (horzcat (uint16(1), int32(1))), 'uint16') 1954 %!assert (class (horzcat (uint16 (1), int32 (1))), "uint16")
1968 %!assert (class (horzcat (uint16(1), int16(1))), 'uint16') 1955 %!assert (class (horzcat (uint16 (1), int16 (1))), "uint16")
1969 %!assert (class (horzcat (uint16(1), int8(1))), 'uint16') 1956 %!assert (class (horzcat (uint16 (1), int8 (1))), "uint16")
1970 %!assert (class (horzcat (uint16(1), uint64(1))), 'uint16') 1957 %!assert (class (horzcat (uint16 (1), uint64 (1))), "uint16")
1971 %!assert (class (horzcat (uint16(1), uint32(1))), 'uint16') 1958 %!assert (class (horzcat (uint16 (1), uint32 (1))), "uint16")
1972 %!assert (class (horzcat (uint16(1), uint16(1))), 'uint16') 1959 %!assert (class (horzcat (uint16 (1), uint16 (1))), "uint16")
1973 %!assert (class (horzcat (uint16(1), uint8(1))), 'uint16') 1960 %!assert (class (horzcat (uint16 (1), uint8 (1))), "uint16")
1974 %!assert (class (horzcat (uint16(1), single(1))), 'uint16') 1961 %!assert (class (horzcat (uint16 (1), single (1))), "uint16")
1975 %!assert (class (horzcat (uint16(1), double(1))), 'uint16') 1962 %!assert (class (horzcat (uint16 (1), double (1))), "uint16")
1976 %!assert (class (horzcat (uint16(1), cell(1))), 'cell') 1963 %!assert (class (horzcat (uint16 (1), cell (1))), "cell")
1977 %!assert (class (horzcat (uint16(1), true)), 'uint16') 1964 %!assert (class (horzcat (uint16 (1), true)), "uint16")
1978 %!assert (class (horzcat (uint16(1), 'a')), 'char') 1965 %!assert (class (horzcat (uint16 (1), "a")), "char")
1979 1966
1980 %!assert (class (horzcat (uint8(1), int64(1))), 'uint8') 1967 %!assert (class (horzcat (uint8 (1), int64 (1))), "uint8")
1981 %!assert (class (horzcat (uint8(1), int32(1))), 'uint8') 1968 %!assert (class (horzcat (uint8 (1), int32 (1))), "uint8")
1982 %!assert (class (horzcat (uint8(1), int16(1))), 'uint8') 1969 %!assert (class (horzcat (uint8 (1), int16 (1))), "uint8")
1983 %!assert (class (horzcat (uint8(1), int8(1))), 'uint8') 1970 %!assert (class (horzcat (uint8 (1), int8 (1))), "uint8")
1984 %!assert (class (horzcat (uint8(1), uint64(1))), 'uint8') 1971 %!assert (class (horzcat (uint8 (1), uint64 (1))), "uint8")
1985 %!assert (class (horzcat (uint8(1), uint32(1))), 'uint8') 1972 %!assert (class (horzcat (uint8 (1), uint32 (1))), "uint8")
1986 %!assert (class (horzcat (uint8(1), uint16(1))), 'uint8') 1973 %!assert (class (horzcat (uint8 (1), uint16 (1))), "uint8")
1987 %!assert (class (horzcat (uint8(1), uint8(1))), 'uint8') 1974 %!assert (class (horzcat (uint8 (1), uint8 (1))), "uint8")
1988 %!assert (class (horzcat (uint8(1), single(1))), 'uint8') 1975 %!assert (class (horzcat (uint8 (1), single (1))), "uint8")
1989 %!assert (class (horzcat (uint8(1), double(1))), 'uint8') 1976 %!assert (class (horzcat (uint8 (1), double (1))), "uint8")
1990 %!assert (class (horzcat (uint8(1), cell(1))), 'cell') 1977 %!assert (class (horzcat (uint8 (1), cell (1))), "cell")
1991 %!assert (class (horzcat (uint8(1), true)), 'uint8') 1978 %!assert (class (horzcat (uint8 (1), true)), "uint8")
1992 %!assert (class (horzcat (uint8(1), 'a')), 'char') 1979 %!assert (class (horzcat (uint8 (1), "a")), "char")
1993 1980
1994 %!assert (class (horzcat (single(1), int64(1))), 'int64') 1981 %!assert (class (horzcat (single (1), int64 (1))), "int64")
1995 %!assert (class (horzcat (single(1), int32(1))), 'int32') 1982 %!assert (class (horzcat (single (1), int32 (1))), "int32")
1996 %!assert (class (horzcat (single(1), int16(1))), 'int16') 1983 %!assert (class (horzcat (single (1), int16 (1))), "int16")
1997 %!assert (class (horzcat (single(1), int8(1))), 'int8') 1984 %!assert (class (horzcat (single (1), int8 (1))), "int8")
1998 %!assert (class (horzcat (single(1), uint64(1))), 'uint64') 1985 %!assert (class (horzcat (single (1), uint64 (1))), "uint64")
1999 %!assert (class (horzcat (single(1), uint32(1))), 'uint32') 1986 %!assert (class (horzcat (single (1), uint32 (1))), "uint32")
2000 %!assert (class (horzcat (single(1), uint16(1))), 'uint16') 1987 %!assert (class (horzcat (single (1), uint16 (1))), "uint16")
2001 %!assert (class (horzcat (single(1), uint8(1))), 'uint8') 1988 %!assert (class (horzcat (single (1), uint8 (1))), "uint8")
2002 %!assert (class (horzcat (single(1), single(1))), 'single') 1989 %!assert (class (horzcat (single (1), single (1))), "single")
2003 %!assert (class (horzcat (single(1), double(1))), 'single') 1990 %!assert (class (horzcat (single (1), double (1))), "single")
2004 %!assert (class (horzcat (single(1), cell(1))), 'cell') 1991 %!assert (class (horzcat (single (1), cell (1))), "cell")
2005 %!assert (class (horzcat (single(1), true)), 'single') 1992 %!assert (class (horzcat (single (1), true)), "single")
2006 %!assert (class (horzcat (single(1), 'a')), 'char') 1993 %!assert (class (horzcat (single (1), "a")), "char")
2007 1994
2008 %!assert (class (horzcat (double(1), int64(1))), 'int64') 1995 %!assert (class (horzcat (double (1), int64 (1))), "int64")
2009 %!assert (class (horzcat (double(1), int32(1))), 'int32') 1996 %!assert (class (horzcat (double (1), int32 (1))), "int32")
2010 %!assert (class (horzcat (double(1), int16(1))), 'int16') 1997 %!assert (class (horzcat (double (1), int16 (1))), "int16")
2011 %!assert (class (horzcat (double(1), int8(1))), 'int8') 1998 %!assert (class (horzcat (double (1), int8 (1))), "int8")
2012 %!assert (class (horzcat (double(1), uint64(1))), 'uint64') 1999 %!assert (class (horzcat (double (1), uint64 (1))), "uint64")
2013 %!assert (class (horzcat (double(1), uint32(1))), 'uint32') 2000 %!assert (class (horzcat (double (1), uint32 (1))), "uint32")
2014 %!assert (class (horzcat (double(1), uint16(1))), 'uint16') 2001 %!assert (class (horzcat (double (1), uint16 (1))), "uint16")
2015 %!assert (class (horzcat (double(1), uint8(1))), 'uint8') 2002 %!assert (class (horzcat (double (1), uint8 (1))), "uint8")
2016 %!assert (class (horzcat (double(1), single(1))), 'single') 2003 %!assert (class (horzcat (double (1), single (1))), "single")
2017 %!assert (class (horzcat (double(1), double(1))), 'double') 2004 %!assert (class (horzcat (double (1), double (1))), "double")
2018 %!assert (class (horzcat (double(1), cell(1))), 'cell') 2005 %!assert (class (horzcat (double (1), cell (1))), "cell")
2019 %!assert (class (horzcat (double(1), true)), 'double') 2006 %!assert (class (horzcat (double (1), true)), "double")
2020 %!assert (class (horzcat (double(1), 'a')), 'char') 2007 %!assert (class (horzcat (double (1), "a")), "char")
2021 2008
2022 %!assert (class (horzcat (cell(1), int64(1))), 'cell') 2009 %!assert (class (horzcat (cell (1), int64 (1))), "cell")
2023 %!assert (class (horzcat (cell(1), int32(1))), 'cell') 2010 %!assert (class (horzcat (cell (1), int32 (1))), "cell")
2024 %!assert (class (horzcat (cell(1), int16(1))), 'cell') 2011 %!assert (class (horzcat (cell (1), int16 (1))), "cell")
2025 %!assert (class (horzcat (cell(1), int8(1))), 'cell') 2012 %!assert (class (horzcat (cell (1), int8 (1))), "cell")
2026 %!assert (class (horzcat (cell(1), uint64(1))), 'cell') 2013 %!assert (class (horzcat (cell (1), uint64 (1))), "cell")
2027 %!assert (class (horzcat (cell(1), uint32(1))), 'cell') 2014 %!assert (class (horzcat (cell (1), uint32 (1))), "cell")
2028 %!assert (class (horzcat (cell(1), uint16(1))), 'cell') 2015 %!assert (class (horzcat (cell (1), uint16 (1))), "cell")
2029 %!assert (class (horzcat (cell(1), uint8(1))), 'cell') 2016 %!assert (class (horzcat (cell (1), uint8 (1))), "cell")
2030 %!assert (class (horzcat (cell(1), single(1))), 'cell') 2017 %!assert (class (horzcat (cell (1), single (1))), "cell")
2031 %!assert (class (horzcat (cell(1), double(1))), 'cell') 2018 %!assert (class (horzcat (cell (1), double (1))), "cell")
2032 %!assert (class (horzcat (cell(1), cell(1))), 'cell') 2019 %!assert (class (horzcat (cell (1), cell (1))), "cell")
2033 %!assert (class (horzcat (cell(1), true)), 'cell') 2020 %!assert (class (horzcat (cell (1), true)), "cell")
2034 %!assert (class (horzcat (cell(1), 'a')), 'cell') 2021 %!assert (class (horzcat (cell (1), "a")), "cell")
2035 2022
2036 %!assert (class (horzcat (true, int64(1))), 'int64') 2023 %!assert (class (horzcat (true, int64 (1))), "int64")
2037 %!assert (class (horzcat (true, int32(1))), 'int32') 2024 %!assert (class (horzcat (true, int32 (1))), "int32")
2038 %!assert (class (horzcat (true, int16(1))), 'int16') 2025 %!assert (class (horzcat (true, int16 (1))), "int16")
2039 %!assert (class (horzcat (true, int8(1))), 'int8') 2026 %!assert (class (horzcat (true, int8 (1))), "int8")
2040 %!assert (class (horzcat (true, uint64(1))), 'uint64') 2027 %!assert (class (horzcat (true, uint64 (1))), "uint64")
2041 %!assert (class (horzcat (true, uint32(1))), 'uint32') 2028 %!assert (class (horzcat (true, uint32 (1))), "uint32")
2042 %!assert (class (horzcat (true, uint16(1))), 'uint16') 2029 %!assert (class (horzcat (true, uint16 (1))), "uint16")
2043 %!assert (class (horzcat (true, uint8(1))), 'uint8') 2030 %!assert (class (horzcat (true, uint8 (1))), "uint8")
2044 %!assert (class (horzcat (true, single(1))), 'single') 2031 %!assert (class (horzcat (true, single (1))), "single")
2045 %!assert (class (horzcat (true, double(1))), 'double') 2032 %!assert (class (horzcat (true, double (1))), "double")
2046 %!assert (class (horzcat (true, cell(1))), 'cell') 2033 %!assert (class (horzcat (true, cell (1))), "cell")
2047 %!assert (class (horzcat (true, true)), 'logical') 2034 %!assert (class (horzcat (true, true)), "logical")
2048 %!assert (class (horzcat (true, 'a')), 'char') 2035 %!assert (class (horzcat (true, "a")), "char")
2049 2036
2050 %!assert (class (horzcat ('a', int64(1))), 'char') 2037 %!assert (class (horzcat ("a", int64 (1))), "char")
2051 %!assert (class (horzcat ('a', int32(1))), 'char') 2038 %!assert (class (horzcat ("a", int32 (1))), "char")
2052 %!assert (class (horzcat ('a', int16(1))), 'char') 2039 %!assert (class (horzcat ("a", int16 (1))), "char")
2053 %!assert (class (horzcat ('a', int8(1))), 'char') 2040 %!assert (class (horzcat ("a", int8 (1))), "char")
2054 %!assert (class (horzcat ('a', int64(1))), 'char') 2041 %!assert (class (horzcat ("a", int64 (1))), "char")
2055 %!assert (class (horzcat ('a', int32(1))), 'char') 2042 %!assert (class (horzcat ("a", int32 (1))), "char")
2056 %!assert (class (horzcat ('a', int16(1))), 'char') 2043 %!assert (class (horzcat ("a", int16 (1))), "char")
2057 %!assert (class (horzcat ('a', int8(1))), 'char') 2044 %!assert (class (horzcat ("a", int8 (1))), "char")
2058 %!assert (class (horzcat ('a', single(1))), 'char') 2045 %!assert (class (horzcat ("a", single (1))), "char")
2059 %!assert (class (horzcat ('a', double(1))), 'char') 2046 %!assert (class (horzcat ("a", double (1))), "char")
2060 %!assert (class (horzcat ('a', cell(1))), 'cell') 2047 %!assert (class (horzcat ("a", cell (1))), "cell")
2061 %!assert (class (horzcat ('a', true)), 'char') 2048 %!assert (class (horzcat ("a", true)), "char")
2062 %!assert (class (horzcat ('a', 'a')), 'char') 2049 %!assert (class (horzcat ("a", "a")), "char")
2063 2050
2064 %!assert (class (horzcat (cell(1), struct('foo', 'bar'))), 'cell') 2051 %!assert (class (horzcat (cell (1), struct ("foo", "bar"))), "cell")
2065 %!error horzcat (struct('foo', 'bar'), cell(1)); 2052
2053 %!error horzcat (struct ("foo", "bar"), cell (1))
2066 */ 2054 */
2067 2055
2068 DEFUN (vertcat, args, , 2056 DEFUN (vertcat, args, ,
2069 "-*- texinfo -*-\n\ 2057 "-*- texinfo -*-\n\
2070 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ 2058 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
2083 return do_cat (args, -1, "vertcat"); 2071 return do_cat (args, -1, "vertcat");
2084 } 2072 }
2085 2073
2086 /* 2074 /*
2087 %!test 2075 %!test
2088 %! c = {'foo'; 'bar'; 'bazoloa'}; 2076 %! c = {"foo"; "bar"; "bazoloa"};
2089 %! assert (vertcat (c, 'a', 'bc', 'def'), {'foo'; 'bar'; 'bazoloa'; 'a'; 'bc'; 'def'}); 2077 %! assert (vertcat (c, "a", "bc", "def"), {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
2090 */ 2078 */
2091 2079
2092 DEFUN (cat, args, , 2080 DEFUN (cat, args, ,
2093 "-*- texinfo -*-\n\ 2081 "-*- texinfo -*-\n\
2094 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ 2082 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
2156 2144
2157 return retval; 2145 return retval;
2158 } 2146 }
2159 2147
2160 /* 2148 /*
2161
2162 %!function ret = __testcat (t1, t2, tr, cmplx) 2149 %!function ret = __testcat (t1, t2, tr, cmplx)
2163 %! assert (cat (1, cast ([], t1), cast([], t2)), cast ([], tr)); 2150 %! assert (cat (1, cast ([], t1), cast([], t2)), cast ([], tr));
2164 %! 2151 %!
2165 %! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr)); 2152 %! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr));
2166 %! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr)); 2153 %! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr));
2167 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr)); 2154 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr));
2168 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr)); 2155 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr));
2169 %! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr)); 2156 %! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr));
2170 %! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr)); 2157 %! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr));
2171 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr)); 2158 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr));
2172 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr)); 2159 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr));
2173 %! 2160 %!
2174 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr)); 2161 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr));
2175 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr)); 2162 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr));
2176 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr)); 2163 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr));
2177 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr)); 2164 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr));
2178 %! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr)); 2165 %! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr));
2179 %! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr)); 2166 %! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr));
2180 %! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr)); 2167 %! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr));
2181 %! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr)); 2168 %! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr));
2182 %! 2169 %!
2183 %! if (nargin == 3 || cmplx) 2170 %! if (nargin == 3 || cmplx)
2184 %! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr)); 2171 %! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr));
2185 %! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr)); 2172 %! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr));
2186 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr)); 2173 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr));
2187 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr)); 2174 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr));
2188 %! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr)); 2175 %! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr));
2189 %! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr)); 2176 %! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr));
2190 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr)); 2177 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr));
2191 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr)); 2178 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr));
2192 %! 2179 %!
2193 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr)); 2180 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr));
2194 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr)); 2181 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr));
2195 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr)); 2182 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr));
2196 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr)); 2183 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr));
2197 %! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr)); 2184 %! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr));
2198 %! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr)); 2185 %! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr));
2199 %! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr)); 2186 %! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr));
2200 %! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr)); 2187 %! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr));
2201 %! 2188 %!
2202 %! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr)); 2189 %! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr));
2203 %! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr)); 2190 %! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr));
2204 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr)); 2191 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr));
2205 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr)); 2192 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr));
2206 %! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr)); 2193 %! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr));
2207 %! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr)); 2194 %! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr));
2208 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr)); 2195 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr));
2209 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr)); 2196 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr));
2210 %! 2197 %!
2211 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr)); 2198 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr));
2212 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr)); 2199 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr));
2213 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr)); 2200 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr));
2214 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr)); 2201 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr));
2215 %! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr)); 2202 %! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr));
2216 %! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr)); 2203 %! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr));
2217 %! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr)); 2204 %! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr));
2218 %! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr)); 2205 %! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr));
2219 %! 2206 %!
2220 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr)); 2207 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr));
2221 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr)); 2208 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr));
2222 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr)); 2209 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr));
2223 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr)); 2210 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr));
2224 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr)); 2211 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr));
2225 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr)); 2212 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr));
2226 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr)); 2213 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr));
2227 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr)); 2214 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr));
2228 %! 2215 %!
2229 %! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr)); 2216 %! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr));
2230 %! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr)); 2217 %! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr));
2231 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr)); 2218 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr));
2232 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr)); 2219 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr));
2233 %! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr)); 2220 %! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr));
2234 %! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr)); 2221 %! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr));
2235 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr)); 2222 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr));
2236 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr)); 2223 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr));
2237 %! endif 2224 %! endif
2238 %! ret = true; 2225 %! ret = true;
2239 %!endfunction 2226 %!endfunction
2240 2227
2241 %!assert (__testcat('double', 'double', 'double')) 2228 %!assert (__testcat ("double", "double", "double"))
2242 %!assert (__testcat('single', 'double', 'single')) 2229 %!assert (__testcat ("single", "double", "single"))
2243 %!assert (__testcat('double', 'single', 'single')) 2230 %!assert (__testcat ("double", "single", "single"))
2244 %!assert (__testcat('single', 'single', 'single')) 2231 %!assert (__testcat ("single", "single", "single"))
2245 2232
2246 %!assert (__testcat('double', 'int8', 'int8', false)) 2233 %!assert (__testcat ("double", "int8", "int8", false))
2247 %!assert (__testcat('int8', 'double', 'int8', false)) 2234 %!assert (__testcat ("int8", "double", "int8", false))
2248 %!assert (__testcat('single', 'int8', 'int8', false)) 2235 %!assert (__testcat ("single", "int8", "int8", false))
2249 %!assert (__testcat('int8', 'single', 'int8', false)) 2236 %!assert (__testcat ("int8", "single", "int8", false))
2250 %!assert (__testcat('int8', 'int8', 'int8', false)) 2237 %!assert (__testcat ("int8", "int8", "int8", false))
2251 %!assert (__testcat('double', 'int16', 'int16', false)) 2238 %!assert (__testcat ("double", "int16", "int16", false))
2252 %!assert (__testcat('int16', 'double', 'int16', false)) 2239 %!assert (__testcat ("int16", "double", "int16", false))
2253 %!assert (__testcat('single', 'int16', 'int16', false)) 2240 %!assert (__testcat ("single", "int16", "int16", false))
2254 %!assert (__testcat('int16', 'single', 'int16', false)) 2241 %!assert (__testcat ("int16", "single", "int16", false))
2255 %!assert (__testcat('int16', 'int16', 'int16', false)) 2242 %!assert (__testcat ("int16", "int16", "int16", false))
2256 %!assert (__testcat('double', 'int32', 'int32', false)) 2243 %!assert (__testcat ("double", "int32", "int32", false))
2257 %!assert (__testcat('int32', 'double', 'int32', false)) 2244 %!assert (__testcat ("int32", "double", "int32", false))
2258 %!assert (__testcat('single', 'int32', 'int32', false)) 2245 %!assert (__testcat ("single", "int32", "int32", false))
2259 %!assert (__testcat('int32', 'single', 'int32', false)) 2246 %!assert (__testcat ("int32", "single", "int32", false))
2260 %!assert (__testcat('int32', 'int32', 'int32', false)) 2247 %!assert (__testcat ("int32", "int32", "int32", false))
2261 %!assert (__testcat('double', 'int64', 'int64', false)) 2248 %!assert (__testcat ("double", "int64", "int64", false))
2262 %!assert (__testcat('int64', 'double', 'int64', false)) 2249 %!assert (__testcat ("int64", "double", "int64", false))
2263 %!assert (__testcat('single', 'int64', 'int64', false)) 2250 %!assert (__testcat ("single", "int64", "int64", false))
2264 %!assert (__testcat('int64', 'single', 'int64', false)) 2251 %!assert (__testcat ("int64", "single", "int64", false))
2265 %!assert (__testcat('int64', 'int64', 'int64', false)) 2252 %!assert (__testcat ("int64", "int64", "int64", false))
2266 2253
2267 %!assert (__testcat('double', 'uint8', 'uint8', false)) 2254 %!assert (__testcat ("double", "uint8", "uint8", false))
2268 %!assert (__testcat('uint8', 'double', 'uint8', false)) 2255 %!assert (__testcat ("uint8", "double", "uint8", false))
2269 %!assert (__testcat('single', 'uint8', 'uint8', false)) 2256 %!assert (__testcat ("single", "uint8", "uint8", false))
2270 %!assert (__testcat('uint8', 'single', 'uint8', false)) 2257 %!assert (__testcat ("uint8", "single", "uint8", false))
2271 %!assert (__testcat('uint8', 'uint8', 'uint8', false)) 2258 %!assert (__testcat ("uint8", "uint8", "uint8", false))
2272 %!assert (__testcat('double', 'uint16', 'uint16', false)) 2259 %!assert (__testcat ("double", "uint16", "uint16", false))
2273 %!assert (__testcat('uint16', 'double', 'uint16', false)) 2260 %!assert (__testcat ("uint16", "double", "uint16", false))
2274 %!assert (__testcat('single', 'uint16', 'uint16', false)) 2261 %!assert (__testcat ("single", "uint16", "uint16", false))
2275 %!assert (__testcat('uint16', 'single', 'uint16', false)) 2262 %!assert (__testcat ("uint16", "single", "uint16", false))
2276 %!assert (__testcat('uint16', 'uint16', 'uint16', false)) 2263 %!assert (__testcat ("uint16", "uint16", "uint16", false))
2277 %!assert (__testcat('double', 'uint32', 'uint32', false)) 2264 %!assert (__testcat ("double", "uint32", "uint32", false))
2278 %!assert (__testcat('uint32', 'double', 'uint32', false)) 2265 %!assert (__testcat ("uint32", "double", "uint32", false))
2279 %!assert (__testcat('single', 'uint32', 'uint32', false)) 2266 %!assert (__testcat ("single", "uint32", "uint32", false))
2280 %!assert (__testcat('uint32', 'single', 'uint32', false)) 2267 %!assert (__testcat ("uint32", "single", "uint32", false))
2281 %!assert (__testcat('uint32', 'uint32', 'uint32', false)) 2268 %!assert (__testcat ("uint32", "uint32", "uint32", false))
2282 %!assert (__testcat('double', 'uint64', 'uint64', false)) 2269 %!assert (__testcat ("double", "uint64", "uint64", false))
2283 %!assert (__testcat('uint64', 'double', 'uint64', false)) 2270 %!assert (__testcat ("uint64", "double", "uint64", false))
2284 %!assert (__testcat('single', 'uint64', 'uint64', false)) 2271 %!assert (__testcat ("single", "uint64", "uint64", false))
2285 %!assert (__testcat('uint64', 'single', 'uint64', false)) 2272 %!assert (__testcat ("uint64", "single", "uint64", false))
2286 %!assert (__testcat('uint64', 'uint64', 'uint64', false)) 2273 %!assert (__testcat ("uint64", "uint64", "uint64", false))
2287 2274
2288 %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4]) 2275 %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4])
2289 %!assert (cat (3, [1,2;3,4], []), [1,2;3,4]) 2276 %!assert (cat (3, [1,2;3,4], []), [1,2;3,4])
2290 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4]) 2277 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4])
2291 %!assert (cat (3, [], [], []), zeros (0, 0, 3)) 2278 %!assert (cat (3, [], [], []), zeros (0, 0, 3))
2292 2279
2293 %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2)) 2280 %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2))
2294 %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4]) 2281 %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4])
2295 %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4]) 2282 %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4])
2283
2284 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat ([0;0;0;1],[1,2,2]) )
2285 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat (zeros (3,2,2), ones (1,2,2)) )
2286
2296 %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4]) 2287 %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4])
2297 %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4]) 2288 %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4])
2298
2299 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat([0;0;0;1],[1,2,2]) )
2300 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat(zeros(3,2,2), ones(1,2,2)) )
2301
2302 */ 2289 */
2303 2290
2304 static octave_value 2291 static octave_value
2305 do_permute (const octave_value_list& args, bool inv) 2292 do_permute (const octave_value_list& args, bool inv)
2306 { 2293 {
2801 2788
2802 return retval; 2789 return retval;
2803 } 2790 }
2804 2791
2805 /* 2792 /*
2806 2793 %!assert (sum ([true,true]), 2)
2807 %!assert (sum([true,true]), 2) 2794 %!assert (sum ([true,true],"native"), true)
2808 %!assert (sum([true,true],'native'), true) 2795 %!assert (sum (int8 ([127,10,-20])), 117)
2809 %!assert (sum(int8([127,10,-20])), 117); 2796 %!assert (sum (int8 ([127,10,-20]),'native'), int8 (107))
2810 %!assert (sum(int8([127,10,-20]),'native'), int8(107)); 2797
2811 2798 %!assert (sum ([1, 2, 3]), 6)
2812 %!assert(sum ([1, 2, 3]), 6) 2799 %!assert (sum ([-1; -2; -3]), -6)
2813 %!assert(sum ([-1; -2; -3]), -6); 2800 %!assert (sum ([i, 2+i, -3+2i, 4]), 3+4i)
2814 %!assert(sum ([i, 2+i, -3+2i, 4]), 3+4i); 2801 %!assert (sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i])
2815 %!assert(sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i]); 2802
2816 2803 %!assert (sum (single ([1, 2, 3])), single (6))
2817 %!assert(sum (single([1, 2, 3])), single(6)) 2804 %!assert (sum (single ([-1; -2; -3])), single (-6))
2818 %!assert(sum (single([-1; -2; -3])), single(-6)); 2805 %!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i))
2819 %!assert(sum (single([i, 2+i, -3+2i, 4])), single(3+4i)); 2806 %!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([2+2i, 4+4i, 6+6i]))
2820 %!assert(sum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([2+2i, 4+4i, 6+6i])); 2807
2821 2808 %!assert (sum ([1, 2; 3, 4], 1), [4, 6])
2822 %!error <Invalid call to sum> sum (); 2809 %!assert (sum ([1, 2; 3, 4], 2), [3; 7])
2823 2810 %!assert (sum (zeros (1, 0)), 0)
2824 %!assert (sum ([1, 2; 3, 4], 1), [4, 6]); 2811 %!assert (sum (zeros (1, 0), 1), zeros (1, 0))
2825 %!assert (sum ([1, 2; 3, 4], 2), [3; 7]); 2812 %!assert (sum (zeros (1, 0), 2), 0)
2826 %!assert (sum (zeros (1, 0)), 0); 2813 %!assert (sum (zeros (0, 1)), 0)
2827 %!assert (sum (zeros (1, 0), 1), zeros(1, 0)); 2814 %!assert (sum (zeros (0, 1), 1), 0)
2828 %!assert (sum (zeros (1, 0), 2), 0); 2815 %!assert (sum (zeros (0, 1), 2), zeros (0, 1))
2829 %!assert (sum (zeros (0, 1)), 0); 2816 %!assert (sum (zeros (2, 0)), zeros (1, 0))
2830 %!assert (sum (zeros (0, 1), 1), 0); 2817 %!assert (sum (zeros (2, 0), 1), zeros (1, 0))
2831 %!assert (sum (zeros (0, 1), 2), zeros(0, 1)); 2818 %!assert (sum (zeros (2, 0), 2), [0; 0])
2832 %!assert (sum (zeros (2, 0)), zeros(1, 0)); 2819 %!assert (sum (zeros (0, 2)), [0, 0])
2833 %!assert (sum (zeros (2, 0), 1), zeros(1, 0)); 2820 %!assert (sum (zeros (0, 2), 1), [0, 0])
2834 %!assert (sum (zeros (2, 0), 2), [0; 0]); 2821 %!assert (sum (zeros (0, 2), 2), zeros (0, 1))
2835 %!assert (sum (zeros (0, 2)), [0, 0]); 2822 %!assert (sum (zeros (2, 2, 0, 3)), zeros (1, 2, 0, 3))
2836 %!assert (sum (zeros (0, 2), 1), [0, 0]); 2823 %!assert (sum (zeros (2, 2, 0, 3), 2), zeros (2, 1, 0, 3))
2837 %!assert (sum (zeros (0, 2), 2), zeros(0, 1)); 2824 %!assert (sum (zeros (2, 2, 0, 3), 3), zeros (2, 2, 1, 3))
2838 %!assert (sum (zeros (2, 2, 0, 3)), zeros(1, 2, 0, 3)); 2825 %!assert (sum (zeros (2, 2, 0, 3), 4), zeros (2, 2, 0))
2839 %!assert (sum (zeros (2, 2, 0, 3), 2), zeros(2, 1, 0, 3)); 2826 %!assert (sum (zeros (2, 2, 0, 3), 7), zeros (2, 2, 0, 3))
2840 %!assert (sum (zeros (2, 2, 0, 3), 3), zeros(2, 2, 1, 3)); 2827
2841 %!assert (sum (zeros (2, 2, 0, 3), 4), zeros(2, 2, 0)); 2828 %!assert (sum (single ([1, 2; 3, 4]), 1), single ([4, 6]))
2842 %!assert (sum (zeros (2, 2, 0, 3), 7), zeros(2, 2, 0, 3)); 2829 %!assert (sum (single ([1, 2; 3, 4]), 2), single ([3; 7]))
2843 2830 %!assert (sum (zeros (1, 0, "single")), single (0))
2844 %!assert (sum (single([1, 2; 3, 4]), 1), single([4, 6])); 2831 %!assert (sum (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
2845 %!assert (sum (single([1, 2; 3, 4]), 2), single([3; 7])); 2832 %!assert (sum (zeros (1, 0, "single"), 2), single (0))
2846 %!assert (sum (zeros (1, 0, 'single')), single(0)); 2833 %!assert (sum (zeros (0, 1, "single")), single (0))
2847 %!assert (sum (zeros (1, 0, 'single'), 1), zeros(1, 0, 'single')); 2834 %!assert (sum (zeros (0, 1, "single"), 1), single (0))
2848 %!assert (sum (zeros (1, 0, 'single'), 2), single(0)); 2835 %!assert (sum (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
2849 %!assert (sum (zeros (0, 1, 'single')), single(0)); 2836 %!assert (sum (zeros (2, 0, "single")), zeros (1, 0, "single"))
2850 %!assert (sum (zeros (0, 1, 'single'), 1), single(0)); 2837 %!assert (sum (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
2851 %!assert (sum (zeros (0, 1, 'single'), 2), zeros(0, 1, 'single')); 2838 %!assert (sum (zeros (2, 0, "single"), 2), single ([0; 0]))
2852 %!assert (sum (zeros (2, 0, 'single')), zeros(1, 0, 'single')); 2839 %!assert (sum (zeros (0, 2, "single")), single ([0, 0]))
2853 %!assert (sum (zeros (2, 0, 'single'), 1), zeros(1, 0, 'single')); 2840 %!assert (sum (zeros (0, 2, "single"), 1), single ([0, 0]))
2854 %!assert (sum (zeros (2, 0, 'single'), 2), single([0; 0])); 2841 %!assert (sum (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
2855 %!assert (sum (zeros (0, 2, 'single')), single([0, 0])); 2842 %!assert (sum (zeros (2, 2, 0, 3, "single")), zeros (1, 2, 0, 3, "single"))
2856 %!assert (sum (zeros (0, 2, 'single'), 1), single([0, 0])); 2843 %!assert (sum (zeros (2, 2, 0, 3, "single"), 2), zeros (2, 1, 0, 3, "single"))
2857 %!assert (sum (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); 2844 %!assert (sum (zeros (2, 2, 0, 3, "single"), 3), zeros (2, 2, 1, 3, "single"))
2858 %!assert (sum (zeros (2, 2, 0, 3, 'single')), zeros(1, 2, 0, 3, 'single')); 2845 %!assert (sum (zeros (2, 2, 0, 3, "single"), 4), zeros (2, 2, 0, "single"))
2859 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 2), zeros(2, 1, 0, 3, 'single')); 2846 %!assert (sum (zeros (2, 2, 0, 3, "single"), 7), zeros (2, 2, 0, 3, "single"))
2860 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 3), zeros(2, 2, 1, 3, 'single')); 2847
2861 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 4), zeros(2, 2, 0, 'single')); 2848 %!error sum ()
2862 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 7), zeros(2, 2, 0, 3, 'single'));
2863
2864 */ 2849 */
2865 2850
2866 DEFUN (sumsq, args, , 2851 DEFUN (sumsq, args, ,
2867 "-*- texinfo -*-\n\ 2852 "-*- texinfo -*-\n\
2868 @deftypefn {Built-in Function} {} sumsq (@var{x})\n\ 2853 @deftypefn {Built-in Function} {} sumsq (@var{x})\n\
2883 { 2868 {
2884 DATA_REDUCTION (sumsq); 2869 DATA_REDUCTION (sumsq);
2885 } 2870 }
2886 2871
2887 /* 2872 /*
2888 2873 %!assert (sumsq ([1, 2, 3]), 14)
2889 %!assert(sumsq ([1, 2, 3]), 14) 2874 %!assert (sumsq ([-1; -2; 4i]), 21)
2890 %!assert(sumsq ([-1; -2; 4i]), 21); 2875 %!assert (sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29])
2891 %!assert(sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29]); 2876
2892 2877 %!assert (sumsq (single ([1, 2, 3])), single (14))
2893 %!assert(sumsq (single([1, 2, 3])), single(14)) 2878 %!assert (sumsq (single ([-1; -2; 4i])), single (21))
2894 %!assert(sumsq (single([-1; -2; 4i])), single(21)); 2879 %!assert (sumsq (single ([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single ([21, 49, 29]))
2895 %!assert(sumsq (single([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single([21, 49, 29])); 2880
2896 2881 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20])
2897 %!error <Invalid call to sumsq> sumsq (); 2882 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25])
2898 2883
2899 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20]); 2884 %!assert (sumsq (single ([1, 2; 3, 4]), 1), single ([10, 20]))
2900 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25]); 2885 %!assert (sumsq (single ([1, 2; 3, 4]), 2), single ([5; 25]))
2901 2886
2902 %!assert (sumsq (single([1, 2; 3, 4]), 1), single([10, 20])); 2887 %!error sumsq ()
2903 %!assert (sumsq (single([1, 2; 3, 4]), 2), single([5; 25])); 2888 */
2904
2905 */
2906 2889
2907 DEFUN (islogical, args, , 2890 DEFUN (islogical, args, ,
2908 "-*- texinfo -*-\n\ 2891 "-*- texinfo -*-\n\
2909 @deftypefn {Built-in Function} {} islogical (@var{x})\n\ 2892 @deftypefn {Built-in Function} {} islogical (@var{x})\n\
2910 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\ 2893 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\
2923 } 2906 }
2924 2907
2925 DEFALIAS (isbool, islogical); 2908 DEFALIAS (isbool, islogical);
2926 2909
2927 /* 2910 /*
2928 2911 %!assert (islogical (true), true)
2929 %!assert (islogical(true), true) 2912 %!assert (islogical (false), true)
2930 %!assert (islogical(false), true) 2913 %!assert (islogical ([true, false]), true)
2931 %!assert (islogical([true, false]), true) 2914 %!assert (islogical (1), false)
2932 %!assert (islogical(1), false) 2915 %!assert (islogical (1i), false)
2933 %!assert (islogical(1i), false) 2916 %!assert (islogical ([1,1]), false)
2934 %!assert (islogical([1,1]), false) 2917 %!assert (islogical (single (1)), false)
2935 %!assert (islogical(single(1)), false) 2918 %!assert (islogical (single (1i)), false)
2936 %!assert (islogical(single(1i)), false) 2919 %!assert (islogical (single ([1,1])), false)
2937 %!assert (islogical(single([1,1])), false) 2920 %!assert (islogical (sparse ([true, false])), true)
2938 %!assert (islogical(sparse ([true, false])), true) 2921 %!assert (islogical (sparse ([1, 0])), false)
2939 %!assert (islogical(sparse ([1, 0])), false) 2922 */
2940
2941 */
2942 2923
2943 DEFUN (isinteger, args, , 2924 DEFUN (isinteger, args, ,
2944 "-*- texinfo -*-\n\ 2925 "-*- texinfo -*-\n\
2945 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\ 2926 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\
2946 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\ 2927 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\
3341 3322
3342 return retval; 3323 return retval;
3343 } 3324 }
3344 3325
3345 /* 3326 /*
3346 3327 %!assert (isnumeric (1), true)
3347 %!assert (isnumeric(1), true) 3328 %!assert (isnumeric (1i), true)
3348 %!assert (isnumeric(1i), true) 3329 %!assert (isnumeric ([1,1]), true)
3349 %!assert (isnumeric([1,1]), true) 3330 %!assert (isnumeric (single (1)), true)
3350 %!assert (isnumeric(single(1)), true) 3331 %!assert (isnumeric (single (1i)), true)
3351 %!assert (isnumeric(single(1i)), true) 3332 %!assert (isnumeric (single ([1,1])), true)
3352 %!assert (isnumeric(single([1,1])), true) 3333 %!assert (isnumeric (int8 (1)), true)
3353 %!assert (isnumeric(int8(1)), true) 3334 %!assert (isnumeric (uint8 ([1,1])), true)
3354 %!assert (isnumeric(uint8([1,1])), true) 3335 %!assert (isnumeric ("Hello World"), false)
3355 %!assert (isnumeric("Hello World"), false) 3336 %!assert (isnumeric (true), false)
3356 %!assert (isnumeric(true), false) 3337 %!assert (isnumeric (false), false)
3357 %!assert (isnumeric(false), false) 3338 %!assert (isnumeric ([true, false]), false)
3358 %!assert (isnumeric([true, false]), false) 3339 %!assert (isnumeric (sparse ([true, false])), false)
3359 %!assert (isnumeric(sparse ([true, false])), false)
3360
3361 */ 3340 */
3362 3341
3363 DEFUN (ismatrix, args, , 3342 DEFUN (ismatrix, args, ,
3364 "-*- texinfo -*-\n\ 3343 "-*- texinfo -*-\n\
3365 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ 3344 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\
3383 3362
3384 return retval; 3363 return retval;
3385 } 3364 }
3386 3365
3387 /* 3366 /*
3388 3367 %!assert (ismatrix ([]))
3389 %!assert(ismatrix ([])); 3368 %!assert (ismatrix (1))
3390 %!assert(ismatrix (1)); 3369 %!assert (ismatrix ([1, 2, 3]))
3391 %!assert(ismatrix ([1, 2, 3])); 3370 %!assert (ismatrix ([1, 2; 3, 4]))
3392 %!assert(ismatrix ([1, 2; 3, 4])); 3371 %!assert (ismatrix (zeros (3, 2, 4)))
3393 %!assert(ismatrix (zeros (3, 2, 4))); 3372
3394 3373 %!assert (ismatrix (single ([])))
3395 %!assert(ismatrix (single([]))); 3374 %!assert (ismatrix (single (1)))
3396 %!assert(ismatrix (single(1))); 3375 %!assert (ismatrix (single ([1, 2, 3])))
3397 %!assert(ismatrix (single([1, 2, 3]))); 3376 %!assert (ismatrix (single ([1, 2; 3, 4])))
3398 %!assert(ismatrix (single([1, 2; 3, 4]))); 3377
3399 3378 %!assert (ismatrix ("t"))
3400 %!assert(ismatrix ("t")); 3379 %!assert (ismatrix ("test"))
3401 %!assert(ismatrix ("test")); 3380 %!assert (ismatrix (["test"; "ing"]))
3402 %!assert(ismatrix (["test"; "ing"]));
3403 3381
3404 %!test 3382 %!test
3405 %! s.a = 1; 3383 %! s.a = 1;
3406 %! assert(ismatrix (s), false); 3384 %! assert (ismatrix (s), false);
3407 3385
3408 %!error <Invalid call to ismatrix> ismatrix (); 3386 %!error ismatrix ()
3409 %!error <Invalid call to ismatrix> ismatrix ([1, 2; 3, 4], 2); 3387 %!error ismatrix ([1, 2; 3, 4], 2)
3410 3388 */
3411 */
3412 3389
3413 static octave_value 3390 static octave_value
3414 fill_matrix (const octave_value_list& args, int val, const char *fcn) 3391 fill_matrix (const octave_value_list& args, int val, const char *fcn)
3415 { 3392 {
3416 octave_value retval; 3393 octave_value retval;
3860 { 3837 {
3861 return fill_matrix (args, 1, "ones"); 3838 return fill_matrix (args, 1, "ones");
3862 } 3839 }
3863 3840
3864 /* 3841 /*
3865 3842 %!assert (ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1])
3866 %!assert(ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1]); 3843 %!assert (ones (2, 3), [1, 1, 1; 1, 1, 1])
3867 %!assert(ones (2, 3), [1, 1, 1; 1, 1, 1]); 3844 %!assert (ones (3, 2), [1, 1; 1, 1; 1, 1])
3868 %!assert(ones (3, 2), [1, 1; 1, 1; 1, 1]); 3845 %!assert (size (ones (3, 4, 5)), [3, 4, 5])
3869 %!assert(size (ones (3, 4, 5)), [3, 4, 5]); 3846
3870 3847 %!assert (ones (3, "single"), single ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
3871 %!assert(ones (3,'single'), single([1, 1, 1; 1, 1, 1; 1, 1, 1])); 3848 %!assert (ones (2, 3, "single"), single ([1, 1, 1; 1, 1, 1]))
3872 %!assert(ones (2, 3,'single'), single([1, 1, 1; 1, 1, 1])); 3849 %!assert (ones (3, 2, "single"), single ([1, 1; 1, 1; 1, 1]))
3873 %!assert(ones (3, 2,'single'), single([1, 1; 1, 1; 1, 1])); 3850 %!assert (size (ones (3, 4, 5, "single")), [3, 4, 5])
3874 %!assert(size (ones (3, 4, 5, 'single')), [3, 4, 5]); 3851
3875 3852 %!assert (ones (3, "int8"), int8 ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
3876 %!assert(ones (3,'int8'), int8([1, 1, 1; 1, 1, 1; 1, 1, 1])); 3853 %!assert (ones (2, 3, "int8"), int8 ([1, 1, 1; 1, 1, 1]))
3877 %!assert(ones (2, 3,'int8'), int8([1, 1, 1; 1, 1, 1])); 3854 %!assert (ones (3, 2, "int8"), int8 ([1, 1; 1, 1; 1, 1]))
3878 %!assert(ones (3, 2,'int8'), int8([1, 1; 1, 1; 1, 1])); 3855 %!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5])
3879 %!assert(size (ones (3, 4, 5, 'int8')), [3, 4, 5]); 3856 */
3880
3881 */
3882 3857
3883 DEFUN (zeros, args, , 3858 DEFUN (zeros, args, ,
3884 "-*- texinfo -*-\n\ 3859 "-*- texinfo -*-\n\
3885 @deftypefn {Built-in Function} {} zeros (@var{n})\n\ 3860 @deftypefn {Built-in Function} {} zeros (@var{n})\n\
3886 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n})\n\ 3861 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n})\n\
3904 { 3879 {
3905 return fill_matrix (args, 0, "zeros"); 3880 return fill_matrix (args, 0, "zeros");
3906 } 3881 }
3907 3882
3908 /* 3883 /*
3909 3884 %!assert (zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0])
3910 %!assert(zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0]); 3885 %!assert (zeros (2, 3), [0, 0, 0; 0, 0, 0])
3911 %!assert(zeros (2, 3), [0, 0, 0; 0, 0, 0]); 3886 %!assert (zeros (3, 2), [0, 0; 0, 0; 0, 0])
3912 %!assert(zeros (3, 2), [0, 0; 0, 0; 0, 0]); 3887 %!assert (size (zeros (3, 4, 5)), [3, 4, 5])
3913 %!assert(size (zeros (3, 4, 5)), [3, 4, 5]); 3888
3914 3889 %!assert (zeros (3, "single"), single ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
3915 %!assert(zeros (3,'single'), single([0, 0, 0; 0, 0, 0; 0, 0, 0])); 3890 %!assert (zeros (2, 3, "single"), single ([0, 0, 0; 0, 0, 0]))
3916 %!assert(zeros (2, 3,'single'), single([0, 0, 0; 0, 0, 0])); 3891 %!assert (zeros (3, 2, "single"), single ([0, 0; 0, 0; 0, 0]))
3917 %!assert(zeros (3, 2,'single'), single([0, 0; 0, 0; 0, 0])); 3892 %!assert (size (zeros (3, 4, 5, "single")), [3, 4, 5])
3918 %!assert(size (zeros (3, 4, 5, 'single')), [3, 4, 5]); 3893
3919 3894 %!assert (zeros (3, "int8"), int8 ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
3920 %!assert(zeros (3,'int8'), int8([0, 0, 0; 0, 0, 0; 0, 0, 0])); 3895 %!assert (zeros (2, 3, "int8"), int8 ([0, 0, 0; 0, 0, 0]))
3921 %!assert(zeros (2, 3,'int8'), int8([0, 0, 0; 0, 0, 0])); 3896 %!assert (zeros (3, 2, "int8"), int8 ([0, 0; 0, 0; 0, 0]))
3922 %!assert(zeros (3, 2,'int8'), int8([0, 0; 0, 0; 0, 0])); 3897 %!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5])
3923 %!assert(size (zeros (3, 4, 5, 'int8')), [3, 4, 5]); 3898 */
3924
3925 */
3926 3899
3927 DEFUN (Inf, args, , 3900 DEFUN (Inf, args, ,
3928 "-*- texinfo -*-\n\ 3901 "-*- texinfo -*-\n\
3929 @c List other form of function in documentation index\n\ 3902 @c List other form of function in documentation index\n\
3930 @findex inf\n\ 3903 @findex inf\n\
3963 } 3936 }
3964 3937
3965 DEFALIAS (inf, Inf); 3938 DEFALIAS (inf, Inf);
3966 3939
3967 /* 3940 /*
3968 3941 %!assert (inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])
3969 %!assert(inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]); 3942 %!assert (inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf])
3970 %!assert(inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf]); 3943 %!assert (inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf])
3971 %!assert(inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf]); 3944 %!assert (size (inf (3, 4, 5)), [3, 4, 5])
3972 %!assert(size (inf (3, 4, 5)), [3, 4, 5]); 3945
3973 3946 %!assert (inf (3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]))
3974 %!assert(inf (3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])); 3947 %!assert (inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf]))
3975 %!assert(inf (2, 3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf])); 3948 %!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf]))
3976 %!assert(inf (3, 2,'single'), single([Inf, Inf; Inf, Inf; Inf, Inf])); 3949 %!assert (size (inf (3, 4, 5, "single")), [3, 4, 5])
3977 %!assert(size (inf (3, 4, 5, 'single')), [3, 4, 5]); 3950
3978 3951 %!error (inf (3, "int8"))
3979 %!error(inf (3,'int8')); 3952 %!error (inf (2, 3, "int8"))
3980 %!error(inf (2, 3,'int8')); 3953 %!error (inf (3, 2, "int8"))
3981 %!error(inf (3, 2,'int8')); 3954 %!error (inf (3, 4, 5, "int8"))
3982 %!error(inf (3, 4, 5, 'int8')); 3955 */
3983
3984 */
3985 3956
3986 DEFUN (NaN, args, , 3957 DEFUN (NaN, args, ,
3987 "-*- texinfo -*-\n\ 3958 "-*- texinfo -*-\n\
3988 @c List other form of function in documentation index\n\ 3959 @c List other form of function in documentation index\n\
3989 @findex nan\n\ 3960 @findex nan\n\
4024 } 3995 }
4025 3996
4026 DEFALIAS (nan, NaN); 3997 DEFALIAS (nan, NaN);
4027 3998
4028 /* 3999 /*
4029 %!assert(NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]); 4000 %!assert (NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])
4030 %!assert(NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN]); 4001 %!assert (NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN])
4031 %!assert(NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN]); 4002 %!assert (NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN])
4032 %!assert(size (NaN (3, 4, 5)), [3, 4, 5]); 4003 %!assert (size (NaN (3, 4, 5)), [3, 4, 5])
4033 4004
4034 %!assert(NaN (3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])); 4005 %!assert (NaN (3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
4035 %!assert(NaN (2, 3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN])); 4006 %!assert (NaN (2, 3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN]))
4036 %!assert(NaN (3, 2,'single'), single([NaN, NaN; NaN, NaN; NaN, NaN])); 4007 %!assert (NaN (3, 2, "single"), single ([NaN, NaN; NaN, NaN; NaN, NaN]))
4037 %!assert(size (NaN (3, 4, 5, 'single')), [3, 4, 5]); 4008 %!assert (size (NaN (3, 4, 5, "single")), [3, 4, 5])
4038 4009
4039 %!error(NaN (3,'int8')); 4010 %!error (NaN (3, "int8"))
4040 %!error(NaN (2, 3,'int8')); 4011 %!error (NaN (2, 3, "int8"))
4041 %!error(NaN (3, 2,'int8')); 4012 %!error (NaN (3, 2, "int8"))
4042 %!error(NaN (3, 4, 5, 'int8')); 4013 %!error (NaN (3, 4, 5, "int8"))
4043 4014 */
4044 */
4045 4015
4046 DEFUN (e, args, , 4016 DEFUN (e, args, ,
4047 "-*- texinfo -*-\n\ 4017 "-*- texinfo -*-\n\
4048 @deftypefn {Built-in Function} {} e\n\ 4018 @deftypefn {Built-in Function} {} e\n\
4049 @deftypefnx {Built-in Function} {} e (@var{n})\n\ 4019 @deftypefnx {Built-in Function} {} e (@var{n})\n\
4169 4139
4170 return retval; 4140 return retval;
4171 } 4141 }
4172 4142
4173 /* 4143 /*
4174 4144 %!assert (eps (1/2), 2^(-53))
4175 %!assert(eps(1/2),2^(-53)) 4145 %!assert (eps (1), 2^(-52))
4176 %!assert(eps(1),2^(-52)) 4146 %!assert (eps (2), 2^(-51))
4177 %!assert(eps(2),2^(-51)) 4147 %!assert (eps (realmax), 2^971)
4178 %!assert(eps(realmax),2^971) 4148 %!assert (eps (0), 2^(-1074))
4179 %!assert(eps(0),2^(-1074)) 4149 %!assert (eps (realmin/2), 2^(-1074))
4180 %!assert(eps(realmin/2),2^(-1074)) 4150 %!assert (eps (realmin/16), 2^(-1074))
4181 %!assert(eps(realmin/16),2^(-1074)) 4151 %!assert (eps (Inf), NaN)
4182 %!assert(eps(Inf),NaN) 4152 %!assert (eps (NaN), NaN)
4183 %!assert(eps(NaN),NaN) 4153 %!assert (eps (single (1/2)), single (2^(-24)))
4184 %!assert(eps(single(1/2)),single(2^(-24))) 4154 %!assert (eps (single (1)), single (2^(-23)))
4185 %!assert(eps(single(1)),single(2^(-23))) 4155 %!assert (eps (single (2)), single (2^(-22)))
4186 %!assert(eps(single(2)),single(2^(-22))) 4156 %!assert (eps (realmax ("single")), single (2^104))
4187 %!assert(eps(realmax('single')),single(2^104)) 4157 %!assert (eps (single (0)), single (2^(-149)))
4188 %!assert(eps(single(0)),single(2^(-149))) 4158 %!assert (eps (realmin ("single")/2), single (2^(-149)))
4189 %!assert(eps(realmin('single')/2),single(2^(-149))) 4159 %!assert (eps (realmin ("single")/16), single (2^(-149)))
4190 %!assert(eps(realmin('single')/16),single(2^(-149))) 4160 %!assert (eps (single (Inf)), single (NaN))
4191 %!assert(eps(single(Inf)),single(NaN)) 4161 %!assert (eps (single (NaN)), single (NaN))
4192 %!assert(eps(single(NaN)),single(NaN))
4193
4194 */ 4162 */
4195
4196 4163
4197 DEFUN (pi, args, , 4164 DEFUN (pi, args, ,
4198 "-*- texinfo -*-\n\ 4165 "-*- texinfo -*-\n\
4199 @deftypefn {Built-in Function} {} pi\n\ 4166 @deftypefn {Built-in Function} {} pi\n\
4200 @deftypefnx {Built-in Function} {} pi (@var{n})\n\ 4167 @deftypefnx {Built-in Function} {} pi (@var{n})\n\
4366 return fill_matrix (args, lo_ieee_na_value (), 4333 return fill_matrix (args, lo_ieee_na_value (),
4367 lo_ieee_float_na_value (), "NA"); 4334 lo_ieee_float_na_value (), "NA");
4368 } 4335 }
4369 4336
4370 /* 4337 /*
4371 4338 %!assert (single (NA ("double")), NA ("single"))
4372 %!assert(single(NA('double')),NA('single')) 4339 %!assert (double (NA ("single")), NA ("double"))
4373 %!assert(double(NA('single')),NA('double')) 4340 */
4374
4375 */
4376 4341
4377 DEFUN (false, args, , 4342 DEFUN (false, args, ,
4378 "-*- texinfo -*-\n\ 4343 "-*- texinfo -*-\n\
4379 @deftypefn {Built-in Function} {} false (@var{x})\n\ 4344 @deftypefn {Built-in Function} {} false (@var{x})\n\
4380 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\ 4345 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\
4619 } 4584 }
4620 4585
4621 return retval; 4586 return retval;
4622 } 4587 }
4623 4588
4624
4625 /* 4589 /*
4626 4590 %!assert (full (eye (3)), [1, 0, 0; 0, 1, 0; 0, 0, 1])
4627 %!assert (full (eye(3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]); 4591 %!assert (full (eye (2, 3)), [1, 0, 0; 0, 1, 0])
4628 %!assert (full (eye(2, 3)), [1, 0, 0; 0, 1, 0]); 4592
4629 4593 %!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
4630 %!assert (full (eye(3,'single')), single([1, 0, 0; 0, 1, 0; 0, 0, 1])); 4594 %!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0]))
4631 %!assert (full (eye(2, 3,'single')), single([1, 0, 0; 0, 1, 0])); 4595
4632 4596 %!assert (eye (3, "int8"), int8 ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
4633 %!assert (eye(3,'int8'), int8([1, 0, 0; 0, 1, 0; 0, 0, 1])); 4597 %!assert (eye (2, 3, "int8"), int8 ([1, 0, 0; 0, 1, 0]))
4634 %!assert (eye(2, 3,'int8'), int8([1, 0, 0; 0, 1, 0])); 4598
4635 4599 %!error eye (1, 2, 3)
4636 %!error <Invalid call to eye> eye (1, 2, 3); 4600 */
4637
4638 */
4639 4601
4640 template <class MT> 4602 template <class MT>
4641 static octave_value 4603 static octave_value
4642 do_linspace (const octave_value& base, const octave_value& limit, 4604 do_linspace (const octave_value& base, const octave_value& limit,
4643 octave_idx_type n) 4605 octave_idx_type n)
4742 return retval; 4704 return retval;
4743 } 4705 }
4744 4706
4745 4707
4746 /* 4708 /*
4747
4748 %!test 4709 %!test
4749 %! x1 = linspace (1, 2); 4710 %! x1 = linspace (1, 2);
4750 %! x2 = linspace (1, 2, 10); 4711 %! x2 = linspace (1, 2, 10);
4751 %! x3 = linspace (1, -2, 10); 4712 %! x3 = linspace (1, -2, 10);
4752 %! assert((size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2 4713 %! assert (size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2);
4753 %! && size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2 4714 %! assert (size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2);
4754 %! && size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2)); 4715 %! assert (size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2);
4755 4716
4756 4717 %#assert (linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6))
4757 % assert(linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6)); 4718
4758 4719 %!fail ("linspace ([1, 2; 3, 4], 5, 6)", "warning")
4759 %!error <Invalid call to linspace> linspace (); 4720
4760 %!error <Invalid call to linspace> linspace (1, 2, 3, 4); 4721 %!error linspace ()
4761 4722 %!error linspace (1, 2, 3, 4)
4762 %!test
4763 %! fail("linspace ([1, 2; 3, 4], 5, 6)","warning");
4764
4765 */ 4723 */
4766 4724
4767 // FIXME -- should accept dimensions as separate args for N-d 4725 // FIXME -- should accept dimensions as separate args for N-d
4768 // arrays as well as 1-d and 2-d arrays. 4726 // arrays as well as 1-d and 2-d arrays.
4769 4727
4975 4933
4976 return retval; 4934 return retval;
4977 } 4935 }
4978 4936
4979 /* 4937 /*
4980 4938 %!assert (size (reshape (ones (4, 4), 2, 8)), [2, 8])
4981 %!assert(size (reshape (ones (4, 4), 2, 8)), [2, 8]) 4939 %!assert (size (reshape (ones (4, 4), 8, 2)), [8, 2])
4982 %!assert(size (reshape (ones (4, 4), 8, 2)), [8, 2]) 4940 %!assert (size (reshape (ones (15, 4), 1, 60)), [1, 60])
4983 %!assert(size (reshape (ones (15, 4), 1, 60)), [1, 60]) 4941 %!assert (size (reshape (ones (15, 4), 60, 1)), [60, 1])
4984 %!assert(size (reshape (ones (15, 4), 60, 1)), [60, 1]) 4942
4985 4943 %!assert (size (reshape (ones (4, 4, "single"), 2, 8)), [2, 8])
4986 %!assert(size (reshape (ones (4, 4, 'single'), 2, 8)), [2, 8]) 4944 %!assert (size (reshape (ones (4, 4, "single"), 8, 2)), [8, 2])
4987 %!assert(size (reshape (ones (4, 4, 'single'), 8, 2)), [8, 2]) 4945 %!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60])
4988 %!assert(size (reshape (ones (15, 4, 'single'), 1, 60)), [1, 60]) 4946 %!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1])
4989 %!assert(size (reshape (ones (15, 4, 'single'), 60, 1)), [60, 1])
4990 4947
4991 %!test 4948 %!test
4992 %! s.a = 1; 4949 %! s.a = 1;
4993 %! fail("reshape (s, 2, 3)"); 4950 %! fail ("reshape (s, 2, 3)");
4994 4951
4995 %!error <Invalid call to reshape> reshape (); 4952 %!error reshape ()
4996 %!error reshape (1, 2, 3, 4); 4953 %!error reshape (1, 2, 3, 4)
4997 4954 */
4998 */
4999 4955
5000 DEFUN (vec, args, , 4956 DEFUN (vec, args, ,
5001 "-*- texinfo -*-\n\ 4957 "-*- texinfo -*-\n\
5002 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\ 4958 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\
5003 @deftypefnx {Built-in Function} {@var{v} =} vec (@var{x}, @var{dim})\n\ 4959 @deftypefnx {Built-in Function} {@var{v} =} vec (@var{x}, @var{dim})\n\
5047 5003
5048 return retval; 5004 return retval;
5049 } 5005 }
5050 5006
5051 /* 5007 /*
5052 5008 %!assert (vec ([1, 2; 3, 4]), [1; 3; 2; 4])
5053 %!assert(vec ([1, 2; 3, 4]), [1; 3; 2; 4]) 5009 %!assert (vec ([1, 3, 2, 4]), [1; 3; 2; 4])
5054 %!assert(vec ([1, 3, 2, 4]), [1; 3; 2; 4]); 5010 %!assert (vec ([1, 2, 3, 4], 2), [1, 2, 3, 4])
5055 %!assert(vec ([1, 2, 3, 4], 2), [1, 2, 3, 4]); 5011 %!assert (vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1))
5056 %!assert(vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1)); 5012 %!assert (vec ([1, 2; 3, 4], 1), [1; 3; 2; 4])
5057 %!assert(vec ([1, 2; 3, 4], 1), [1; 3; 2; 4]); 5013 %!assert (vec ([1, 2; 3, 4], 2), [1, 3, 2, 4])
5058 %!assert(vec ([1, 2; 3, 4], 2), [1, 3, 2, 4]); 5014 %!assert (vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4))
5059 %!assert(vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4)); 5015 %!assert (vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2))
5060 %!assert(vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2)); 5016
5061 5017 %!error vec ()
5062 %!error vec (); 5018 %!error vec (1, 2, 3)
5063 %!error vec (1, 2, 3); 5019 %!error vec ([1, 2; 3, 4], 0)
5064 %!error vec ([1, 2; 3, 4], 0);
5065
5066 */ 5020 */
5067 5021
5068 DEFUN (squeeze, args, , 5022 DEFUN (squeeze, args, ,
5069 "-*- texinfo -*-\n\ 5023 "-*- texinfo -*-\n\
5070 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ 5024 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\
5225 } 5179 }
5226 5180
5227 /* 5181 /*
5228 %!shared x 5182 %!shared x
5229 %! x = [1, -3, 4, 5, -7]; 5183 %! x = [1, -3, 4, 5, -7];
5230 %!assert(norm(x,1), 20); 5184 %!assert (norm (x,1), 20)
5231 %!assert(norm(x,2), 10); 5185 %!assert (norm (x,2), 10)
5232 %!assert(norm(x,3), 8.24257059961711, -4*eps); 5186 %!assert (norm (x,3), 8.24257059961711, -4*eps)
5233 %!assert(norm(x,Inf), 7); 5187 %!assert (norm (x,Inf), 7)
5234 %!assert(norm(x,-Inf), 1); 5188 %!assert (norm (x,-Inf), 1)
5235 %!assert(norm(x,"inf"), 7); 5189 %!assert (norm (x,"inf"), 7)
5236 %!assert(norm(x,"fro"), 10, -eps); 5190 %!assert (norm (x,"fro"), 10, -eps)
5237 %!assert(norm(x), 10); 5191 %!assert (norm (x), 10)
5238 %!assert(norm([1e200, 1]), 1e200); 5192 %!assert (norm ([1e200, 1]), 1e200)
5239 %!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps); 5193 %!assert (norm ([3+4i, 3-4i, sqrt(31)]), 9, -4*eps)
5240 %!shared m 5194 %!shared m
5241 %! m = magic (4); 5195 %! m = magic (4);
5242 %!assert(norm(m,1), 34); 5196 %!assert (norm (m,1), 34)
5243 %!assert(norm(m,2), 34, -eps); 5197 %!assert (norm (m,2), 34, -eps)
5244 %!assert(norm(m,Inf), 34); 5198 %!assert (norm (m,Inf), 34)
5245 %!assert(norm(m,"inf"), 34); 5199 %!assert (norm (m,"inf"), 34)
5246 %!shared m2, flo, fhi 5200 %!shared m2, flo, fhi
5247 %! m2 = [1,2;3,4]; 5201 %! m2 = [1,2;3,4];
5248 %! flo = 1e-300; 5202 %! flo = 1e-300;
5249 %! fhi = 1e+300; 5203 %! fhi = 1e+300;
5250 %!assert (norm(flo*m2,"fro"), sqrt(30)*flo, -eps) 5204 %!assert (norm (flo*m2,"fro"), sqrt (30)*flo, -eps)
5251 %!assert (norm(fhi*m2,"fro"), sqrt(30)*fhi, -eps) 5205 %!assert (norm (fhi*m2,"fro"), sqrt (30)*fhi, -eps)
5252 5206
5253 %!shared x 5207 %!shared x
5254 %! x = single([1, -3, 4, 5, -7]); 5208 %! x = single ([1, -3, 4, 5, -7]);
5255 %!assert(norm(x,1), single(20)); 5209 %!assert (norm (x,1), single (20))
5256 %!assert(norm(x,2), single(10)); 5210 %!assert (norm (x,2), single (10))
5257 %!assert(norm(x,3), single(8.24257059961711), -4*eps('single')); 5211 %!assert (norm (x,3), single (8.24257059961711), -4*eps ("single"))
5258 %!assert(norm(x,Inf), single(7)); 5212 %!assert (norm (x,Inf), single (7))
5259 %!assert(norm(x,-Inf), single(1)); 5213 %!assert (norm (x,-Inf), single (1))
5260 %!assert(norm(x,"inf"), single(7)); 5214 %!assert (norm (x,"inf"), single (7))
5261 %!assert(norm(x,"fro"), single(10), -eps('single')); 5215 %!assert (norm (x,"fro"), single (10), -eps ("single"))
5262 %!assert(norm(x), single(10)); 5216 %!assert (norm (x), single (10))
5263 %!assert(norm(single([1e200, 1])), single(1e200)); 5217 %!assert (norm (single ([1e200, 1])), single (1e200))
5264 %!assert(norm(single([3+4i, 3-4i, sqrt(31)])), single(9), -4*eps('single')); 5218 %!assert (norm (single ([3+4i, 3-4i, sqrt(31)])), single (9), -4*eps ("single"))
5265 %!shared m 5219 %!shared m
5266 %! m = single(magic (4)); 5220 %! m = single (magic (4));
5267 %!assert(norm(m,1), single(34)); 5221 %!assert (norm (m,1), single (34))
5268 %!assert(norm(m,2), single(34), -eps('single')); 5222 %!assert (norm (m,2), single (34), -eps ("single"))
5269 %!assert(norm(m,Inf), single(34)); 5223 %!assert (norm (m,Inf), single (34))
5270 %!assert(norm(m,"inf"), single(34)); 5224 %!assert (norm (m,"inf"), single (34))
5271 %!shared m2, flo, fhi 5225 %!shared m2, flo, fhi
5272 %! m2 = single([1,2;3,4]); 5226 %! m2 = single ([1,2;3,4]);
5273 %! flo = single(1e-300); 5227 %! flo = single (1e-300);
5274 %! fhi = single(1e+300); 5228 %! fhi = single (1e+300);
5275 %!assert (norm(flo*m2,"fro"), single(sqrt(30)*flo), -eps('single')) 5229 %!assert (norm (flo*m2,"fro"), single (sqrt (30)*flo), -eps ("single"))
5276 %!assert (norm(fhi*m2,"fro"), single(sqrt(30)*fhi), -eps('single')) 5230 %!assert (norm (fhi*m2,"fro"), single (sqrt (30)*fhi), -eps ("single"))
5277 */ 5231 */
5278 5232
5279 static octave_value 5233 static octave_value
5280 unary_op_defun_body (octave_value::unary_op op, 5234 unary_op_defun_body (octave_value::unary_op op,
5281 const octave_value_list& args) 5235 const octave_value_list& args)
5328 { 5282 {
5329 return unary_op_defun_body (octave_value::op_transpose, args); 5283 return unary_op_defun_body (octave_value::op_transpose, args);
5330 } 5284 }
5331 5285
5332 /* 5286 /*
5333 5287 %!assert (2.', 2)
5334 %!assert (2.', 2); 5288 %!assert (2i.', 2i)
5335 %!assert (2i.',2i); 5289 %!assert ([1:4].', [1;2;3;4])
5336 %!assert ([1:4].',[1;2;3;4]); 5290 %!assert ([1;2;3;4].', [1:4])
5337 %!assert ([1;2;3;4].',[1:4]); 5291 %!assert ([1,2;3,4].', [1,3;2,4])
5338 %!assert ([1,2;3,4].',[1,3;2,4]); 5292 %!assert ([1,2i;3,4].', [1,3;2i,4])
5339 %!assert ([1,2i;3,4].',[1,3;2i,4]); 5293
5340 5294 %!assert (transpose ([1,2;3,4]), [1,3;2,4])
5341 %!assert (transpose ([1,2;3,4]),[1,3;2,4]); 5295
5342 5296 %!assert (single (2).', single (2))
5343 %!assert (single(2).', single(2)); 5297 %!assert (single (2i).', single (2i))
5344 %!assert (single(2i).',single(2i)); 5298 %!assert (single ([1:4]).', single ([1;2;3;4]))
5345 %!assert (single([1:4]).',single([1;2;3;4])); 5299 %!assert (single ([1;2;3;4]).', single ([1:4]))
5346 %!assert (single([1;2;3;4]).',single([1:4])); 5300 %!assert (single ([1,2;3,4]).', single ([1,3;2,4]))
5347 %!assert (single([1,2;3,4]).',single([1,3;2,4])); 5301 %!assert (single ([1,2i;3,4]).', single ([1,3;2i,4]))
5348 %!assert (single([1,2i;3,4]).',single([1,3;2i,4])); 5302
5349 5303 %!assert (transpose (single ([1,2;3,4])), single ([1,3;2,4]))
5350 %!assert (transpose (single([1,2;3,4])),single([1,3;2,4]));
5351
5352 */ 5304 */
5353 5305
5354 DEFUN (ctranspose, args, , 5306 DEFUN (ctranspose, args, ,
5355 "-*- texinfo -*-\n\ 5307 "-*- texinfo -*-\n\
5356 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\ 5308 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\
5361 { 5313 {
5362 return unary_op_defun_body (octave_value::op_hermitian, args); 5314 return unary_op_defun_body (octave_value::op_hermitian, args);
5363 } 5315 }
5364 5316
5365 /* 5317 /*
5366 5318 %!assert (2', 2)
5367 %!assert (2', 2); 5319 %!assert (2i', -2i)
5368 %!assert (2i',-2i); 5320 %!assert ([1:4]', [1;2;3;4])
5369 %!assert ([1:4]',[1;2;3;4]); 5321 %!assert ([1;2;3;4]', [1:4])
5370 %!assert ([1;2;3;4]',[1:4]); 5322 %!assert ([1,2;3,4]', [1,3;2,4])
5371 %!assert ([1,2;3,4]',[1,3;2,4]); 5323 %!assert ([1,2i;3,4]', [1,3;-2i,4])
5372 %!assert ([1,2i;3,4]',[1,3;-2i,4]); 5324
5373 5325 %!assert (ctranspose ([1,2i;3,4]), [1,3;-2i,4])
5374 %!assert (ctranspose ([1,2i;3,4]),[1,3;-2i,4]); 5326
5375 5327 %!assert (single (2)', single (2))
5376 %!assert (single(2)', single(2)); 5328 %!assert (single (2i)', single (-2i))
5377 %!assert (single(2i)',single(-2i)); 5329 %!assert (single ([1:4])', single ([1;2;3;4]))
5378 %!assert (single([1:4])',single([1;2;3;4])); 5330 %!assert (single ([1;2;3;4])', single ([1:4]))
5379 %!assert (single([1;2;3;4])',single([1:4])); 5331 %!assert (single ([1,2;3,4])', single ([1,3;2,4]))
5380 %!assert (single([1,2;3,4])',single([1,3;2,4])); 5332 %!assert (single ([1,2i;3,4])', single ([1,3;-2i,4]))
5381 %!assert (single([1,2i;3,4])',single([1,3;-2i,4])); 5333
5382 5334 %!assert (ctranspose (single ([1,2i;3,4])), single ([1,3;-2i,4]))
5383 %!assert (ctranspose (single([1,2i;3,4])),single([1,3;-2i,4]));
5384
5385 */ 5335 */
5386 5336
5387 static octave_value 5337 static octave_value
5388 binary_op_defun_body (octave_value::binary_op op, 5338 binary_op_defun_body (octave_value::binary_op op,
5389 const octave_value_list& args) 5339 const octave_value_list& args)
6002 5952
6003 return retval; 5953 return retval;
6004 } 5954 }
6005 5955
6006 /* 5956 /*
6007 5957 ## Double
6008 %% Double
6009 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) 5958 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN])
6010 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) 5959 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf])
6011 %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN]) 5960 %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN])
6012 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf]) 5961 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf])
6013 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN]) 5962 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN])
6019 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8]) 5968 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8])
6020 %!assert (sort (1), 1) 5969 %!assert (sort (1), 1)
6021 5970
6022 %!test 5971 %!test
6023 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]); 5972 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]);
6024 %! assert (v, [-1, 1, 1, Inf, NaN]) 5973 %! assert (v, [-1, 1, 1, Inf, NaN]);
6025 %! assert (i, [3, 2, 5, 4, 1]) 5974 %! assert (i, [3, 2, 5, 4, 1]);
6026 5975
6027 %% Complex 5976 ## Complex
6028 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) 5977 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN])
6029 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) 5978 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf])
6030 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN]) 5979 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN])
6031 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf]) 5980 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf])
6032 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN]) 5981 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN])
6038 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8]) 5987 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8])
6039 %!assert (sort (1i), 1i) 5988 %!assert (sort (1i), 1i)
6040 5989
6041 %!test 5990 %!test
6042 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]); 5991 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]);
6043 %! assert (v, [1, 1i, 1i, -1, Inf, NaN]) 5992 %! assert (v, [1, 1i, 1i, -1, Inf, NaN]);
6044 %! assert (i, [5, 2, 6, 3, 4, 1]) 5993 %! assert (i, [5, 2, 6, 3, 4, 1]);
6045 5994
6046 %% Single 5995 ## Single
6047 %!assert (sort (single([NaN, 1, -1, 2, Inf])), single([-1, 1, 2, Inf, NaN])) 5996 %!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN]))
6048 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 1), single([NaN, 1, -1, 2, Inf])) 5997 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1), single ([NaN, 1, -1, 2, Inf]))
6049 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2), single([-1, 1, 2, Inf, NaN])) 5998 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2), single ([-1, 1, 2, Inf, NaN]))
6050 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 3), single([NaN, 1, -1, 2, Inf])) 5999 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3), single ([NaN, 1, -1, 2, Inf]))
6051 %!assert (sort (single([NaN, 1, -1, 2, Inf]), "ascend"), single([-1, 1, 2, Inf, NaN])) 6000 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"), single ([-1, 1, 2, Inf, NaN]))
6052 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "ascend"), single([-1, 1, 2, Inf, NaN])) 6001 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"), single ([-1, 1, 2, Inf, NaN]))
6053 %!assert (sort (single([NaN, 1, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, 1, -1])) 6002 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, 1, -1]))
6054 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, 1, -1])) 6003 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, 1, -1]))
6055 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4])), single([3, 1, 6, 4; 8, 2, 7, 5])) 6004 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])), single ([3, 1, 6, 4; 8, 2, 7, 5]))
6056 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 1), single([3, 1, 6, 4; 8, 2, 7, 5])) 6005 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1, 6, 4; 8, 2, 7, 5]))
6057 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 2), single([1, 3, 5, 7; 2, 4, 6, 8])) 6006 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2), single ([1, 3, 5, 7; 2, 4, 6, 8]))
6058 %!assert (sort (single(1)), single(1)) 6007 %!assert (sort (single (1)), single (1))
6059 6008
6060 %!test 6009 %!test
6061 %! [v, i] = sort (single([NaN, 1, -1, Inf, 1])); 6010 %! [v, i] = sort (single ([NaN, 1, -1, Inf, 1]));
6062 %! assert (v, single([-1, 1, 1, Inf, NaN])) 6011 %! assert (v, single ([-1, 1, 1, Inf, NaN]));
6063 %! assert (i, [3, 2, 5, 4, 1]) 6012 %! assert (i, [3, 2, 5, 4, 1]);
6064 6013
6065 %% Single Complex 6014 ## Single Complex
6066 %!assert (sort (single([NaN, 1i, -1, 2, Inf])), single([1i, -1, 2, Inf, NaN])) 6015 %!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN]))
6067 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 1), single([NaN, 1i, -1, 2, Inf])) 6016 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1), single ([NaN, 1i, -1, 2, Inf]))
6068 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2), single([1i, -1, 2, Inf, NaN])) 6017 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2), single ([1i, -1, 2, Inf, NaN]))
6069 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 3), single([NaN, 1i, -1, 2, Inf])) 6018 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3), single ([NaN, 1i, -1, 2, Inf]))
6070 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), "ascend"), single([1i, -1, 2, Inf, NaN])) 6019 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"), single ([1i, -1, 2, Inf, NaN]))
6071 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single([1i, -1, 2, Inf, NaN])) 6020 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single ([1i, -1, 2, Inf, NaN]))
6072 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, -1, 1i])) 6021 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, -1, 1i]))
6073 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, -1, 1i])) 6022 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, -1, 1i]))
6074 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4])), single([3, 1i, 6, 4; 8, 2, 7, 5])) 6023 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
6075 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single([3, 1i, 6, 4; 8, 2, 7, 5])) 6024 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
6076 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single([1i, 3, 5, 7; 2, 4, 6, 8])) 6025 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single ([1i, 3, 5, 7; 2, 4, 6, 8]))
6077 %!assert (sort (single(1i)),single( 1i)) 6026 %!assert (sort (single (1i)), single (1i))
6078 6027
6079 %!test 6028 %!test
6080 %! [v, i] = sort (single([NaN, 1i, -1, Inf, 1, 1i])); 6029 %! [v, i] = sort (single ([NaN, 1i, -1, Inf, 1, 1i]));
6081 %! assert (v, single([1, 1i, 1i, -1, Inf, NaN])) 6030 %! assert (v, single ([1, 1i, 1i, -1, Inf, NaN]));
6082 %! assert (i, [5, 2, 6, 3, 4, 1]) 6031 %! assert (i, [5, 2, 6, 3, 4, 1]);
6083 6032
6084 %% Bool 6033 ## Bool
6085 %!assert (sort ([true, false, true, false]), [false, false, true, true]) 6034 %!assert (sort ([true, false, true, false]), [false, false, true, true])
6086 %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) 6035 %!assert (sort ([true, false, true, false], 1), [true, false, true, false])
6087 %!assert (sort ([true, false, true, false], 2), [false, false, true, true]) 6036 %!assert (sort ([true, false, true, false], 2), [false, false, true, true])
6088 %!assert (sort ([true, false, true, false], 3), [true, false, true, false]) 6037 %!assert (sort ([true, false, true, false], 3), [true, false, true, false])
6089 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true]) 6038 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true])
6092 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false]) 6041 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false])
6093 %!assert (sort (true), true) 6042 %!assert (sort (true), true)
6094 6043
6095 %!test 6044 %!test
6096 %! [v, i] = sort ([true, false, true, false]); 6045 %! [v, i] = sort ([true, false, true, false]);
6097 %! assert (v, [false, false, true, true]) 6046 %! assert (v, [false, false, true, true]);
6098 %! assert (i, [2, 4, 1, 3]) 6047 %! assert (i, [2, 4, 1, 3]);
6099 6048
6100 %% Sparse Double 6049 ## Sparse Double
6101 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) 6050 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
6102 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) 6051 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
6103 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) 6052 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
6104 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf])) 6053 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
6105 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) 6054 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
6107 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) 6056 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
6108 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) 6057 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
6109 6058
6110 %!shared a 6059 %!shared a
6111 %! a = randn (10, 10); 6060 %! a = randn (10, 10);
6112 %! a (a < 0) = 0; 6061 %! a(a < 0) = 0;
6113 %!assert (sort (sparse (a)), sparse (sort (a))) 6062 %!assert (sort (sparse (a)), sparse (sort (a)))
6114 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) 6063 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
6115 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) 6064 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
6116 %!test 6065 %!test
6117 %! [v, i] = sort (a); 6066 %! [v, i] = sort (a);
6118 %! [vs, is] = sort (sparse (a)); 6067 %! [vs, is] = sort (sparse (a));
6119 %! assert (vs, sparse (v)) 6068 %! assert (vs, sparse (v));
6120 %! assert (is, i) 6069 %! assert (is, i);
6121 6070
6122 %% Sparse Complex 6071 ## Sparse Complex
6123 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) 6072 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
6124 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) 6073 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
6125 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) 6074 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
6126 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) 6075 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
6127 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) 6076 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
6129 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) 6078 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
6130 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) 6079 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
6131 6080
6132 %!shared a 6081 %!shared a
6133 %! a = randn (10, 10); 6082 %! a = randn (10, 10);
6134 %! a (a < 0) = 0; 6083 %! a(a < 0) = 0;
6135 %! a = 1i * a; 6084 %! a = 1i * a;
6136 %!assert (sort (sparse (a)), sparse (sort (a))) 6085 %!assert (sort (sparse (a)), sparse (sort (a)))
6137 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) 6086 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
6138 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) 6087 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
6139 %!test 6088 %!test
6140 %! [v, i] = sort (a); 6089 %! [v, i] = sort (a);
6141 %! [vs, is] = sort (sparse (a)); 6090 %! [vs, is] = sort (sparse (a));
6142 %! assert (vs, sparse (v)) 6091 %! assert (vs, sparse (v));
6143 %! assert (is, i) 6092 %! assert (is, i);
6144 6093
6145 %% Sparse Bool 6094 ## Sparse Bool
6146 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true])) 6095 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true]))
6147 %!assert (sort (sparse([true, false, true, false]), 1), sparse ([true, false, true, false])) 6096 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false]))
6148 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true])) 6097 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true]))
6149 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false])) 6098 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false]))
6150 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse([false, false, true, true])) 6099 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse ([false, false, true, true]))
6151 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse([false, false, true, true])) 6100 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true]))
6152 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false])) 6101 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false]))
6153 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse([true, true, false, false])) 6102 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false]))
6154 6103
6155 %!test 6104 %!test
6156 %! [v, i] = sort (sparse([true, false, true, false])); 6105 %! [v, i] = sort (sparse ([true, false, true, false]));
6157 %! assert (v, sparse([false, false, true, true])) 6106 %! assert (v, sparse ([false, false, true, true]));
6158 %! assert (i, [2, 4, 1, 3]) 6107 %! assert (i, [2, 4, 1, 3]);
6159 6108
6160 %% Cell string array 6109 ## Cell string array
6161 %!shared a, b, c 6110 %!shared a, b, c
6162 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; 6111 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
6163 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; 6112 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
6164 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"}; 6113 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"};
6165 %!assert (sort (a), b); 6114 %!assert (sort (a), b)
6166 %!assert (sort (a, 1), a) 6115 %!assert (sort (a, 1), a)
6167 %!assert (sort (a, 2), b) 6116 %!assert (sort (a, 2), b)
6168 %!assert (sort (a, 3), a) 6117 %!assert (sort (a, 3), a)
6169 %!assert (sort (a, "ascend"), b) 6118 %!assert (sort (a, "ascend"), b)
6170 %!assert (sort (a, 2, "ascend"), b) 6119 %!assert (sort (a, 2, "ascend"), b)
6171 %!assert (sort (a, "descend"), c) 6120 %!assert (sort (a, "descend"), c)
6172 %!assert (sort (a, 2, "descend"), c) 6121 %!assert (sort (a, 2, "descend"), c)
6173 6122
6174 %!test 6123 %!test
6175 %! [v, i] = sort (a); 6124 %! [v, i] = sort (a);
6176 %! assert (i, [1, 4, 2, 5, 3]) 6125 %! assert (i, [1, 4, 2, 5, 3]);
6177 6126
6178 %!error <Invalid call to sort> sort (); 6127 %!error sort ()
6179 %!error <Invalid call to sort> sort (1, 2, 3, 4); 6128 %!error sort (1, 2, 3, 4)
6180
6181 */ 6129 */
6182 6130
6183 // Sort the rows of the matrix @var{a} according to the order 6131 // Sort the rows of the matrix @var{a} according to the order
6184 // specified by @var{mode}, which can either be `ascend' or `descend' 6132 // specified by @var{mode}, which can either be `ascend' or `descend'
6185 // and return the index vector corresponding to the sort order. 6133 // and return the index vector corresponding to the sort order.
6338 %!shared sm, um, sv, uv 6286 %!shared sm, um, sv, uv
6339 %! sm = [1, 2; 3, 4]; 6287 %! sm = [1, 2; 3, 4];
6340 %! um = [3, 1; 2, 4]; 6288 %! um = [3, 1; 2, 4];
6341 %! sv = [1, 2, 3, 4]; 6289 %! sv = [1, 2, 3, 4];
6342 %! uv = [2, 1, 4, 3]; 6290 %! uv = [2, 1, 4, 3];
6343 %!assert(issorted (sm, "rows")); 6291 %!assert (issorted (sm, "rows"))
6344 %!assert(!issorted (um, "rows")); 6292 %!assert (!issorted (um, "rows"))
6345 %!assert(issorted (sv)); 6293 %!assert (issorted (sv))
6346 %!assert(!issorted (uv)); 6294 %!assert (!issorted (uv))
6347 %!assert(issorted (sv')); 6295 %!assert (issorted (sv'))
6348 %!assert(!issorted (uv')); 6296 %!assert (!issorted (uv'))
6349 %!assert(issorted (sm, "rows", "ascending")); 6297 %!assert (issorted (sm, "rows", "ascending"))
6350 %!assert(!issorted (um, "rows", "ascending")); 6298 %!assert (!issorted (um, "rows", "ascending"))
6351 %!assert(issorted (sv, "ascending")); 6299 %!assert (issorted (sv, "ascending"))
6352 %!assert(!issorted (uv, "ascending")); 6300 %!assert (!issorted (uv, "ascending"))
6353 %!assert(issorted (sv', "ascending")); 6301 %!assert (issorted (sv', "ascending"))
6354 %!assert(!issorted (uv', "ascending")); 6302 %!assert (!issorted (uv', "ascending"))
6355 %!assert(!issorted (sm, "rows", "descending")); 6303 %!assert (!issorted (sm, "rows", "descending"))
6356 %!assert(issorted (flipud (sm), "rows", "descending")); 6304 %!assert (issorted (flipud (sm), "rows", "descending"))
6357 %!assert(!issorted (sv, "descending")); 6305 %!assert (!issorted (sv, "descending"))
6358 %!assert(issorted (fliplr (sv), "descending")); 6306 %!assert (issorted (fliplr (sv), "descending"))
6359 %!assert(!issorted (sv', "descending")); 6307 %!assert (!issorted (sv', "descending"))
6360 %!assert(issorted (fliplr (sv)', "descending")); 6308 %!assert (issorted (fliplr (sv)', "descending"))
6361 %!assert(!issorted (um, "rows", "either")); 6309 %!assert (!issorted (um, "rows", "either"))
6362 %!assert(!issorted (uv, "either")); 6310 %!assert (!issorted (uv, "either"))
6363 %!assert(issorted (sm, "rows", "either")); 6311 %!assert (issorted (sm, "rows", "either"))
6364 %!assert(issorted (flipud (sm), "rows", "either")); 6312 %!assert (issorted (flipud (sm), "rows", "either"))
6365 %!assert(issorted (sv, "either")); 6313 %!assert (issorted (sv, "either"))
6366 %!assert(issorted (fliplr (sv), "either")); 6314 %!assert (issorted (fliplr (sv), "either"))
6367 %!assert(issorted (sv', "either")); 6315 %!assert (issorted (sv', "either"))
6368 %!assert(issorted (fliplr (sv)', "either")); 6316 %!assert (issorted (fliplr (sv)', "either"))
6369 */ 6317 */
6370 6318
6371 DEFUN (nth_element, args, , 6319 DEFUN (nth_element, args, ,
6372 "-*- texinfo -*-\n\ 6320 "-*- texinfo -*-\n\
6373 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\ 6321 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\
7069 7017
7070 return retval; 7018 return retval;
7071 } 7019 }
7072 7020
7073 /* 7021 /*
7074
7075 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) 7022 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
7076 %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) 7023 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
7077 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5]) 7024 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5])
7078 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0]) 7025 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0])
7079 %!assert (isempty (diff (1))); 7026 %!assert (isempty (diff (1)))
7080 7027
7081 %!error diff ([1, 2; 3, 4], -1); 7028 %!error diff ()
7082 7029 %!error diff (1, 2, 3, 4)
7083 %!error diff ("foo"); 7030 %!error diff ("foo")
7084 7031 %!error diff ([1, 2; 3, 4], -1)
7085 %!error diff ();
7086
7087 %!error diff (1, 2, 3, 4);
7088
7089 */ 7032 */
7090 7033
7091 template <class T> 7034 template <class T>
7092 static Array<T> 7035 static Array<T>
7093 do_repelems (const Array<T>& src, const Array<octave_idx_type>& rep) 7036 do_repelems (const Array<T>& src, const Array<octave_idx_type>& rep)