Skip to content

Commit

Permalink
expand testing
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
  • Loading branch information
jabraham17 committed Feb 3, 2025
1 parent 3916bab commit 7de01ba
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 4 deletions.
4 changes: 4 additions & 0 deletions test/library/packages/Python/correctness/arrays/PRETEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

FILE_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)
$FILE_DIR/../../skipIfAndInstallPackage.sh $FILE_DIR numpy &> /dev/null
20 changes: 20 additions & 0 deletions test/library/packages/Python/correctness/arrays/SUPPRESSIF
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# tests require numpy

# respect CHPL_TEST_VENV_DIR if it is set and not none
if [ -n "$CHPL_TEST_VENV_DIR" ] && [ "$CHPL_TEST_VENV_DIR" != "none" ]; then
chpl_python=$CHPL_TEST_VENV_DIR/bin/python3
else
chpl_python=$($CHPL_HOME/util/config/find-python.sh)
fi

FILE_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)
export PYTHONPATH=$FILE_DIR/python_libs:$PYTHONPATH

# try and import numpy
if ! $chpl_python -c "import numpy" &>/dev/null; then
echo "True"
else
echo "False"
fi
48 changes: 48 additions & 0 deletions test/library/packages/Python/correctness/arrays/gradient.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use Python;


var code = """
import numpy as np
def gradModifyArg(arr, res):
arr_np = np.asarray(arr)
res_np = np.asarray(res)
res_np[:] = np.gradient(arr_np)
def grad(arr):
x = np.asarray(arr)
return np.gradient(x)
""";

proc main() {
var interp = new Interpreter();
var mod = new Module(interp, '__empty__', code);
var gradModifyArg = new Function(mod, 'gradModifyArg');
var grad = new Function(mod, 'grad');

var arr = [1, 2, 4, 7, 11, 16];
var pyArr = new Array(interp, arr);


var res: [arr.domain] real;
{
var pyRes = new Array(interp, res);
gradModifyArg(NoneType, pyArr, pyRes);
}
write("gradModifyArg: ", res);
write(" dom: ", res.domain);
writeln(" eltType: ", res.eltType:string);

res = 0.0;

{
var pyRes = grad(owned PyArray(real), pyArr);
res = pyRes.array;
}
write("grad: ", res);
write(" dom: ", res.domain);
writeln(" eltType: ", res.eltType:string);
}
2 changes: 2 additions & 0 deletions test/library/packages/Python/correctness/arrays/gradient.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gradModifyArg: 1.0 1.5 2.5 3.5 4.5 5.0 dom: {0..5} eltType: real(64)
grad: 1.0 1.5 2.5 3.5 4.5 5.0 dom: {0..5} eltType: real(64)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use Python;

proc main() {
var interp = new Interpreter();
var mod = new Module(interp, "usePythonArray");
var doit = new Function(mod, 'doit');


var pyRes = doit(owned PyArray(int), 10, 11, 12, 13);
var res = pyRes.array;
write("arr: ", res);
write(" dom: ", res.domain);
writeln(" eltType: ", res.eltType:string);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arr: 10 11 12 13 dom: {0..3} eltType: int(64)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import array

def doit(*args):
a = array.array('l', args)
return a

0 comments on commit 7de01ba

Please sign in to comment.