Skip to content

Commit c7d2a01

Browse files
authored
Add allowNative system properties as switch (#28)
1 parent 519b2ca commit c7d2a01

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea/
12
**/target
23
**/.classpath
34
**/.project

arpack/src/main/java/dev/ludovic/netlib/arpack/ARPACK.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
public interface ARPACK {
2929

30+
public static final String ALLOW_NATIVE_ARPACK = "dev.ludovic.netlib.arpack.allowNative";
31+
3032
public static ARPACK getInstance() {
3133
return InstanceBuilder.arpack();
3234
}

arpack/src/main/java/dev/ludovic/netlib/arpack/InstanceBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ final class InstanceBuilder {
3737
private static final JavaARPACK javaArpack;
3838

3939
static {
40-
nativeArpack = initializeNative();
40+
String allowNativeArpack = System.getProperty(ARPACK.ALLOW_NATIVE_ARPACK, "true");
41+
if (Boolean.parseBoolean(allowNativeArpack)) {
42+
nativeArpack = initializeNative();
43+
} else {
44+
log.info("Skip trying to load native BLAS implementation because system property " +
45+
ARPACK.ALLOW_NATIVE_ARPACK + " is " + allowNativeArpack);
46+
nativeArpack = null;
47+
}
4148
javaArpack = initializeJava();
4249
arpack = nativeArpack != null ? nativeArpack : javaArpack;
4350

@@ -52,7 +59,7 @@ private static NativeARPACK initializeNative() {
5259
try {
5360
return JNIARPACK.getInstance();
5461
} catch (Throwable t) {
55-
log.log(Level.FINE, "Failed to load implementation from:" + JNIARPACK.class.getName(), t);
62+
log.log(Level.FINE, "Failed to load implementation from: " + JNIARPACK.class.getName(), t);
5663
return null;
5764
}
5865
}

blas/src/main/java/dev/ludovic/netlib/blas/BLAS.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
public interface BLAS {
2929

30+
public static final String ALLOW_NATIVE_BLAS = "dev.ludovic.netlib.blas.allowNative";
31+
3032
public static BLAS getInstance() {
3133
return InstanceBuilder.blas();
3234
}

blas/src/main/java/dev/ludovic/netlib/blas/InstanceBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ final class InstanceBuilder {
3737
private static final JavaBLAS javaBlas;
3838

3939
static {
40-
nativeBlas = initializeNative();
40+
String allowNativeBlas = System.getProperty(BLAS.ALLOW_NATIVE_BLAS, "true");
41+
if (Boolean.parseBoolean(allowNativeBlas)) {
42+
nativeBlas = initializeNative();
43+
} else {
44+
log.info("Skip trying to load native BLAS implementation because system property " +
45+
BLAS.ALLOW_NATIVE_BLAS + " is " + allowNativeBlas);
46+
nativeBlas = null;
47+
}
4148
javaBlas = initializeJava();
4249
blas = nativeBlas != null ? nativeBlas : javaBlas;
4350

@@ -52,7 +59,7 @@ private static NativeBLAS initializeNative() {
5259
try {
5360
return JNIBLAS.getInstance();
5461
} catch (Throwable t) {
55-
log.log(Level.FINE, "Failed to load implementation from:" + JNIBLAS.class.getName(), t);
62+
log.log(Level.FINE, "Failed to load implementation from: " + JNIBLAS.class.getName(), t);
5663
return null;
5764
}
5865
}

lapack/src/main/java/dev/ludovic/netlib/lapack/InstanceBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ final class InstanceBuilder {
3737
private static final JavaLAPACK javaLapack;
3838

3939
static {
40-
nativeLapack = initializeNative();
40+
String allowNativeLapack = System.getProperty(LAPACK.ALLOW_NATIVE_LAPACK, "true");
41+
if (Boolean.parseBoolean(allowNativeLapack)) {
42+
nativeLapack = initializeNative();
43+
} else {
44+
log.info("Skip trying to load native LAPACK implementation because system property " +
45+
LAPACK.ALLOW_NATIVE_LAPACK + " is " + allowNativeLapack);
46+
nativeLapack = null;
47+
}
4148
javaLapack = initializeJava();
4249
lapack = nativeLapack != null ? nativeLapack : javaLapack;
4350

@@ -52,7 +59,7 @@ private static NativeLAPACK initializeNative() {
5259
try {
5360
return JNILAPACK.getInstance();
5461
} catch (Throwable t) {
55-
log.log(Level.FINE, "Failed to load implementation from:" + JNILAPACK.class.getName(), t);
62+
log.log(Level.FINE, "Failed to load implementation from: " + JNILAPACK.class.getName(), t);
5663
return null;
5764
}
5865
}

lapack/src/main/java/dev/ludovic/netlib/lapack/LAPACK.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
public interface LAPACK {
2929

30+
public static final String ALLOW_NATIVE_LAPACK = "dev.ludovic.netlib.lapack.allowNative";
31+
3032
public static LAPACK getInstance() {
3133
return InstanceBuilder.lapack();
3234
}

0 commit comments

Comments
 (0)