comparison scripts/general/pagectranspose.m @ 31140:7c5cb8f8a21e

pagetranspose.m, pagectranspose.m: New functions for transposing the page (3-D) of an N-D array. * pagectranspose.m, pagetranspose.m: New functions. * scripts/general/module.mk: Add new functions to build system. * etc/NEWS.8.md: Announce new functions. * expr.txi: Add functions to Octave manual.
author Rik <rik@octave.org>
date Mon, 11 Jul 2022 22:38:57 -0700
parents
children 597f3ee61a48
comparison
equal deleted inserted replaced
31139:22305b923761 31140:7c5cb8f8a21e
1 ########################################################################
2 ##
3 ## Copyright (C) 2022 The Octave Project Developers
4 ##
5 ## See the file COPYRIGHT.md in the top-level directory of this
6 ## distribution or <https://octave.org/copyright/>.
7 ##
8 ## This file is part of Octave.
9 ##
10 ## Octave is free software: you can redistribute it and/or modify it
11 ## under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation, either version 3 of the License, or
13 ## (at your option) any later version.
14 ##
15 ## Octave is distributed in the hope that it will be useful, but
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
19 ##
20 ## You should have received a copy of the GNU General Public License
21 ## along with Octave; see the file COPYING. If not, see
22 ## <https://www.gnu.org/licenses/>.
23 ##
24 ########################################################################
25
26 ## -*- texinfo -*-
27 ## @deftypefn {} {@var{y} =} pagectranspose (@var{A})
28 ## Return the page-wise complex conjugate transpose of the N-dimensional array
29 ## @var{A}.
30 ##
31 ## This is equivalent to @tcode{@var{A}(:,:, @var{k})'} for each page @var{k}.
32 ##
33 ## @seealso{pagetranspose, ctranspose, permute}
34 ## @end deftypefn
35
36 function B = pagectranspose (A)
37
38 if (nargin != 1)
39 print_usage ();
40 endif
41
42 B = permute (conj (A), [2, 1, 3:ndims(A)]);
43
44 endfunction
45
46
47 %!test
48 %! A = reshape (1:8, [2, 2, 2]);
49 %! B = pagectranspose (A);
50 %! assert (B, cat (3, [1,2;3,4], [5,6;7,8]));
51
52 %!test
53 %! A = reshape ((1:8)*i, [2, 2, 2]);
54 %! B = pagectranspose (A);
55 %! assert (B, -i * cat (3, [1,2;3,4], [5,6;7,8]));
56
57 ## Test input validation
58 %!error <Invalid call> pagectranspose ()