File: sprandsym.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 (39 lines) | stat: -rw-r--r-- 1,394 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
function C = sprandsym (arg1, arg2)
%SPRANDSYM random symmetric matrix.
% C = sprandsym (A) is a symmetric random matrix.  Its lower triangle and
%   diagonal have the same pattern as tril (A).  The values of C have a
%   normal distribution.  A must be square.  This usage is the same as
%   C = GrB.random (A, 'symmetric', 'normal').
%
% C = sprandsym (n,d) is an n-by-n symmetric random matrix with about n*n*d
%   entries, with a normal distribution.  If d == inf, C is full.  To use
%   this function instead of the built-in sprandsym, use
%   C = sprandsym (n,GrB(d)), or C = GrB.random (n,d,'symmetric','normal').
%
% For additional options, see GrB.random.
% The C = sprandsym (n,d,rc) syntax is not supported.
% C is returned as a double GraphBLAS matrix.
%
% Example:
%
%   A = sprand (1000, 1000, 0.5) ;
%   G = GrB (A) ;
%   C0 = sprandsym (A) ;                % the built-in sprandsym
%   C1 = sprandsym (G) ;                % GrB/sprandsym
%
% See also GrB/sprand, GrB/sprandn, GrB.random.

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

if (nargin == 1)
    % C = sprandsym (G)
    G = arg1.opaque ;
    C = GrB (gb_random (G, 'symmetric', 'normal')) ;
else
    % C = sprandsym (n, d)
    n = gb_get_scalar (arg1) ;
    d = gb_get_scalar (arg2) ;
    C = GrB (gb_random (n, d, 'symmetric', 'normal')) ;
end