summaryrefslogtreecommitdiff
path: root/doc/source/f2py/code/results
diff options
context:
space:
mode:
authorRohit Goswami <rog32@hi.is>2021-09-19 17:01:16 +0000
committerRohit Goswami <rog32@hi.is>2021-09-19 17:52:00 +0000
commit156c005422b020b6fdcd27fc39211708f84f91cb (patch)
treea07055cb48d9d70f70f388f7e539c3192e4abde3 /doc/source/f2py/code/results
parent80c28d12a4500e12b194d62107c61d37703c0f93 (diff)
downloadnumpy-156c005422b020b6fdcd27fc39211708f84f91cb.tar.gz
MAINT,DOC: Refactor, syntax highlighting for f2py
Diffstat (limited to 'doc/source/f2py/code/results')
-rw-r--r--doc/source/f2py/code/results/allocarr_session.dat32
-rw-r--r--doc/source/f2py/code/results/array_session.dat87
-rw-r--r--doc/source/f2py/code/results/calculate_session.dat6
-rw-r--r--doc/source/f2py/code/results/callback_session.dat35
-rw-r--r--doc/source/f2py/code/results/common_session.dat30
-rw-r--r--doc/source/f2py/code/results/compile_session.dat11
-rw-r--r--doc/source/f2py/code/results/extcallback_session.dat19
-rw-r--r--doc/source/f2py/code/results/ftype_session.dat21
-rw-r--r--doc/source/f2py/code/results/moddata_session.dat28
-rw-r--r--doc/source/f2py/code/results/run_main_session.dat14
-rw-r--r--doc/source/f2py/code/results/scalar_session.dat24
-rw-r--r--doc/source/f2py/code/results/spam_session.dat5
-rw-r--r--doc/source/f2py/code/results/string_session.dat30
-rw-r--r--doc/source/f2py/code/results/var_session.dat3
14 files changed, 345 insertions, 0 deletions
diff --git a/doc/source/f2py/code/results/allocarr_session.dat b/doc/source/f2py/code/results/allocarr_session.dat
new file mode 100644
index 000000000..ba168c22a
--- /dev/null
+++ b/doc/source/f2py/code/results/allocarr_session.dat
@@ -0,0 +1,32 @@
+>>> import allocarr
+>>> print(allocarr.mod.__doc__)
+b : 'f'-array(-1,-1), not allocated
+foo()
+
+Wrapper for ``foo``.
+
+
+
+>>> allocarr.mod.foo()
+ b is not allocated
+>>> allocarr.mod.b = [[1, 2, 3], [4, 5, 6]] # allocate/initialize b
+>>> allocarr.mod.foo()
+ b=[
+ 1.000000 2.000000 3.000000
+ 4.000000 5.000000 6.000000
+ ]
+>>> allocarr.mod.b # b is Fortran-contiguous
+array([[ 1., 2., 3.],
+ [ 4., 5., 6.]], dtype=float32)
+>>> allocarr.mod.b.flags.f_contiguous
+True
+>>> allocarr.mod.b = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # reallocate/initialize b
+>>> allocarr.mod.foo()
+ b=[
+ 1.000000 2.000000 3.000000
+ 4.000000 5.000000 6.000000
+ 7.000000 8.000000 9.000000
+ ]
+>>> allocarr.mod.b = None # deallocate array
+>>> allocarr.mod.foo()
+ b is not allocated
diff --git a/doc/source/f2py/code/results/array_session.dat b/doc/source/f2py/code/results/array_session.dat
new file mode 100644
index 000000000..714c03651
--- /dev/null
+++ b/doc/source/f2py/code/results/array_session.dat
@@ -0,0 +1,87 @@
+>>> import arr
+>>> from numpy import asfortranarray
+>>> print(arr.foo.__doc__)
+a = foo(a,[overwrite_a])
+
+Wrapper for ``foo``.
+
+Parameters
+----------
+a : input rank-2 array('d') with bounds (n,m)
+
+Other Parameters
+----------------
+overwrite_a : input int, optional
+ Default: 0
+
+Returns
+-------
+a : rank-2 array('d') with bounds (n,m)
+
+>>> a = arr.foo([[1, 2, 3],
+... [4, 5, 6]])
+created an array from object
+>>> print(a)
+[[ 1. 3. 4.]
+ [ 3. 5. 6.]]
+>>> a.flags.c_contiguous
+False
+>>> a.flags.f_contiguous
+True
+# even if a is proper-contiguous and has proper type,
+# a copy is made forced by intent(copy) attribute
+# to preserve its original contents
+>>> b = arr.foo(a)
+copied an array: size=6, elsize=8
+>>> print(a)
+[[ 1. 3. 4.]
+ [ 3. 5. 6.]]
+>>> print(b)
+[[ 1. 4. 5.]
+ [ 2. 5. 6.]]
+>>> b = arr.foo(a, overwrite_a = 1) # a is passed directly to Fortran
+... # routine and its contents is discarded
+...
+>>> print(a)
+[[ 1. 4. 5.]
+ [ 2. 5. 6.]]
+>>> print(b)
+[[ 1. 4. 5.]
+ [ 2. 5. 6.]]
+>>> a is b # a and b are actually the same objects
+True
+>>> print(arr.foo([1, 2, 3])) # different rank arrays are allowed
+created an array from object
+[ 1. 1. 2.]
+>>> print(arr.foo([[[1], [2], [3]]]))
+created an array from object
+[[[ 1.]
+ [ 1.]
+ [ 2.]]]
+>>>
+>>> # Creating arrays with column major data storage order:
+ ...
+>>> s = asfortranarray([[1, 2, 3], [4, 5, 6]])
+>>> s.flags.f_contiguous
+True
+>>> print(s)
+[[1 2 3]
+ [4 5 6]]
+>>> print(arr.foo(s))
+>>> s2 = asfortranarray(s)
+>>> s2 is s # an array with column major storage order
+ # is returned immediately
+True
+>>> # Note that arr.foo returns a column major data storage order array:
+ ...
+>>> s3 = ascontiguousarray(s)
+>>> s3.flags.f_contiguous
+False
+>>> s3.flags.c_contiguous
+True
+>>> s3 = arr.foo(s3)
+copied an array: size=6, elsize=8
+>>> s3.flags.f_contiguous
+True
+>>> s3.flags.c_contiguous
+False
diff --git a/doc/source/f2py/code/results/calculate_session.dat b/doc/source/f2py/code/results/calculate_session.dat
new file mode 100644
index 000000000..c4c380700
--- /dev/null
+++ b/doc/source/f2py/code/results/calculate_session.dat
@@ -0,0 +1,6 @@
+>>> import foo
+>>> foo.calculate(range(5), lambda x: x*x)
+array([ 0., 1., 4., 9., 16.])
+>>> import math
+>>> foo.calculate(range(5), math.exp)
+array([ 1. , 2.71828183, 7.3890561, 20.08553692, 54.59815003])
diff --git a/doc/source/f2py/code/results/callback_session.dat b/doc/source/f2py/code/results/callback_session.dat
new file mode 100644
index 000000000..460c9ce28
--- /dev/null
+++ b/doc/source/f2py/code/results/callback_session.dat
@@ -0,0 +1,35 @@
+>>> import callback
+>>> print(callback.foo.__doc__)
+r = foo(fun,[fun_extra_args])
+
+Wrapper for ``foo``.
+
+Parameters
+----------
+fun : call-back function
+
+Other Parameters
+----------------
+fun_extra_args : input tuple, optional
+ Default: ()
+
+Returns
+-------
+r : float
+
+Notes
+-----
+Call-back functions::
+
+ def fun(i): return r
+ Required arguments:
+ i : input int
+ Return objects:
+ r : float
+
+>>> def f(i): return i*i
+...
+>>> print(callback.foo(f))
+110.0
+>>> print(callback.foo(lambda i:1))
+11.0
diff --git a/doc/source/f2py/code/results/common_session.dat b/doc/source/f2py/code/results/common_session.dat
new file mode 100644
index 000000000..2595bfbd5
--- /dev/null
+++ b/doc/source/f2py/code/results/common_session.dat
@@ -0,0 +1,30 @@
+>>> import common
+>>> print(common.data.__doc__)
+i : 'i'-scalar
+x : 'i'-array(4)
+a : 'f'-array(2,3)
+
+>>> common.data.i = 5
+>>> common.data.x[1] = 2
+>>> common.data.a = [[1,2,3],[4,5,6]]
+>>> common.foo()
+>>> common.foo()
+ I= 5
+ X=[ 0 2 0 0 ]
+ A=[
+ [ 1.00000000 , 2.00000000 , 3.00000000 ]
+ [ 4.00000000 , 5.00000000 , 6.00000000 ]
+ ]
+>>> common.data.a[1] = 45
+>>> common.foo()
+ I= 5
+ X=[ 0 2 0 0 ]
+ A=[
+ [ 1.00000000 , 2.00000000 , 3.00000000 ]
+ [ 45.0000000 , 45.0000000 , 45.0000000 ]
+ ]
+>>> common.data.a # a is Fortran-contiguous
+array([[ 1., 2., 3.],
+ [ 45., 45., 45.]], dtype=float32)
+>>> common.data.a.flags.f_contiguous
+True \ No newline at end of file
diff --git a/doc/source/f2py/code/results/compile_session.dat b/doc/source/f2py/code/results/compile_session.dat
new file mode 100644
index 000000000..5c42742be
--- /dev/null
+++ b/doc/source/f2py/code/results/compile_session.dat
@@ -0,0 +1,11 @@
+>>> import numpy.f2py
+>>> fsource = '''
+... subroutine foo
+... print*, "Hello world!"
+... end
+... '''
+>>> numpy.f2py.compile(fsource, modulename='hello', verbose=0)
+0
+>>> import hello
+>>> hello.foo()
+ Hello world!
diff --git a/doc/source/f2py/code/results/extcallback_session.dat b/doc/source/f2py/code/results/extcallback_session.dat
new file mode 100644
index 000000000..5b97ab7cf
--- /dev/null
+++ b/doc/source/f2py/code/results/extcallback_session.dat
@@ -0,0 +1,19 @@
+>>> import pfromf
+>>> pfromf.f2()
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+pfromf.error: Callback fpy not defined (as an argument or module pfromf attribute).
+
+>>> def f(): print("python f")
+...
+>>> pfromf.fpy = f
+>>> pfromf.f2()
+ in f2, calling f2py..
+python f
+>>> pfromf.f1()
+ in f1, calling f2 twice..
+ in f2, calling f2py..
+python f
+ in f2, calling f2py..
+python f
+>>> \ No newline at end of file
diff --git a/doc/source/f2py/code/results/ftype_session.dat b/doc/source/f2py/code/results/ftype_session.dat
new file mode 100644
index 000000000..e39cc128d
--- /dev/null
+++ b/doc/source/f2py/code/results/ftype_session.dat
@@ -0,0 +1,21 @@
+>>> import ftype
+>>> print(ftype.__doc__)
+This module 'ftype' is auto-generated with f2py (version:2).
+Functions:
+ foo(n=13)
+COMMON blocks:
+ /data/ a,x(3)
+.
+>>> type(ftype.foo), type(ftype.data)
+(<class 'fortran'>, <class 'fortran'>)
+>>> ftype.foo()
+ IN FOO: N= 13 A= 0. X=[ 0. 0. 0.]
+>>> ftype.data.a = 3
+>>> ftype.data.x = [1,2,3]
+>>> ftype.foo()
+ IN FOO: N= 13 A= 3. X=[ 1. 2. 3.]
+>>> ftype.data.x[1] = 45
+>>> ftype.foo(24)
+ IN FOO: N= 24 A= 3. X=[ 1. 45. 3.]
+>>> ftype.data.x
+array([ 1., 45., 3.], dtype=float32)
diff --git a/doc/source/f2py/code/results/moddata_session.dat b/doc/source/f2py/code/results/moddata_session.dat
new file mode 100644
index 000000000..824bd86fc
--- /dev/null
+++ b/doc/source/f2py/code/results/moddata_session.dat
@@ -0,0 +1,28 @@
+>>> import moddata
+>>> print(moddata.mod.__doc__)
+i : 'i'-scalar
+x : 'i'-array(4)
+a : 'f'-array(2,3)
+b : 'f'-array(-1,-1), not allocated
+foo()
+
+Wrapper for ``foo``.
+
+
+
+>>> moddata.mod.i = 5
+>>> moddata.mod.x[:2] = [1,2]
+>>> moddata.mod.a = [[1,2,3],[4,5,6]]
+>>> moddata.mod.foo()
+ i= 5
+ x=[ 1 2 0 0 ]
+ a=[
+ [ 1.000000 , 2.000000 , 3.000000 ]
+ [ 4.000000 , 5.000000 , 6.000000 ]
+ ]
+ Setting a(1,2)=a(1,2)+3
+>>> moddata.mod.a # a is Fortran-contiguous
+array([[ 1., 5., 3.],
+ [ 4., 5., 6.]], dtype=float32)
+>>> moddata.mod.a.flags.f_contiguous
+True
diff --git a/doc/source/f2py/code/results/run_main_session.dat b/doc/source/f2py/code/results/run_main_session.dat
new file mode 100644
index 000000000..be6cacd22
--- /dev/null
+++ b/doc/source/f2py/code/results/run_main_session.dat
@@ -0,0 +1,14 @@
+>>> import numpy.f2py
+>>> r = numpy.f2py.run_main(['-m','scalar','doc/source/f2py/scalar.f'])
+Reading fortran codes...
+ Reading file 'doc/source/f2py/scalar.f' (format:fix,strict)
+Post-processing...
+ Block: scalar
+ Block: FOO
+Building modules...
+ Building module "scalar"...
+ Wrote C/API module "scalar" to file "./scalarmodule.c"
+>>> print(r)
+{'scalar': {'h': ['/home/users/pearu/src_cvs/f2py/src/fortranobject.h'],
+ 'csrc': ['./scalarmodule.c',
+ '/home/users/pearu/src_cvs/f2py/src/fortranobject.c']}}
diff --git a/doc/source/f2py/code/results/scalar_session.dat b/doc/source/f2py/code/results/scalar_session.dat
new file mode 100644
index 000000000..3bb45ed68
--- /dev/null
+++ b/doc/source/f2py/code/results/scalar_session.dat
@@ -0,0 +1,24 @@
+>>> import scalar
+>>> print(scalar.foo.__doc__)
+foo(a,b)
+
+Wrapper for ``foo``.
+
+Parameters
+----------
+a : input float
+b : in/output rank-0 array(float,'d')
+
+>>> scalar.foo(2, 3)
+ A= 2. B= 3.
+ INCREMENT A AND B
+ NEW A= 3. B= 4.
+>>> import numpy
+>>> a = numpy.array(2) # these are integer rank-0 arrays
+>>> b = numpy.array(3)
+>>> scalar.foo(a, b)
+ A= 2. B= 3.
+ INCREMENT A AND B
+ NEW A= 3. B= 4.
+>>> print(a, b) # note that only b is changed in situ
+2 4
diff --git a/doc/source/f2py/code/results/spam_session.dat b/doc/source/f2py/code/results/spam_session.dat
new file mode 100644
index 000000000..bd5832d88
--- /dev/null
+++ b/doc/source/f2py/code/results/spam_session.dat
@@ -0,0 +1,5 @@
+>>> import spam
+>>> status = spam.system('whoami')
+pearu
+>>> status = spam.system('blah')
+sh: line 1: blah: command not found \ No newline at end of file
diff --git a/doc/source/f2py/code/results/string_session.dat b/doc/source/f2py/code/results/string_session.dat
new file mode 100644
index 000000000..e8f7854d9
--- /dev/null
+++ b/doc/source/f2py/code/results/string_session.dat
@@ -0,0 +1,30 @@
+>>> import mystring
+>>> print(mystring.foo.__doc__)
+foo(a,b,c,d)
+
+Wrapper for ``foo``.
+
+Parameters
+----------
+a : input string(len=5)
+b : in/output rank-0 array(string(len=5),'c')
+c : input string(len=-1)
+d : in/output rank-0 array(string(len=-1),'c')
+
+>>> from numpy import array
+>>> a = array(b'123\0\0')
+>>> b = array(b'123\0\0')
+>>> c = array(b'123')
+>>> d = array(b'123')
+>>> mystring.foo(a, b, c, d)
+ A=123
+ B=123
+ C=123
+ D=123
+ CHANGE A,B,C,D
+ A=A23
+ B=B23
+ C=C23
+ D=D23
+>>> a[()], b[()], c[()], d[()]
+(b'123', b'B23', b'123', b'D2')
diff --git a/doc/source/f2py/code/results/var_session.dat b/doc/source/f2py/code/results/var_session.dat
new file mode 100644
index 000000000..fb0f798bf
--- /dev/null
+++ b/doc/source/f2py/code/results/var_session.dat
@@ -0,0 +1,3 @@
+>>> import var
+>>> var.BAR
+5 \ No newline at end of file