File: flip.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 503; asm: 369; python: 125; awk: 10
file content (52 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function C = flip (A, dim)
%FLIP flip the order of elements.
% C = flip (A) flips the order of elements in each column of A.  That is,
% C = A (end:-1:1,:).  C = flip (A, dim) specifies the dimension to flip,
% so that flip (A,1) and flip (A) are the same thing, and flip (A,2) flips
% the columns so that C = A (:,end:-1,1).
%
% To use this function on a built-in matrix, use C = flip (A, GrB (dim)).
%
% See also GrB/transpose.

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

a_is_object = isobject (A) ;
if (a_is_object)
    G = A.opaque ;
else
    G = A ;
end

[m, n] = gbsize (G) ;

if (nargin == 1)
    if (m == 1)
        dim = 2 ;
    else
        dim = 1 ;
    end
else
    dim = gb_get_scalar (dim) ;
end

dim = floor (double (dim)) ;
if (dim <= 0)
    error ('GrB:error', 'dim must be positive') ;
end

if (dim == 1 && m ~= 1)
    % C = A (m:-1:1, :)
    C = GrB (gbextract (G, {m,-1,1}, { })) ;
elseif (dim == 2 && n ~= 1)
    % C = A (:, n:-1:1)
    C = GrB (gbextract (G, { }, {n,-1,1})) ;
elseif (a_is_object)
    % nothing to do
    C = A ;
else
    % nothing to do except convert A to GrB
    C = GrB (A) ;
end