You should not mix the symbolic world with the numeric world.
When you have compiled a Theano function, you should give that function
only real values. So this line is bad:
e = f(x)
As f is a Theano function and x is a Theano variable. x must be some real
values.
Why do you compile 2 Theano function? From what I understand, you could
make only 1 function and call it twice.
Fred
On Tue, Apr 11, 2017 at 1:05 PM Vena Jia Li <[email protected]> wrote:
>
> Here are my code and error message. I have two functions since I want to
> call the NewOp in the middle, not directly providing input.
>
> import theano
> import theano.tensor as T
> import numpy as np
>
> class NewOp(theano.Op):
> __props__ = ()
>
> itypes = [theano.tensor.dmatrix]
> otypes = [theano.tensor.dmatrix]
>
> def perform(self, node, inputs, output_storage):
> x = inputs[0]
> z = output_storage[0]
> z[0] = x * 2
>
> def test():
> newop = NewOp()
> # x is a middle output which is generated from input
> x = theano.tensor.matrix()
> f = theano.function([x], NewOp()(x))
> # y and z are direct input data
> y = theano.tensor.matrix()
> z = theano.tensor.matrix()
> # Since x is generated using some complicated tensor operations, just
> use a simple example here.
> x = y + z
> e = f(x)
> y_input = np.random.rand(5, 4)
> z_input = np.random.rand(5, 4)
> anotherf = theano.function([y, z], e)
> output = anotherf(y_input, z_input)
> # I want to use the output for other things as well, so, I want to use
> e before generating the real ouput.
> print output
> print type(output)
> if __name__ == '__main__':
> test()
>
>
>
> 'Expected an array-like object, but found a Variable: '
> TypeError: ('Bad input argument to theano function with name
> "testop.py:20" at index 0(0-based)', 'Expected an array-like object, but
> found a Variable: maybe you are trying to call a function on a (possibly
> shared) variable instead of a numeric array?')
>
> Any thoughts?
>
> Thanks,
> Ven
>
> On Tue, Apr 11, 2017 at 9:56 AM, Frédéric Bastien <
> [email protected]> wrote:
>
> Without an error message, it is hard to help.
>
> I would suggest you to use as_op in Theano for this if you have difficulty
> with the Op interface. Both are equivalent, so you can continue with the Op
> interface:
>
>
> http://deeplearning.net/software/theano/extending/extending_theano.html#as-op
>
> On Mon, Apr 10, 2017 at 11:17 AM Vena Li <[email protected]> wrote:
>
> Hi,
>
> I want to call a Java function in my program. I am able to call it in
> python. It takes a numpy array as input and return a numpy array as output.
> However, I am having some difficulties to make it work in theano using
> tensor. I want to pass a tensor as a input, and after calling the function,
> I want another tensor returned. I will use the returned tensor for other
> operations. I was wondering is there an easy of doing so? I tried to use
> the "Creating a new Op:", but still not able to use the returned value.
>
> Thanks,
> Vena
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "theano-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "theano-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/theano-users/wcx9UI7F0Ao/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
>
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "theano-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.