-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
- Loading branch information
1 parent
3916bab
commit 7de01ba
Showing
8 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
test/library/packages/Python/correctness/arrays/SUPPRESSIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
test/library/packages/Python/correctness/arrays/gradient.chpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2
test/library/packages/Python/correctness/arrays/gradient.good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
4 changes: 0 additions & 4 deletions
4
test/library/packages/Python/correctness/arrays/numpyInterop.skipif
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
test/library/packages/Python/correctness/arrays/usePythonArray.chpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
test/library/packages/Python/correctness/arrays/usePythonArray.good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
arr: 10 11 12 13 dom: {0..3} eltType: int(64) |
5 changes: 5 additions & 0 deletions
5
test/library/packages/Python/correctness/arrays/usePythonArray.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |