comparison libinterp/corefcn/data.cc @ 17915:56d2b6838405

Issue an error if reshape called with just a single dimension. * data.cc (Freshape): Issue an error if reshape called with just a single dimension. Add more %!error input validation tests.
author Rik <rik@octave.org>
date Tue, 12 Nov 2013 22:37:50 -0800
parents 573f865aa8c8
children 6a71e5030df5 7eeaecac9b5b ac0c04e4d141
comparison
equal deleted inserted replaced
17914:46da2c323ad6 17915:56d2b6838405
4951 4951
4952 if (nargin == 2) 4952 if (nargin == 2)
4953 { 4953 {
4954 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); 4954 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value ();
4955 4955
4956 if (new_size.length () < 2)
4957 {
4958 error ("reshape: SIZE must have 2 or more dimensions");
4959 return retval;
4960 }
4961
4956 new_dims = dim_vector::alloc (new_size.length ()); 4962 new_dims = dim_vector::alloc (new_size.length ());
4957 4963
4958 for (octave_idx_type i = 0; i < new_size.length (); i++) 4964 for (octave_idx_type i = 0; i < new_size.length (); i++)
4959 { 4965 {
4960 if (new_size(i) < 0) 4966 if (new_size(i) < 0)
5042 %!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60]) 5048 %!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60])
5043 %!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1]) 5049 %!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1])
5044 5050
5045 %!test 5051 %!test
5046 %! s.a = 1; 5052 %! s.a = 1;
5047 %! fail ("reshape (s, 2, 3)"); 5053 %! fail ("reshape (s, 2, 3)", "can't reshape 1x1 array to 2x3 array");
5048 5054
5049 %!error reshape () 5055 %!error reshape ()
5050 %!error reshape (1, 2, 3, 4) 5056 %!error reshape (1, 2, 3, 4)
5057 %!error <SIZE must have 2 or more dimensions> reshape (1:3, 3)
5058 %!error <SIZE must be non-negative> reshape (1:3, [3 -1])
5059 %!error <only a single dimension can be unknown> reshape (1:3, 1,[],[],3)
5060 %!error <SIZE must be non-negative> reshape (1:3, 3, -1)
5061 %!error <SIZE is not divisible> reshape (1:3, 3, [], 2)
5051 */ 5062 */
5052 5063
5053 DEFUN (vec, args, , 5064 DEFUN (vec, args, ,
5054 "-*- texinfo -*-\n\ 5065 "-*- texinfo -*-\n\
5055 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\ 5066 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\