Skip to content

Commit 5f53d18

Browse files
committed
Slightly modified to test the latest DL_PY2F
1 parent 389aef1 commit 5f53d18

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

example/callback.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . import example_dirs
2+
from time import time
23

34
def callback(*args) -> int:
45
'''Callback function for DL_FIND'''
@@ -23,8 +24,6 @@ def callback(*args) -> int:
2324
# we could even run more Python methods
2425
callback.obj.doSomething()
2526

26-
27-
2827
##################################################################
2928
# PART 2 (optional): Fortran-to-Python
3029
# NB: currently this only works with gfortran!
@@ -104,6 +103,7 @@ def callback(*args) -> int:
104103
# `real(kind=8) , dimension(-4:9,2:19) :: rarr03 = 3D0`
105104
print(" >>> callback (Py): libexample.modules.yourmodule.var_of_t04.rarr03.shape =\n"+" "*19,
106105
libexample.modules.yourmodule.var_of_t04.rarr03.shape)
106+
# in Python we cannot use customised indices (l-/ubounds) as rarr03 is declared
107107
print(" >>> callback (Py): libexample.yourmodule.arr03_of_int =\n"+" "*19,
108108
libexample.modules.yourmodule.arr03_of_int)
109109

@@ -233,4 +233,28 @@ def callback(*args) -> int:
233233
var_of_t04.rarr21[i] = float(i+1)
234234

235235

236+
# we support PDE-style slicing
237+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[:,2], ivar04 =")
238+
for a in var_of_t04.t2ar02[:,2]:
239+
print(a.ivar04, end=' ')
240+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[1:5,:], ivar04 =")
241+
for a in var_of_t04.t2ar02[1:5,:]:
242+
print(a.ivar04, end=' ')
243+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[::2,::2], ivar04 =")
244+
for a in var_of_t04.t2ar02[::2,::2]:
245+
print(a.ivar04, end=' ')
246+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[...,1], ivar04 =")
247+
for a in var_of_t04.t2ar02[...,1]:
248+
print(a.ivar04, end=' ')
249+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[1,:,2], ivar04 =")
250+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[-2:-1,:-2], ivar04 =")
251+
for a in var_of_t04.t2ar02[-2:-1,-2]:
252+
print(a.ivar04, end=' ')
253+
print("\n >>> callback (Py): scanning along var_of_t04.t2ar02[::-1,0], ivar04 =")
254+
for a in var_of_t04.t2ar02[::-1,0]:
255+
print(a.ivar04, end=' ')
256+
print("\n >>> callback (Py): shape of var_of_t04.t2ar02[:,None,:] =")
257+
print(var_of_t04.t2ar02[:,None,:].shape)
258+
print('', flush=True)
259+
236260
return 0

0 commit comments

Comments
 (0)