Package solvcon :: Package tests :: Module test_ctypes :: Class TestCtypesFortran
[hide private]
[frames] | no frames]

Class TestCtypesFortran

source code

       object --+    
                |    
unittest.TestCase --+
                    |
                   TestCtypesFortran

Test calling FORTRAN subroutine with scalars and arrays through ctypes.

_ctypes is the extension module generated by f2py. Without using the interface provided by f2py, the compiled FORTRAN subroutine can be accessed with ctypes.

It should be noted that FORTRAN subroutines are called by reference, i.e., all the arguements passed in are pointers. ctypes.byref should be used to access the subroutines.

Also, FORTRAN arrays are column-major while C arrays are row-major. The order of indices of arrays should be transposed while passed into subroutine.

Usually the symbol for FORTRAN subroutines in shared object files generated by compiler/linker is appended with an underscore.

Nested Classes [hide private]

Inherited from unittest.TestCase: failureException

Instance Methods [hide private]
 
setUp(self)
Set up shared objects generated by f2py.
source code
 
test_int(self)
Test for the 1D integer array.
source code
 
test_double(self)
Test for 2D double array.
source code
 
test_struct(self) source code

Inherited from unittest.TestCase: __call__, __eq__, __hash__, __init__, __ne__, __repr__, __str__, assertAlmostEqual, assertAlmostEquals, assertEqual, assertEquals, assertFalse, assertNotAlmostEqual, assertNotAlmostEquals, assertNotEqual, assertNotEquals, assertRaises, assertTrue, assert_, countTestCases, debug, defaultTestResult, fail, failIf, failIfAlmostEqual, failIfEqual, failUnless, failUnlessAlmostEqual, failUnlessEqual, failUnlessRaises, id, run, shortDescription, tearDown

Inherited from unittest.TestCase (private): _exc_info

Inherited from object: __delattr__, __format__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Instance Variables [hide private]
  a
one dimensional integer array.
  args
list of arguements for test FORTRAN subroutine.
  b
two dimensional double array.
  lib_c_ctypes
loaded shared object file.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

setUp(self)

source code 

Set up shared objects generated by f2py.

f2py generates standard .pyd shared object file on Windows while .so under Linux.

Overrides: unittest.TestCase.setUp

test_int(self)

source code 

Test for the 1D integer array.

FORTRAN subroutine adds each element with a random value, and after that the value is substracted in the following Python code.

test_double(self)

source code 

Test for 2D double array. Shape is also taken care.

FORTRAN subroutine adds each element with a random value and subtracts it from the first column. In the following Python code, the value is substracted from the remaining rows.