File: gb_index.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (84 lines) | stat: -rw-r--r-- 2,606 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function [I, whole] = gb_index (I)
%GB_INDEX helper function for subsref and subsasgn
% [I, whole] = gb_index (I) converts I into a cell array of built-in
% matrices or vectors containing integer indices, to access A(I).
%
%   I = { }: this denotes A(:), accessing all rows or all columns.
%       In this case, the parameter whole is returned as true.
%
%   I = { list }: denotes A(list)
%
%   I = { start,fini }: denotes A(start:fini), without forming
%       the explicit list start:fini.
%
%   I = { start,inc,fini }: denotes A(start:inc:fini), without forming
%       the explicit list start:inc:fini.
%
% The input I can be a GraphBLAS matrix (as an object or its opaque
% struct).  In this case, it is wrapped in a cell, I = {gb_index1(I)},
% but kept as 1-based indices (they are later translated to 0-based).
%
% If the input is already a cell array, then it is already in one of the
% above forms.  Any member of the cell array that is a GraphBLAS matrix or
% struct is converted into an index list, with gb_index1(I{k}).
%
% The subsref and subsasgn methods are passed the string I = ':'.  This is
% converted into I = { }.
%
% If I is a built-in matrix or vector (not a cell array), then it is
% wrapped in a cell array, { I }, to denote A(I).

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

whole = false ;

if (isobject (I))

    % C (I) where I is a GraphBLAS matrix/vector of integer indices
    I = I.opaque ;
    I = { (gb_index1 (I)) } ;

elseif (isstruct (I))

    % C (I) where I is the opaque struct of a GrB matrix/vector
    I = { (gb_index1 (I)) } ;

elseif (iscell (I))

    % The index I already appears as a cell, for the usage
    % C ({ }), C ({ I }), C ({start,fini}), or C ({start,inc,fini}).
    len = length (I) ;
    if (len > 3)
        error ('GrB:error', 'invalid indexing: usage is A ({start,inc,fini})') ;
    elseif (len == 0)
        % C ({ })
        whole = true ;
    else
        % C ({ I }), C ({start,fini}), or C ({start,inc,fini})
        for k = 1:length(I)
            K = I {k} ;
            if (isobject (K))
                % C ({ ..., K, ... }) where K is a GraphBLAS object
                K = K.opaque ;
            end
            if (isstruct (K))
                % C ({ ..., K, ... }) where I is a GraphBLAS struct
                I {k} = gb_index1 (K) ;
            end
        end
    end

elseif (ischar (I) && isequal (I, ':'))

    % C (:)
    I = { } ;
    whole = true ;

else

    % C (I) where I is a built-in matrix/vector of integer indices
    I = { I } ;

end