Did I find the right examples for you? yes no

All Samples(18)  |  Call(15)  |  Derive(0)  |  Import(3)
Create Theano function from SymPy expressions 

        def theano_function(inputs, outputs, dtypes={}, cache=None, **kwargs):
    """ Create Theano function from SymPy expressions """
    cache = {} if cache == None else cache
    broadcastables = dim_handling(inputs, **kwargs)

    # Remove keyword arguments corresponding to dim_handling
    dim_names = inspect.getargspec(dim_handling)[0]
    theano_kwargs = dict((k, v) for k, v in kwargs.items()
                                if k not in dim_names)

    code = partial(theano_code, cache=cache, dtypes=dtypes,
                   broadcastables=broadcastables)
    tinputs  = list(map(code, inputs))
    toutputs = list(map(code, outputs))
    toutputs = toutputs[0] if len(toutputs) == 1 else toutputs
    return theano.function(tinputs, toutputs, **theano_kwargs)
        


src/p/y/pydy-code-gen-0.1.0/pydy_code_gen/code.py   pydy-code-gen(Download)
from sympy import lambdify, numbered_symbols, cse, symbols
from sympy.printing.ccode import CCodePrinter
from sympy.printing.theanocode import theano_function
 
# internal libraries
        elif generator == 'theano':
 
            mass_matrix_func = theano_function(arguments, [mass_matrix],
                                               on_unused_input='ignore')
            forcing_vector_func = theano_function(arguments,

src/s/y/sympy-0.7.5/sympy/printing/tests/test_theanocode.py   sympy(Download)
sy = sympy
from sympy.abc import x, y, z, a, b, c
from sympy.printing.theanocode import (theano_code, dim_handling,
        theano_function)
 
def test_theano_function_simple():
    f = theano_function([x, y], [x+y])
    assert f(2, 3) == 5
 
def test_theano_function_numpy():
    f = theano_function([x, y], [x+y], dim=1,
                        dtypes={x: 'float64', y: 'float64'})
    assert np.linalg.norm(f([1, 2], [3, 4]) - np.asarray([4, 6])) < 1e-9
 
    f = theano_function([x, y], [x+y], dtypes={x: 'float64', y: 'float64'},
def test_theano_function_kwargs():
    import numpy as np
    f = theano_function([x, y, z], [x+y], dim=1, on_unused_input='ignore',
            dtypes={x: 'float64', y: 'float64', z: 'float64'})
    assert np.linalg.norm(f([1, 2], [3, 4], [0, 0]) - np.asarray([4, 6])) < 1e-9

src/s/y/sympy-HEAD/sympy/printing/tests/test_theanocode.py   sympy(Download)
sy = sympy
from sympy.abc import x, y, z, a, b, c
from sympy.printing.theanocode import (theano_code, dim_handling,
        theano_function)
 
def test_theano_function_simple():
    f = theano_function([x, y], [x+y])
    assert f(2, 3) == 5
 
 
def test_theano_function_numpy():
    import numpy as np
    f = theano_function([x, y], [x+y], dim=1)
    assert np.linalg.norm(f([1, 2], [3, 4]) - np.asarray([4, 6])) < 1e-9
 
    f = theano_function([x, y], [x+y], dtypes={x: 'float64', y: 'float64'},
                                     dim=1)
    xx = np.arange(3).astype('float64')
 
    dtypes = dict(zip(inputs, [dtype]*len(inputs)))
    f = theano_function(inputs, [output], dtypes=dtypes)
    fblocked = theano_function(inputs, [sympy.block_collapse(cutoutput)],
                               dtypes=dtypes)