SpM Handbook 1.2.4
Loading...
Searching...
No Matches
spm_driver.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3 @file spm_driver.py
4
5 @brief SpM example to generate a sparse matrix from the spm drivers
6
7 @copyright 2017-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 Univ. Bordeaux. All rights reserved.
9
10 @version 1.2.4
11 @author Pierre Ramet
12 @author Mathieu Faverge
13 @author Tony Delarue
14 @author Alycia Lisito
15 @date 2024-05-29
16
17 @ingroup examples_python
18 @code
19
20 @endcode
21"""
22
23##\cond
24import spm
25import numpy as np
26
27# Hack to make sure that the mkl is loaded
28tmp = np.eye(2).dot(np.ones(2))
29
30# Load a sparse matrix from the Laplacian driver
31A = spm.spmatrix( driver=spm.driver.Laplacian, filename="10:10:10:2.:1." )
32
33# Example from a HB file
34#A = spm( driver=driver.HB, filename="$SPM_DIR/test/matrix/orsirr.rua" )
35
36A.printInfo()
37
38# Scale A for low-rank: A / ||A||_f
39norm = A.norm()
40A.scale( 1. / norm )
41
42# Generate b and x0 vectors such that A * x0 = b
43nrhs = 10
44x0, b = A.genRHS( spm.rhstype.RndX, nrhs, True )
45
46# Check that A * x = b
47A.checkAxb( None, b, x0 )
48##\endcond