Skip to content

Commit 5d4127f

Browse files
committed
UMFPACK: add octave support
1 parent 31f2a24 commit 5d4127f

File tree

3 files changed

+75
-21
lines changed

3 files changed

+75
-21
lines changed

UMFPACK/MATLAB/umfpack_make.m

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@
1818
% UMFPACK, Copyright (c) 2005-2022, Timothy A. Davis, All Rights Reserved.
1919
% SPDX-License-Identifier: GPL-2.0+
2020

21+
have_octave = (exist ('OCTAVE_VERSION', 'builtin') == 5) ;
22+
2123
metis_path = '../../CHOLMOD/SuiteSparse_metis' ;
2224
with_cholmod = exist (metis_path, 'dir') ;
2325

2426
details = 0 ; % set to 1 to print out each mex command as it's executed
2527

2628
flags = '' ;
2729
is64 = ~isempty (strfind (computer, '64')) ;
28-
if (is64)
30+
if (is64 && ~have_octave)
2931
flags = ' -largeArrayDims' ;
3032
end
3133

32-
% MATLAB 8.3.0 now has a -silent option to keep 'mex' from burbling too much
33-
if (~verLessThan ('matlab', '8.3.0'))
34+
if (have_octave)
35+
flags = ['--silent', flags] ;
36+
elseif (~verLessThan ('matlab', '8.3.0'))
37+
% MATLAB 8.3.0 now has a -silent option to keep 'mex' from burbling too much
3438
flags = ['-silent ' flags] ;
3539
end
3640

@@ -41,7 +45,11 @@
4145

4246
v = version ;
4347

44-
fprintf ('Compiling UMFPACK for MATLAB Version %s\n', v) ;
48+
if (have_octave)
49+
fprintf ('Compiling UMFPACK for Octave Version %s\n', v) ;
50+
else
51+
fprintf ('Compiling UMFPACK for MATLAB Version %s\n', v) ;
52+
end
4553

4654
if (ispc)
4755
obj = 'obj' ;
@@ -57,41 +65,63 @@
5765

5866
% This is exceedingly ugly. The MATLAB mex command needs to be told where to
5967
% find the LAPACK and BLAS libraries, which is a real portability nightmare.
60-
6168
if (ispc)
6269
% BLAS/LAPACK functions have no underscore on Windows
6370
flags = [flags ' -DBLAS_NO_UNDERSCORE'] ;
64-
if (verLessThan ('matlab', '7.5'))
65-
lapack = 'libmwlapack.lib' ;
66-
elseif (verLessThan ('matlab', '9.5'))
67-
lapack = 'libmwlapack.lib libmwblas.lib' ;
71+
72+
if (have_octave)
73+
lapack = '-llapack -lblas' ;
6874
else
69-
lapack = '-lmwlapack -lmwblas' ;
75+
if (verLessThan ('matlab', '7.5'))
76+
lapack = 'libmwlapack.lib' ;
77+
elseif (verLessThan ('matlab', '9.5'))
78+
lapack = 'libmwlapack.lib libmwblas.lib' ;
79+
else
80+
lapack = '-lmwlapack -lmwblas' ;
81+
end
7082
end
83+
7184
else
7285
% BLAS/LAPACK functions have an underscore suffix
7386
flags = [flags ' -DBLAS_UNDERSCORE'] ;
74-
if (verLessThan ('matlab', '7.5'))
75-
lapack = '-lmwlapack' ;
87+
88+
if (have_octave)
89+
lapack = '-llapack -lblas' ;
7690
else
77-
lapack = '-lmwlapack -lmwblas' ;
91+
if (verLessThan ('matlab', '7.5'))
92+
lapack = '-lmwlapack' ;
93+
else
94+
lapack = '-lmwlapack -lmwblas' ;
95+
end
7896
end
7997
end
8098

81-
if (is64 && ~verLessThan ('matlab', '7.8'))
82-
% versions 7.8 and later on 64-bit platforms use a 64-bit BLAS
83-
fprintf ('with 64-bit BLAS\n') ;
84-
flags = [flags ' -DBLAS64'] ;
99+
if (is64)
100+
101+
if (have_octave)
102+
fprintf ('with 64-bit BLAS\n') ;
103+
flags = [flags ' -DBLAS64'] ;
104+
elseif (~verLessThan ('matlab', '7.8'))
105+
% versions 7.8 and later on 64-bit platforms use a 64-bit BLAS
106+
fprintf ('with 64-bit BLAS\n') ;
107+
flags = [flags ' -DBLAS64'] ;
108+
else
109+
% other versions of MATLAB use a 32-bit BLAS
110+
flags = [flags ' -DBLAS32'] ;
111+
end
85112
else
86113
% other versions of MATLAB use a 32-bit BLAS
87114
flags = [flags ' -DBLAS32'] ;
88115
end
89116

117+
if (have_octave)
118+
flags = [flags ' -DOCTAVE -DNRECIPROCAL']
119+
end
120+
90121
if (~(ispc || ismac))
91122
% for POSIX timing routine
92123
lapack = [lapack ' -lrt'] ;
93124
end
94-
95125
%-------------------------------------------------------------------------------
96126
% Source and include directories
97127
%-------------------------------------------------------------------------------

UMFPACK/MATLAB/umfpack_test.m

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function umfpack_test (nmat)
99
% UMFPACK, Copyright (c) 2005-2022, Timothy A. Davis, All Rights Reserved.
1010
% SPDX-License-Identifier: GPL-2.0+
1111

12-
index = ssget ;
12+
have_octave = (exist ('OCTAVE_VERSION', 'builtin') == 5) ;
13+
14+
index = ssget('refresh') ;
1315

1416
f = find (index.nrows == index.ncols) ;
1517
[ignore, i] = sort (index.nrows (f)) ;
@@ -42,6 +44,12 @@ function umfpack_test (nmat)
4244

4345
Prob = ssget (i) ;
4446
A = Prob.A ;
47+
48+
% Octave cannot process matrices whose version is 7.3
49+
if (have_octave && ~issparse(A))
50+
continue ;
51+
end
52+
4553
n = size (A,1) ;
4654

4755
b = rand (1,n) ;
@@ -57,7 +65,19 @@ function umfpack_test (nmat)
5765
title ('A')
5866

5967
subplot (2,2,2)
60-
treeplot (Fr (1:end-1,2)') ;
68+
69+
Fr_slice = Fr(1:end-1, 2)'
70+
if (~have_octave)
71+
treeplot(Fr_slice)
72+
else
73+
% Octave don't support treeplot with empty vector
74+
if (~isempty(Fr_slice))
75+
treeplot(Fr_slice)
76+
else
77+
plot([])
78+
end
79+
end
80+
6181
title ('supercolumn etree')
6282

6383
%-----------------------------------------------------------------------

UMFPACK/MATLAB/umfpackmex.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353

5454
#include "umfpack.h"
5555
#include "mex.h"
56-
#include "matrix.h"
5756
#include <string.h>
5857
#include <math.h>
5958
#include <float.h>
59+
#include <stdio.h>
60+
61+
#ifndef OCTAVE
62+
#include "matrix.h"
63+
#endif
6064

6165
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
6266
#define MAX(a,b) (((a) > (b)) ? (a) : (b))

0 commit comments

Comments
 (0)