File: save.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 (54 lines) | stat: -rw-r--r-- 1,839 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
function filename_used = save (C, filename)
%GRB.SAVE Save a single GraphBLAS matrix to a file.
% GrB.save (C) saves a single @GrB or built-in matrix C to a file, with a
% filename of 'C.mat' that matches the matrix name.  If C is an
% expression, the filename 'GrB_Matrix.mat' is used.  A second parameter
% allows for the selection of a different filename, as GrB.save (C,
% 'myfile.mat').  If A is not already a @GrB matrix, it is converted to
% one with GrB(A).
%
% The object or matrix C is saved as a struct containing the opaque
% contents of the GrB object, which is then reconstructed by GrB.load.  A
% matrix saved to a file with GrB.save must be loaded back with GrB.load.
% It cannot be loaded with the built-in load method.
%
% Example:
%
%   A = magic (4) ;
%   GrB.save (A) ;              % A can be a @GrB or built-in matrix
%   clear all
%   A = GrB.load ('A.mat') ;    % A is now a @GrB matrix
%
% See also GrB.load, GrB/struct, GrB.serialize, GrB.deserialize.

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

% make sure C is a @GrB object
if (~isobject (C))
    C = GrB (C) ;
end

% Extract the opaque contents of C as a struct.  Give it a long and peculiar
% name to help ensure it is only loaded by GrB.load.
GraphBLAS_struct_from_GrB_save = C.opaque ;

% determine the default filename
if (nargin < 2)
    filename = inputname (1) ;
    if (isempty (filename))
        % inputname returns an empty string if the input argument C
        % is an expression that has no name
        filename = 'GrB_Matrix' ;
    end
    filename = [filename '.mat'] ;
end

% save the struct (not the @GrB matrix C) to the file. 
save (filename, 'GraphBLAS_struct_from_GrB_save') ;

% return the chosen filename
if (nargout > 0)
    filename_used = filename ;
end