SpM Handbook
1.2.4
Toggle main menu visibility
Main Page
Topics
Data Types
Data Types List
Data Type Index
Data Fields
All
Variables
Files
File List
Globals
All
_
c
d
g
l
p
r
s
t
v
w
z
Functions/Subroutines
_
c
d
g
l
p
r
s
w
z
Variables
Typedefs
_
s
Enumerations
Enumerator
s
Macros
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
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
24
import
spm
25
import
scipy.sparse
as
sps
26
import
numpy
as
np
27
28
# Hack to make sure that the mkl is loaded
29
tmp = np.eye(2).dot(np.ones(2))
30
31
# Set the problem
32
n = 9
33
A = sps.spdiags([np.ones(n)*i
for
i
in
[4, -1, -1, -1, -1]],
34
[0, 1, 3, -1, -3], n, n)
35
x = np.arange(n)
36
b = np.zeros(n)
37
38
spmA = spm.spmatrix( A )
39
40
# b <= A * x
41
spmA.mult( x, b, trans=spm.trans.NoTrans, alpha=1., beta=0. )
42
43
# Use the solver check to check that A * x == b
44
spmA.checkAxb(
None
, b, x )
45
##\endcond
wrappers
python
spm_scipy.py
Generated by
1.9.8