Exemplo n.º 1
0
def test_give_variables_names_small():
    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x)
    fgraph = theano.FunctionGraph((x, ), (y, ))
    give_variables_names(fgraph.variables)
    assert all(var.name for var in fgraph.variables)
    assert unique([var.name for var in fgraph.variables])
Exemplo n.º 2
0
def test_give_variables_names_small():
    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x)
    fgraph = theano.FunctionGraph((x,), (y,))
    give_variables_names(fgraph.variables)
    assert all(var.name for var in fgraph.variables)
    assert unique([var.name for var in fgraph.variables])
Exemplo n.º 3
0
def theano_graph_to_tuple_dag(i, o):
    """ Converts a theano.FunctionGraph into a tuple-dag

    This dag is of the form

        {(outputs): {'fn': fn, 'args': inputs}, ...}

    All keys are tuples

    This format is used when some functions create multiple outputs.
    It can be converted or simplified with functions in the root dag library.
    """
    i, o = theano.gof.graph.clone(i, o)
    variables = theano.gof.graph.variables(i, o)
    apply_nodes = theano.gof.graph.list_of_nodes(i, o)
    give_variables_names(variables)

    newvars = {var: clone(var) for var in variables}

    # Produces dag with inputs and outputs as tuples
    dag = {tuple(map(newvars.__getitem__, node.outputs)):
            {'fn'  : node.op,
             'args': tuple(map(newvars.__getitem__, node.inputs))}
             for node in apply_nodes}

    inputs  = tuple(map(newvars.__getitem__, i))
    outputs = tuple(map(newvars.__getitem__, o))

    return dag, inputs, outputs
Exemplo n.º 4
0
def test_give_variables_names():
    x = theano.tensor.matrix('x')
    y = x + 1
    z = theano.tensor.dot(x, y)
    variables = (x, y, z)
    give_variables_names(variables)
    assert all(var.name for var in variables)
    assert unique([var.name for var in variables])
Exemplo n.º 5
0
def test_give_variables_names():
    x = theano.tensor.matrix('x')
    y = x + 1
    z = theano.tensor.dot(x, y)
    variables = (x, y, z)
    give_variables_names(variables)
    assert all(var.name for var in variables)
    assert unique([var.name for var in variables])
Exemplo n.º 6
0
def test_give_variables_names_idempotence():
    x = theano.tensor.matrix('x')
    y = x + 1
    z = theano.tensor.dot(x, y)
    variables = (x, y, z)

    give_variables_names(variables)
    names = [var.name for var in variables]
    give_variables_names(variables)
    names2 = [var.name for var in variables]

    assert names == names2
Exemplo n.º 7
0
def test_give_variables_names_idempotence():
    x = theano.tensor.matrix('x')
    y = x + 1
    z = theano.tensor.dot(x, y)
    variables = (x, y, z)

    give_variables_names(variables)
    names = [var.name for var in variables]
    give_variables_names(variables)
    names2 = [var.name for var in variables]

    assert names == names2