1## Copyright 2015-2016 Oliver Heimlich
2## Copyright 2017 Joel Dahne
3##
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 3 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, see <http://www.gnu.org/licenses/>.
16
17## -*- texinfo -*-
18## @documentencoding UTF-8
19## @defmethod {@@infsupdec} reshape (@var{A}, @var{M}, @var{N}, ...)
20## @defmethodx {@@infsupdec} reshape (@var{X}, [@var{M} @var{N}, ...])
21## @defmethodx {@@infsupdec} reshape (@var{X}, ..., @var{[]}, ...)
22##
23## Return an interval matrix with the specified dimensions (M, N, ...) whose
24## elements are taken from the interval matrix @var{A}.  The elements of the
25## matrix are accessed in column-major order (like Fortran arrays are stored).
26##
27## Note that the total number of elements in the original matrix
28## (@code{prod (size (@var{A}))}) must match the total number of elements in
29## the new matrix (@code{prod ([@var{M} @var{N}])}).
30##
31## A single dimension of the return matrix may be left unspecified and
32## Octave will determine its size automatically.  An empty matrix ([])
33## is used to flag the unspecified dimension.
34##
35## @example
36## @group
37## reshape (infsupdec (1 : 6), 2, 3)
38##   @result{} ans = 2×3 interval matrix
39##          [1]_com   [3]_com   [5]_com
40##          [2]_com   [4]_com   [6]_com
41## @end group
42## @end example
43## @seealso{@@infsupdec/resize, @@infsup/cat, @@infsupdec/postpad, @@infsupdec/prepad}
44## @end defmethod
45
46## Author: Oliver Heimlich
47## Keywords: interval
48## Created: 2015-04-19
49
50function x = reshape (x, varargin)
51
52  if (not (isa (x, "infsupdec")))
53    print_usage ();
54    return
55  endif
56
57  x.infsup = reshape (x.infsup, varargin{:});
58  x.dec = reshape (x.dec, varargin{:});
59
60endfunction
61
62%!assert (isequal (reshape (infsupdec (1 : 6), 2, 3), infsupdec (reshape (1 : 6, 2, 3))));
63%!assert (isequal (reshape (infsupdec (1 : 24), 2, [], 4), infsupdec (reshape (1 : 24, 2, 3, 4))));
64