SpM Handbook 1.2.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spm_scipy.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3 @file spm_scipy.py
4
5 @brief SpM example to generate a sparse matrix from Scipy to SPM
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 scipy.sparse as sps
26import numpy as np
27
28# Hack to make sure that the mkl is loaded
29tmp = np.eye(2).dot(np.ones(2))
30
31# Set the problem
32n = 9
33A = sps.spdiags([np.ones(n)*i for i in [4, -1, -1, -1, -1]],
34 [0, 1, 3, -1, -3], n, n)
35x = np.arange(n)
36b = np.zeros(n)
37
38spmA = spm.spmatrix( A )
39
40# b <= A * x
41spmA.mult( x, b, trans=spm.trans.NoTrans, alpha=1., beta=0. )
42
43# Use the solver check to check that A * x == b
44spmA.checkAxb( None, b, x )
45##\endcond