8000 removed old nlpy dependencies. · PythonOptimizers/HSL.py@3ca0ead · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ca0ead

Browse files
committed
removed old nlpy dependencies.
1 parent aa2c337 commit 3ca0ead

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

examples/demo_sils.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# from hsl.solvers.pyma27 import PyMa27Solver as LBLContext
77
from hsl.solvers.pyma57 import PyMa57Solver as LBLContext
88
from pysparse import spmatrix
9-
from nlpy.tools import norms
10-
from nlpy.tools.timing import cputime
11-
import numpy
9+
from numpy.linalg import norm
10+
import timeit
11+
import numpy as np
1212

1313

1414
def Hilbert(n):
@@ -43,7 +43,7 @@ def Ma27SpecSheet():
4343
A[4, 1] = 6
4444
A[4, 4] = 1
4545

46-
rhs = numpy.ones(5, 'd')
46+
rhs = np.ones(5, 'd')
4747
rhs[0] = 8
4848
rhs[1] = 45
4949
rhs[2] = 31
@@ -56,22 +56,22 @@ def Ma27SpecSheet():
5656
def solve_system(A, rhs, itref_threshold=1.0e-6, nitrefmax=5, **kwargs):
5757

5858
# Obtain Sils context object
59-
t = cputime()
59+
t = timeit.default_timer()
6060
LBL = LBLContext(A, **kwargs)
61-
t_analyze = cputime() - t
61+
t_analyze = timeit.default_timer() - t
6262

6363
# Solve system and compute residual
64-
t = cputime()
64+
t = timeit.default_timer()
6565
LBL.solve(rhs)
66-
t_solve = cputime() - t_analyze
66+
t_solve = timeit.default_timer() - t
6767

6868
# Compute residual norm
69-
nrhsp1 = norms.norm_infty(rhs) + 1
70-
nr = norms.norm2(LBL.residual) / nrhsp1
69+
nrhsp1 = norm(rhs, ord=np.infty) + 1
70+
nr = norm(LBL.residual) / nrhsp1
7171

7272
# If residual not small, perform iterative refinement
7373
LBL.refine(rhs, tol=itref_threshold, nitref=nitrefmax)
74-
nr1 = norms.norm_infty(LBL.residual) / nrhsp1
74+
nr1 = norm(LBL.residual, ord=np.infty) / nrhsp1
7575

7676
return (LBL.x, LBL.residual, nr, nr1, t_analyze, t_solve, LBL.neig)
7777

@@ -93,33 +93,35 @@ def solve_system(A, rhs, itref_threshold=1.0e-6, nitrefmax=5, **kwargs):
9393
# Solve example from the spec sheet
9494
(A, rhs) = Ma27SpecSheet()
9595
(x, r, nr, nr1, t_an, t_sl, neig) = solve_system(A, rhs)
96-
exact = numpy.arange(5, dtype='d') + 1
97-
relres = norms.norm2(x - exact) / norms.norm2(exact)
98-
sys.stdout.write(res_fmt, 'Spec sheet', relres, nr, nr1, t_an, t_sl, neig)
96+
exact = np.arange(5, dtype='d') + 1
97+
relres = norm(x - exact) / norm(exact)
98+
sys.stdout.write(res_fmt %
99+
('Spec sheet', relres, nr, nr1, t_an, t_sl, neig))
99100

100101
# Solve example with Hilbert matrix
101102
n = 10
102103
H = Hilbert(n)
103-
e = numpy.ones(n, 'd')
104-
rhs = numpy.empty(n, 'd')
104+
e = np.ones(n, 'd')
105+
rhs = np.empty(n, 'd')
105106
H.matvec(e, rhs)
106107
(x, r, nr, nr1, t_an, t_sl, neig) = solve_system(H, rhs)
107-
relres = norms.norm2(x - e) / norms.norm2(e)
108-
sys.stdout.write(res_fmt, 'Hilbert', relres, nr, nr1, t_an, t_sl, neig)
108+
relres = norm(x - e) / norm(e)
109+
sys.stdout.write(res_fmt % ('Hilbert', relres, nr, nr1, t_an, t_sl, neig))
109110

110111
# Process matrices given on the command line
111112
for matrix in matrices:
112113
M = spmatrix.ll_mat_from_mtx(matrix)
113114
(m, n) = M.shape
114115
if m != n:
115116
break
116-
e = numpy.ones(n, 'd')
117-
rhs = numpy.empty(n, 'd')
117+
e = np.ones(n, 'd')
118+
rhs = np.empty(n, 'd')
118119
M.matvec(e, rhs)
119120
(x, r, nr, nr1, t_an, t_sl, neig) = solve_system(M, rhs)
120-
relres = norms.norm2(x - e) / norms.norm2(e)
121+
relres = norm(x - e) / norm(e)
121122
probname = os.path.basename(matrix)
122123
if probname[-4:] == '.mtx':
123124
probname = probname[:-4]
124-
sys.stdout.write(res_fmt, probname, relres, nr, nr1, t_an, t_sl, neig)
125+
sys.stdout.write(res_fmt %
126+
(probname, relres, nr, nr1, t_an, t_sl, neig))
125127
sys.stderr.write('-' * lhead + '\n')

hsl/solvers/pyma27.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ def __init__(self, A, **kwargs):
4949
(default: False)
5050
5151
Example:
52-
from nlpy.linalg import pyma27
53-
from nlpy.tools import norms
54-
P = pyma27.PyMa27Solver(A)
55-
P.solve(rhs, get_resid = True)
56-
print norms.norm2(P.residual)
5752
58-
Pyma27 relies on the sparse direct multifrontal code MA27
53+
>>>> from hsl.solvers import pyma27
54+
>>>> from numpy.linalg import norm
55+
>>>> P = pyma27.PyMa27Solver(A)
56+
>>>> P.solve(rhs, get_resid = True)
57+
>>>> print norm(P.residual)
58+
59+
PyMa27 relies on the sparse direct multifrontal code MA27
5960
from the Harwell Subroutine Library archive.
6061
"""
6162

hsl/solvers/pyma57.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def __init__(self, A, factorize=True, **kwargs):
4646
4747
Example:
4848
49-
>>> import pyma57
50-
>>> import numpy
49+
>>> from hsl.solvers import pyma57
50+
>>> from numpy.linalg import norm
5151
>>> P = pyma57.PyMa57Solver(A)
5252
>>> P.solve(rhs, get_resid=True)
53-
>>> print numpy.linalg.norm(P.residual)
53+
>>> print norm(P.residual)
5454
5555
PyMa57Solver relies on the sparse direct multifrontal code MA57
5656
from the Harwell Subroutine Library.

hsl/solvers/src/hsl_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
22
#include <stdio.h>
3-
#include "nlpy.h"
3+
#include "hslpy.h"
44

55
#ifdef __FUNCT__
66
#undef __FUNCT__
File renamed without changes.

include/ma27.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* ============================================
1010
*/
1111

12-
#include "nlpy.h"
12+
#include "hslpy.h"
1313

1414
#define LOGMSG(...) if (ma27->logfile) fprintf(ma27->logfile, __VA_ARGS__);
1515

include/ma57.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* ============================================
1010
*/
1111

12-
#include "nlpy.h"
12+
#include "hslpy.h"
1313

1414
#define LOGMSG(...) if (ma57->logfile) fprintf(ma57->logfile, __VA_ARGS__)
1515

0 commit comments

Comments
 (0)
0