diff options
-rw-r--r-- | doc/source/f2py/advanced.rst | 2 | ||||
-rw-r--r-- | doc/source/f2py/allocarr_session.dat | 16 | ||||
-rw-r--r-- | doc/source/f2py/array_session.dat | 112 | ||||
-rw-r--r-- | doc/source/f2py/calculate.f | 2 | ||||
-rw-r--r-- | doc/source/f2py/calculate_session.dat | 2 | ||||
-rw-r--r-- | doc/source/f2py/callback.f | 2 | ||||
-rw-r--r-- | doc/source/f2py/callback_session.dat | 36 | ||||
-rw-r--r-- | doc/source/f2py/common_session.dat | 23 | ||||
-rw-r--r-- | doc/source/f2py/extcallback_session.dat | 4 | ||||
-rw-r--r-- | doc/source/f2py/ftype_session.dat | 10 | ||||
-rw-r--r-- | doc/source/f2py/getting-started.rst | 102 | ||||
-rw-r--r-- | doc/source/f2py/moddata_session.dat | 7 | ||||
-rw-r--r-- | doc/source/f2py/python-usage.rst | 25 | ||||
-rw-r--r-- | doc/source/f2py/scalar_session.dat | 25 | ||||
-rw-r--r-- | doc/source/f2py/signature-file.rst | 2 | ||||
-rw-r--r-- | doc/source/f2py/spam_session.dat | 2 | ||||
-rw-r--r-- | doc/source/f2py/string_session.dat | 35 | ||||
-rw-r--r-- | doc/source/f2py/usage.rst | 37 | ||||
-rw-r--r-- | numpy/lib/histograms.py | 4 |
19 files changed, 258 insertions, 190 deletions
diff --git a/doc/source/f2py/advanced.rst b/doc/source/f2py/advanced.rst index 375922033..1b4625dde 100644 --- a/doc/source/f2py/advanced.rst +++ b/doc/source/f2py/advanced.rst @@ -25,7 +25,7 @@ In Python: Modifying the dictionary of a F2PY generated module =================================================== -The following example illustrates how to add a user-defined +The following example illustrates how to add user-defined variables to a F2PY generated extension module. Given the following signature file diff --git a/doc/source/f2py/allocarr_session.dat b/doc/source/f2py/allocarr_session.dat index fc91959b7..754d9cb8b 100644 --- a/doc/source/f2py/allocarr_session.dat +++ b/doc/source/f2py/allocarr_session.dat @@ -1,27 +1,29 @@ ->>> import allocarr ->>> print allocarr.mod.__doc__ +>>> import allocarr +>>> print(allocarr.mod.__doc__) b - 'f'-array(-1,-1), not allocated foo - Function signature: foo() >>> allocarr.mod.foo() b is not allocated ->>> allocarr.mod.b = [[1,2,3],[4,5,6]] # allocate/initialize b +>>> 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 +>>> allocarr.mod.b # b is Fortran-contiguous array([[ 1., 2., 3.], - [ 4., 5., 6.]],'f') ->>> allocarr.mod.b = [[1,2,3],[4,5,6],[7,8,9]] # reallocate/initialize b + [ 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.b = None # deallocate array >>> allocarr.mod.foo() b is not allocated diff --git a/doc/source/f2py/array_session.dat b/doc/source/f2py/array_session.dat index 069530d03..714c03651 100644 --- a/doc/source/f2py/array_session.dat +++ b/doc/source/f2py/array_session.dat @@ -1,65 +1,87 @@ >>> import arr ->>> from numpy import array ->>> print arr.foo.__doc__ -foo - Function signature: - a = foo(a,[overwrite_a]) -Required arguments: - a : input rank-2 array('d') with bounds (n,m) -Optional arguments: - overwrite_a := 0 input int -Return objects: - a : rank-2 array('d') with bounds (n,m) +>>> from numpy import asfortranarray +>>> print(arr.foo.__doc__) +a = foo(a,[overwrite_a]) ->>> a=arr.foo([[1,2,3], -... [4,5,6]]) -copied an array using PyArray_CopyFromObject: size=6, elsize=8 ->>> print 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.iscontiguous(), arr.has_column_major_storage(a) -(0, 1) ->>> b=arr.foo(a) # even if a is proper-contiguous -... # and has proper type, a copy is made -... # forced by intent(copy) attribute -... # to preserve its original contents -... -copied an array using copy_ND_array: size=6, elsize=8 ->>> print a +>>> 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 +>>> 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 +>>> b = arr.foo(a, overwrite_a = 1) # a is passed directly to Fortran +... # routine and its contents is discarded ... ->>> print a +>>> print(a) [[ 1. 4. 5.] [ 2. 5. 6.]] ->>> print b +>>> print(b) [[ 1. 4. 5.] [ 2. 5. 6.]] ->>> a is b # a and b are actually the same objects -1 ->>> print arr.foo([1,2,3]) # different rank arrays are allowed -copied an array using PyArray_CopyFromObject: size=3, elsize=8 +>>> 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]]]) -copied an array using PyArray_CopyFromObject: size=3, elsize=8 -[ [[ 1.] - [ 3.] - [ 4.]]] +>>> print(arr.foo([[[1], [2], [3]]])) +created an array from object +[[[ 1.] + [ 1.] + [ 2.]]] >>> >>> # Creating arrays with column major data storage order: -... ->>> s = arr.as_column_major_storage(array([[1,2,3],[4,5,6]])) -copied an array using copy_ND_array: size=6, elsize=4 ->>> arr.has_column_major_storage(s) -1 ->>> print s + ... +>>> s = asfortranarray([[1, 2, 3], [4, 5, 6]]) +>>> s.flags.f_contiguous +True +>>> print(s) [[1 2 3] [4 5 6]] ->>> s2 = arr.as_column_major_storage(s) +>>> print(arr.foo(s)) +>>> s2 = asfortranarray(s) >>> s2 is s # an array with column major storage order # is returned immediately -1 +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/calculate.f b/doc/source/f2py/calculate.f index 1cda1c8dd..4ff570d28 100644 --- a/doc/source/f2py/calculate.f +++ b/doc/source/f2py/calculate.f @@ -7,7 +7,7 @@ cf2py y = func(y) c cf2py intent(in,out,copy) x integer n,i - real*8 x(n) + real*8 x(n), func do i=1,n x(i) = func(x(i)) end do diff --git a/doc/source/f2py/calculate_session.dat b/doc/source/f2py/calculate_session.dat index 2fe64f522..c4c380700 100644 --- a/doc/source/f2py/calculate_session.dat +++ b/doc/source/f2py/calculate_session.dat @@ -3,4 +3,4 @@ array([ 0., 1., 4., 9., 16.]) >>> import math >>> foo.calculate(range(5), math.exp) -array([ 1. , 2.71828175, 7.38905621, 20.08553696, 54.59814835]) +array([ 1. , 2.71828183, 7.3890561, 20.08553692, 54.59815003]) diff --git a/doc/source/f2py/callback.f b/doc/source/f2py/callback.f index 6e9bfb920..d5cfc7574 100644 --- a/doc/source/f2py/callback.f +++ b/doc/source/f2py/callback.f @@ -2,7 +2,7 @@ C FILE: CALLBACK.F SUBROUTINE FOO(FUN,R) EXTERNAL FUN INTEGER I - REAL*8 R + REAL*8 R, FUN Cf2py intent(out) r R = 0D0 DO I=-5,5 diff --git a/doc/source/f2py/callback_session.dat b/doc/source/f2py/callback_session.dat index cd2f26084..460c9ce28 100644 --- a/doc/source/f2py/callback_session.dat +++ b/doc/source/f2py/callback_session.dat @@ -1,14 +1,26 @@ >>> import callback ->>> print callback.foo.__doc__ -foo - Function signature: - r = foo(fun,[fun_extra_args]) -Required arguments: - fun : call-back function -Optional arguments: - fun_extra_args := () input tuple -Return objects: - r : float -Call-back functions: +>>> 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 @@ -17,7 +29,7 @@ Call-back functions: >>> def f(i): return i*i ... ->>> print callback.foo(f) +>>> print(callback.foo(f)) 110.0 ->>> print callback.foo(lambda i:1) +>>> print(callback.foo(lambda i:1)) 11.0 diff --git a/doc/source/f2py/common_session.dat b/doc/source/f2py/common_session.dat index 846fdaa07..0a38bec27 100644 --- a/doc/source/f2py/common_session.dat +++ b/doc/source/f2py/common_session.dat @@ -1,5 +1,5 @@ >>> import common ->>> print common.data.__doc__ +>>> print(common.data.__doc__) i - 'i'-scalar x - 'i'-array(4) a - 'f'-array(2,3) @@ -8,20 +8,23 @@ a - 'f'-array(2,3) >>> common.data.x[1] = 2 >>> common.data.a = [[1,2,3],[4,5,6]] >>> common.foo() - I= 5 - X=[ 0 2 0 0] +>>> common.foo() + I= 5 + X=[ 0 2 0 0 ] A=[ - [ 1., 2., 3.] - [ 4., 5., 6.] + [ 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] + I= 5 + X=[ 0 2 0 0 ] A=[ - [ 1., 2., 3.] - [ 45., 45., 45.] + [ 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.]],'f') + [ 45., 45., 45.]], dtype=float32) +>>> common.data.a.flags.f_contiguous +True
\ No newline at end of file diff --git a/doc/source/f2py/extcallback_session.dat b/doc/source/f2py/extcallback_session.dat index c22935ea0..5b97ab7cf 100644 --- a/doc/source/f2py/extcallback_session.dat +++ b/doc/source/f2py/extcallback_session.dat @@ -1,10 +1,10 @@ >>> import pfromf >>> pfromf.f2() Traceback (most recent call last): - File "<stdin>", line 1, in ? + File "<stdin>", line 1, in <module> pfromf.error: Callback fpy not defined (as an argument or module pfromf attribute). ->>> def f(): print "python f" +>>> def f(): print("python f") ... >>> pfromf.fpy = f >>> pfromf.f2() diff --git a/doc/source/f2py/ftype_session.dat b/doc/source/f2py/ftype_session.dat index 01f9febaf..e39cc128d 100644 --- a/doc/source/f2py/ftype_session.dat +++ b/doc/source/f2py/ftype_session.dat @@ -1,13 +1,13 @@ >>> import ftype ->>> print ftype.__doc__ -This module 'ftype' is auto-generated with f2py (version:2.28.198-1366). +>>> 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) -(<type 'fortran'>, <type 'fortran'>) +>>> 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 @@ -18,4 +18,4 @@ COMMON blocks: >>> ftype.foo(24) IN FOO: N= 24 A= 3. X=[ 1. 45. 3.] >>> ftype.data.x -array([ 1., 45., 3.],'f') +array([ 1., 45., 3.], dtype=float32) diff --git a/doc/source/f2py/getting-started.rst b/doc/source/f2py/getting-started.rst index 3d8ea24e4..c600eee01 100644 --- a/doc/source/f2py/getting-started.rst +++ b/doc/source/f2py/getting-started.rst @@ -54,17 +54,23 @@ Python the Fortran subroutine ``FIB`` is accessible via ``fib1.fib``:: >>> import numpy >>> import fib1 - >>> print fib1.fib.__doc__ - fib - Function signature: - fib(a,[n]) - Required arguments: - a : input rank-1 array('d') with bounds (n) - Optional arguments: - n := len(a) input int - - >>> a = numpy.zeros(8,'d') + >>> print(fib1.fib.__doc__) + fib(a,[n]) + + Wrapper for ``fib``. + + Parameters + ---------- + a : input rank-1 array('d') with bounds (n) + + Other Parameters + ---------------- + n : input int, optional + Default: len(a) + + >>> a = numpy.zeros(8, 'd') >>> fib1.fib(a) - >>> print a + >>> print(a) [ 0. 1. 1. 2. 3. 5. 8. 13.] .. note:: @@ -76,22 +82,20 @@ Python the Fortran subroutine ``FIB`` is accessible via ``fib1.fib``:: * One can use different values for optional ``n``:: - >>> a1 = numpy.zeros(8,'d') - >>> fib1.fib(a1,6) - >>> print a1 + >>> a1 = numpy.zeros(8, 'd') + >>> fib1.fib(a1, 6) + >>> print(a1) [ 0. 1. 1. 2. 3. 5. 0. 0.] but an exception is raised when it is incompatible with the input array ``a``:: - >>> fib1.fib(a,10) - fib:n=10 + >>> fib1.fib(a, 10) Traceback (most recent call last): - File "<stdin>", line 1, in ? - fib.error: (len(a)>=n) failed for 1st keyword n + File "<stdin>", line 1, in <module> + fib.error: (len(a)>=n) failed for 1st keyword n: fib:n=10 >>> - This demonstrates one of the useful features in F2PY, that it, F2PY implements basic compatibility checks between related arguments in order to avoid any unexpected crashes. @@ -105,9 +109,9 @@ Python the Fortran subroutine ``FIB`` is accessible via ``fib1.fib``:: input array have no effect to the original argument, as demonstrated below:: - >>> a = numpy.ones(8,'i') + >>> a = numpy.ones(8, 'i') >>> fib1.fib(a) - >>> print a + >>> print(a) [1 1 1 1 1 1 1 1] Clearly, this is not an expected behaviour. The fact that the @@ -118,15 +122,15 @@ Python the Fortran subroutine ``FIB`` is accessible via ``fib1.fib``:: the attributes of an input array so that any changes made by Fortran routine will be effective also in input argument. For example, if one specifies ``intent(inplace) a`` (see below, how), then - the example above would read: + the example above would read:: - >>> a = numpy.ones(8,'i') + >>> a = numpy.ones(8, 'i') >>> fib1.fib(a) - >>> print a + >>> print(a) [ 0. 1. 1. 2. 3. 5. 8. 13.] However, the recommended way to get changes made by Fortran - subroutine back to python is to use ``intent(out)`` attribute. It + subroutine back to Python is to use ``intent(out)`` attribute. It is more efficient and a cleaner solution. * The usage of ``fib1.fib`` in Python is very similar to using @@ -193,15 +197,20 @@ one. In Python:: >>> import fib2 - >>> print fib2.fib.__doc__ - fib - Function signature: - a = fib(n) - Required arguments: - n : input int - Return objects: - a : rank-1 array('d') with bounds (n) - - >>> print fib2.fib(8) + >>> print(fib2.fib.__doc__) + a = fib(n) + + Wrapper for ``fib``. + + Parameters + ---------- + n : input int + + Returns + ------- + a : rank-1 array('d') with bounds (n) + + >>> print(fib2.fib(8)) [ 0. 1. 1. 2. 3. 5. 8. 13.] .. note:: @@ -213,8 +222,8 @@ In Python:: rules out any surprises that we experienced with ``fib1.fib``. * Note that by default using single ``intent(out)`` also implies - ``intent(hide)``. Argument that has ``intent(hide)`` attribute - specified, will not be listed in the argument list of a wrapper + ``intent(hide)``. Arguments that have the ``intent(hide)`` attribute + specified will not be listed in the argument list of a wrapper function. The quick and smart way @@ -249,13 +258,18 @@ Notice that the resulting wrapper to ``FIB`` is as "smart" as in previous case:: >>> import fib3 - >>> print fib3.fib.__doc__ - fib - Function signature: - a = fib(n) - Required arguments: - n : input int - Return objects: - a : rank-1 array('d') with bounds (n) - - >>> print fib3.fib(8) + >>> print(fib3.fib.__doc__) + a = fib(n) + + Wrapper for ``fib``. + + Parameters + ---------- + n : input int + + Returns + ------- + a : rank-1 array('d') with bounds (n) + + >>> print(fib3.fib(8)) [ 0. 1. 1. 2. 3. 5. 8. 13.] diff --git a/doc/source/f2py/moddata_session.dat b/doc/source/f2py/moddata_session.dat index 1ec212f8b..e3c758041 100644 --- a/doc/source/f2py/moddata_session.dat +++ b/doc/source/f2py/moddata_session.dat @@ -1,12 +1,11 @@ >>> import moddata ->>> print moddata.mod.__doc__ +>>> print(moddata.mod.__doc__) i - 'i'-scalar x - 'i'-array(4) a - 'f'-array(2,3) foo - Function signature: foo() - >>> moddata.mod.i = 5 >>> moddata.mod.x[:2] = [1,2] >>> moddata.mod.a = [[1,2,3],[4,5,6]] @@ -20,4 +19,6 @@ foo - Function signature: Setting a(1,2)=a(1,2)+3 >>> moddata.mod.a # a is Fortran-contiguous array([[ 1., 5., 3.], - [ 4., 5., 6.]],'f') + [ 4., 5., 6.]], dtype=float32) +>>> moddata.mod.a.flags.f_contiguous +True diff --git a/doc/source/f2py/python-usage.rst b/doc/source/f2py/python-usage.rst index 60167d01a..a7f2b3d86 100644 --- a/doc/source/f2py/python-usage.rst +++ b/doc/source/f2py/python-usage.rst @@ -8,7 +8,7 @@ type objects. Routine wrappers are callable ``fortran`` type objects while wrappers to Fortran data have attributes referring to data objects. -All ``fortran`` type object have attribute ``_cpointer`` that contains +All ``fortran`` type objects have attribute ``_cpointer`` that contains CObject referring to the C pointer of the corresponding Fortran/C function or variable in C level. Such CObjects can be used as a callback argument of F2PY generated functions to bypass Python C/API @@ -34,7 +34,7 @@ Scalar arguments ================= In general, a scalar argument of a F2PY generated wrapper function can -be ordinary Python scalar (integer, float, complex number) as well as +be an ordinary Python scalar (integer, float, complex number) as well as an arbitrary sequence object (list, tuple, array, string) of scalars. In the latter case, the first element of the sequence object is passed to Fortran routine as a scalar argument. @@ -45,7 +45,7 @@ float), F2PY does not raise any exception. In complex to real type-casting only the real part of a complex number is used. ``intent(inout)`` scalar arguments are assumed to be array objects in -order to *in situ* changes to be effective. It is recommended to use +order to have *in situ* changes be effective. It is recommended to use arrays with proper type but also other types work. Consider the following Fortran 77 code: @@ -75,8 +75,7 @@ expected, the string is truncated. If the length is smaller that expected, additional memory is allocated and filled with ``\0``. Because Python strings are immutable, an ``intent(inout)`` argument -expects an array version of a string in order to *in situ* changes to -be effective. +expects an array version of a string in order to have *in situ* changes be effective. Consider the following Fortran 77 code: @@ -99,7 +98,7 @@ arbitrary sequences that can be transformed to NumPy array objects. An exception is ``intent(inout)`` array arguments that always must be proper-contiguous and have proper type, otherwise an exception is raised. Another exception is ``intent(inplace)`` array arguments that -attributes will be changed in-situ if the argument has different type +attributes will be changed *in situ* if the argument has different type than expected (see ``intent(inplace)`` attribute for more information). @@ -129,11 +128,9 @@ and C-contiguous if the order is as follows:: A[0,0] A[0,1] A[1,0] A[1,1] -To test whether an array is C-contiguous, use ``.iscontiguous()`` -method of NumPy arrays. To test for Fortran contiguity, all -F2PY generated extension modules provide a function -``has_column_major_storage(<array>)``. This function is equivalent to -``<array>.flags.f_contiguous`` but more efficient. +To test whether an array is C-contiguous, use the ``.flags.c_contiguous`` +attribute of NumPy arrays. To test for Fortran contiguity, use the +``.flags.f_contiguous`` attribute. Usually there is no need to worry about how the arrays are stored in memory and whether the wrapped functions, being either Fortran or C @@ -146,11 +143,9 @@ the physical memory in your computer, then a care must be taken to use always proper-contiguous and proper type arguments. To transform input arrays to column major storage order before passing -them to Fortran routines, use a function -``as_column_major_storage(<array>)`` that is provided by all F2PY -generated extension modules. +them to Fortran routines, use the function ``numpy.asfortranarray(<array>)``. -Consider Fortran 77 code: +Consider the following Fortran 77 code: .. include:: array.f :literal: diff --git a/doc/source/f2py/scalar_session.dat b/doc/source/f2py/scalar_session.dat index 8aff097c2..3bb45ed68 100644 --- a/doc/source/f2py/scalar_session.dat +++ b/doc/source/f2py/scalar_session.dat @@ -1,21 +1,24 @@ >>> import scalar ->>> print scalar.foo.__doc__ -foo - Function signature: - foo(a,b) -Required arguments: - a : input float - b : in/output rank-0 array(float,'d') +>>> 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) +>>> 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 = 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 +>>> print(a, b) # note that only b is changed in situ 2 4 diff --git a/doc/source/f2py/signature-file.rst b/doc/source/f2py/signature-file.rst index 8e5a9710c..3a163ee23 100644 --- a/doc/source/f2py/signature-file.rst +++ b/doc/source/f2py/signature-file.rst @@ -14,7 +14,7 @@ Signature files may contain arbitrary Fortran code (so that Fortran codes can be considered as signature files). F2PY silently ignores Fortran constructs that are irrelevant for creating the interface. However, this includes also syntax errors. So, be careful not making -ones;-). +ones ;-). In general, the contents of signature files is case-sensitive. When scanning Fortran codes and writing a signature file, F2PY lowers all diff --git a/doc/source/f2py/spam_session.dat b/doc/source/f2py/spam_session.dat index 7f99d13f9..bd5832d88 100644 --- a/doc/source/f2py/spam_session.dat +++ b/doc/source/f2py/spam_session.dat @@ -1,5 +1,5 @@ >>> import spam >>> status = spam.system('whoami') pearu ->> status = spam.system('blah') +>>> status = spam.system('blah') sh: line 1: blah: command not found
\ No newline at end of file diff --git a/doc/source/f2py/string_session.dat b/doc/source/f2py/string_session.dat index cbae6b784..e8f7854d9 100644 --- a/doc/source/f2py/string_session.dat +++ b/doc/source/f2py/string_session.dat @@ -1,19 +1,22 @@ >>> import mystring ->>> print mystring.foo.__doc__ -foo - Function signature: - foo(a,b,c,d) -Required arguments: - 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') +>>> print(mystring.foo.__doc__) +foo(a,b,c,d) ->>> import numpy ->>> a=numpy.array('123') ->>> b=numpy.array('123') ->>> c=numpy.array('123') ->>> d=numpy.array('123') ->>> mystring.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 @@ -23,5 +26,5 @@ Required arguments: B=B23 C=C23 D=D23 ->>> a.tostring(),b.tostring(),c.tostring(),d.tostring() -('123', 'B23', '123', 'D23') +>>> a[()], b[()], c[()], d[()] +(b'123', b'B23', b'123', b'D2') diff --git a/doc/source/f2py/usage.rst b/doc/source/f2py/usage.rst index 5043ec430..6c3b4b6ef 100644 --- a/doc/source/f2py/usage.rst +++ b/doc/source/f2py/usage.rst @@ -6,11 +6,9 @@ F2PY can be used either as a command line tool ``f2py`` or as a Python module ``numpy.f2py``. While we try to install the command line tool as part of the numpy setup, some platforms like Windows make it difficult to reliably put the executable on the ``PATH``. We will refer to ``f2py`` -in this document but you may have to run it as a module +in this document but you may have to run it as a module:: -``` -python -m numpy.f2py -``` + python -m numpy.f2py If you run ``f2py`` with no arguments, and the line ``numpy Version`` at the end matches the NumPy version printed from ``python -m numpy.f2py``, then you @@ -50,9 +48,9 @@ distinguished by the usage of ``-c`` and ``-h`` switches: :: - f2py <options> <fortran files> \ - [[ only: <fortran functions> : ] \ - [ skip: <fortran functions> : ]]... \ + f2py -m <modulename> <options> <fortran files> \ + [[ only: <fortran functions> : ] \ + [ skip: <fortran functions> : ]]... \ [<fortran files> ...] The constructed extension module is saved as @@ -79,11 +77,9 @@ distinguished by the usage of ``-c`` and ``-h`` switches: functions. This feature enables using arbitrary C functions (defined in ``<includefile>``) in F2PY generated wrappers. - This option is deprecated. Use ``usercode`` statement to specify - C code snippets directly in signature files + .. note:: This option is deprecated. Use ``usercode`` statement to specify C code snippets directly in signature files. ``--[no-]wrap-functions`` - Create Fortran subroutine wrappers to Fortran functions. ``--wrap-functions`` is default because it ensures maximum portability and compiler independence. @@ -161,12 +157,29 @@ distinguished by the usage of ``-c`` and ``-h`` switches: for ``-l``. ``link-<resource>`` - Link extension module with <resource> as defined by ``numpy_distutils/system_info.py``. E.g. to link with optimized LAPACK libraries (vecLib on MacOSX, ATLAS elsewhere), use ``--link-lapack_opt``. See also ``--help-link`` switch. - + + .. note:: The ``f2py -c`` option must be applied either to an existing ``.pyf`` file (plus the source/object/library files) or one must specify the ``-m <modulename>`` option (plus the sources/object/library files). Use one of the following options: + + :: + + f2py -c -m fib1 fib1.f + + or + + :: + + f2py -m fib1 fib1.f -h fib1.pyf + f2py -c fib1.pyf fib1.f + + For more information, see `Building C and C++ Extensions`__ Python documentation for details. + + __ https://docs.python.org/3/extending/building.html + + When building an extension module, a combination of the following macros may be required for non-gcc Fortran compilers:: diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 0eff73b39..70ecd6eb1 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -954,9 +954,9 @@ def histogramdd(sample, bins=10, range=None, normed=None, weights=None, Note the unusual interpretation of sample when an array_like: * When an array, each row is a coordinate in a D-dimensional space - - such as ``histogramgramdd(np.array([p1, p2, p3]))``. + such as ``histogramdd(np.array([p1, p2, p3]))``. * When an array_like, each element is the list of values for single - coordinate - such as ``histogramgramdd((X, Y, Z))``. + coordinate - such as ``histogramdd((X, Y, Z))``. The first form should be preferred. |