daredare.extern.toolkithelpers.octave4numpy

Package daredare :: Package extern :: Module toolkithelpers :: Class octave4numpy |
[hide private]
[frames] | no frames]

# Class octave4numpy

source code

    Lets octave functions calculate things, collects results as numpy-matrices.

    Example usage qz decomposition with octave syntax
     [AA,BB,Q,Z,V,W,lambda] = qz(A,B):

    1) "session approach"
    myoct = octave4numpy()
    myoct.definemats(['A', 'B'], [a, b])    # a and b: numpy arrays/matrices
    (AA,BB,Q,Z,V,W,lda) = myoct.execfunc('qz', ['A', 'B'], 7)
    # (7 is the number of returned objects, must be specified here in advance!)
    # (possibly execute other funcs after this)
    myoct.close()

    2) or the "shortcut approach", quick way for one-time use:
    myoct = octave4numpy('qz', (a, b), 7)
    (AA,BB,Q,Z,V,W,lda) = myoct.results
    # (connection to octave is automatically closed in this variant)

    If something else than 'octave' is needed to invoke your octave version,
      specify the command string in optional keyword arg cmd, like so:
    myoct = octave4numpy(cmd = 'octave2.0')

    The user should not pass 1d-numpy-arrays; be explicit about row or col!

    to do:
    - test on windows
    - allow to set precision
    - test if it also works with complex numbers (it should)
    ...

Instance Methods | [hide private]
__init__(self, func=None, args=None, numout=1, cmd=`'``octave``'`) opens the octave connection via pipes (is this really cross-platform?) | source code
definemats(self, namelist, mlist) transfers matrices (values, can be 1x1) to octave for further use | source code
getreaction(self, items=1) parse (and thereby chop off) octave's stdout | source code
octstr2nmat(self, octstring) creates numpy matrix from octave's matrix printout | source code
execfunc(self, funcname, argnames, numout=1) executes an octave function call and returns matrix results | source code
close(self) | source code

Method Details | [hide private]

### __init__(self, func=None, args=None, numout=1, cmd=`'``octave``'`) (Constructor) | source code
    opens the octave connection via pipes (is this really cross-platform?)

    optionally already executes a function for quick use, func is the name
     of an octave function; then assignments must match the number of return
     objects from that specific octave function

### definemats(self, namelist, mlist) | source code
    transfers matrices (values, can be 1x1) to octave for further use

    names must be valid denominator strings

    examples:
    myoct.definemats('a', m)
    myoct.definemats(['a', 'b'], [m1, m2])

    (since octave also accepts j for imaginary parts, should also work for
     complex numbers)

### getreaction(self, items=1) | source code
parse (and thereby chop off) octave's stdout Converting the string to a numpy matrix is left to another method.

### octstr2nmat(self, octstring) | source code
creates numpy matrix from octave's matrix printout only one matrix per call should be passed

### execfunc(self, funcname, argnames, numout=1) | source code
    executes an octave function call and returns matrix results

    For example, the octave function [AA,BB,Q,Z,V,W] = qz(A,B) would be
     called by
     (a, b, q, z, v, w) = myoctconn.exefunc('qz', ['myA', 'myB'], 6)

    The arg names must be given as strings, and must have been defined in
     octave before with definemats.

    If there's only one arg, it is admissible to provide just one arg string
     instead of an 1-element list