Files
TheRock/rocm-libraries/projects/rocsolver/scripts/spdata/genmat_posdef.m
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

110 lines
2.6 KiB
Matlab

% ********************************************************************
% Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
% ********************************************************************
function genmat_posdef(n,nz)
%{
-----------------------------------------------------------
This function generates all the files required for a
test case of the Cholesky re-factorization functionality in rocSOLVER.
genmat_gen(n, nz)
Inputs:
n Size of the problem (number of row and columns
of the sparse positive-definite matrix A)
nz Max number of non-zero elements in A
Outputs:
isok This will be -1 if any of the files could not
be generated
The resulting files are created in the working directory.
See printall.m for more details.
(This script is for internal use only. It is not part of
rocSOLVER library interface and could change or be removed
without any notice)
-----------------------------------------------------------
%}
%---------------------------
% generate random sparse matrix
% with nz non-zero elements
%---------------------------
per = nz / (n*n);
A = sprand(n, n, per);
%---------------------------
% Take lower part L and make it diagonally dominant
% (this means that the symmetric matrix L+L^T will be
% positive definite)
%---------------------------
A=tril(A);
A = fixmat(A, n/2);
%---------------------------
% If necessary, remove extra non-zero elements
% so that the final symmetric matrix has no more
% than nz non-zero elements
%---------------------------
nzsym = (nz + n) / 2;
dif = nnz(A) - nzsym;
if(dif > 0),
A = cleanmat(A, dif);
end;
%---------------------------
% compute the final symmetric matrix
% (functions work with only the lower part, but better
% to have a full symmetric to generate the linear systems)
%---------------------------
A = A + transpose(A);
%---------------------------
% Compute Cholesky factorization
%---------------------------
[T, p, Q] = chol(A, 'vector', 'lower');
%---------------------------
% Generate output files
%---------------------------
disp('')
disp('Generating files...')
isok = printall("po", A, T, Q);
if (isok),
disp('OK')
disp('')
else
disp('FAILURE!');
disp('')
end;
%------------------------
% quick validation
%------------------------
ptr = dlmread('ptrT');
ind = dlmread('indT');
val = dlmread('valT');
t = csr2full(n, ptr, ind, val);
qq = dlmread('Q') + 1;
q = eye(n,n);
q = q(:,qq);
disp('Quick checking:')
b = dlmread('B_1');
x = dlmread('X_1');
err1 = norm(q*t*t'*q'*x-b, "fro")
b = dlmread('B_10');
x = dlmread('X_10');
err2 = norm(q*t*t'*q'*x-b, "fro")
b = dlmread('B_30');
x = dlmread('X_30');
err3 = norm(q*t*t'*q'*x-b, "fro")
disp('')
end