Skip to content

Commit

Permalink
Allow to pass NULL for the boolean[], int[], float[] and double[] par…
Browse files Browse the repository at this point in the history
…ameters (#18)


Co-authored-by: Jonathan Schilling <[email protected]>
  • Loading branch information
luhenry and jonathanschilling authored Aug 19, 2022
1 parent c63517f commit b8384e0
Show file tree
Hide file tree
Showing 47 changed files with 6,004 additions and 4,265 deletions.
584 changes: 292 additions & 292 deletions arpack/src/main/native/jni.c

Large diffs are not rendered by default.

430 changes: 215 additions & 215 deletions blas/src/main/native/jni.c

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,45 +168,45 @@ def __init__(self, name):
self.name = name
self.native_type_and_name = "int *{name}".format(name=name)
self.java_type_and_name = [a.format(name=name) for a in ["jbooleanArray {name}", "jint offset{name}"]]
self.native_argument = "__n{name} + offset{name}".format(name=name)
self.native_argument = "__n{name} ? __n{name} + offset{name} : NULL".format(name=name)
self.native_local = "int *__n{name} = NULL; jboolean *__j{name} = NULL;".format(name=name)
self.prolog = """if (!(__j{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }}
self.prolog = """if ({name}) {{ if (!(__j{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }}
do {{
int __length = (*env)->GetArrayLength(env, {name});
if (__length <= 0) {{ __failed = TRUE; goto done; }}
if (!(__n{name} = malloc(sizeof(int) * __length))) {{ __failed = TRUE; goto done; }}
for (int i = 0; i < __length; i++) {{ __n{name}[i] = __j{name}[i]; }}
}} while(0);""".format(name=name)
}} while(0); }}""".format(name=name)
self.epilog = "if (__n{name}) {{ free(__n{name}); }} if (__j{name}) (*env)->ReleasePrimitiveArrayCritical(env, {name}, __n{name}, JNI_ABORT);".format(name=name)
class JIntArray:
def __init__(self, name, mode = "0"):
self.idx = 1
self.name = name
self.native_type_and_name = "int *{name}".format(name=name)
self.java_type_and_name = [a.format(name=name) for a in ["jintArray {name}", "jint offset{name}"]]
self.native_argument = "__n{name} + offset{name}".format(name=name)
self.native_argument = "__n{name} ? __n{name} + offset{name} : NULL".format(name=name)
self.native_local = "int *__n{name} = NULL;".format(name=name)
self.prolog = "if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }}".format(name=name)
self.prolog = "if ({name}) {{ if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }} }}".format(name=name)
self.epilog = "if (__n{name}) (*env)->ReleasePrimitiveArrayCritical(env, {name}, __n{name}, {mode});".format(name=name, mode=("JNI_ABORT" if mode == "JNI_ABORT" else ("__failed ? JNI_ABORT : %s" % mode)))
class JFloatArray:
def __init__(self, name, mode = "0"):
self.idx = 1
self.name = name
self.native_type_and_name = "float *{name}".format(name=name)
self.java_type_and_name = [a.format(name=name) for a in ["jfloatArray {name}", "jint offset{name}"]]
self.native_argument = "__n{name} + offset{name}".format(name=name)
self.native_argument = "__n{name} ? __n{name} + offset{name} : NULL".format(name=name)
self.native_local = "float *__n{name} = NULL;".format(name=name)
self.prolog = "if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }}".format(name=name)
self.prolog = "if ({name}) {{ if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }} }}".format(name=name)
self.epilog = "if (__n{name}) (*env)->ReleasePrimitiveArrayCritical(env, {name}, __n{name}, {mode});".format(name=name, mode=("JNI_ABORT" if mode == "JNI_ABORT" else ("__failed ? JNI_ABORT : %s" % mode)))
class JDoubleArray:
def __init__(self, name, mode = "0"):
self.idx = 1
self.name = name
self.native_type_and_name = "double *{name}".format(name=name)
self.java_type_and_name = [a.format(name=name) for a in ["jdoubleArray {name}", "jint offset{name}"]]
self.native_argument = "__n{name} + offset{name}".format(name=name)
self.native_argument = "__n{name} ? __n{name} + offset{name} : NULL".format(name=name)
self.native_local = "double *__n{name} = NULL;".format(name=name)
self.prolog = "if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }}".format(name=name)
self.prolog = "if ({name}) {{ if (!(__n{name} = (*env)->GetPrimitiveArrayCritical(env, {name}, NULL))) {{ __failed = TRUE; goto done; }} }}".format(name=name)
self.epilog = "if (__n{name}) (*env)->ReleasePrimitiveArrayCritical(env, {name}, __n{name}, {mode});".format(name=name, mode=("JNI_ABORT" if mode == "JNI_ABORT" else ("__failed ? JNI_ABORT : %s" % mode)))

class RoutineR:
Expand Down
7,498 changes: 3,749 additions & 3,749 deletions lapack/src/main/native/jni.c

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DisnanTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class DisnanTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DlaisnanTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class DlaisnanTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/Dlamc3Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class Dlamc3Test extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DlamchTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class DlamchTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DlanegTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class DlanegTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
40 changes: 40 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DlangbTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

public class DlangbTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}
}
59 changes: 59 additions & 0 deletions lapack/src/test/java/dev/ludovic/netlib/lapack/DlangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020, 2022, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Please contact [email protected] or visit ludovic.dev if you need additional
* information or have any questions.
*/

package dev.ludovic.netlib.lapack;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Random;

public class DlangeTest extends LAPACKTest {

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testSanity(LAPACK lapack) {
org.junit.jupiter.api.Assumptions.assumeTrue(false);
}

@ParameterizedTest
@MethodSource("LAPACKImplementations")
void testNullWorkspace(LAPACK lapack) {
int n = 13;
double[] greensFunction = new double[n * n];

// some predictable test data
Random rnd = new Random(42);
for (int i = 0; i < n * n; ++i) {
greensFunction[i] = rnd.nextDouble();
}

double[] w = null;

assertEquals(8.347588916043293, lapack.dlange("1", n, n, greensFunction, n, w), depsilon);
}
}
Loading

0 comments on commit b8384e0

Please sign in to comment.