Theano broadcasting is hardcoded in the Theano graph. You will need to build 2 nodes and probably compile 2 Theano function for that.
If you would like to have a partially working version that don't hardcode in the graph the number of dimensions, you could have the inputs/outputs of the nodes that changes be a Generic() variable instead of a TensorVariable. But you won't have any operation working on it. Fred On Fri, Apr 28, 2017 at 7:10 PM Brad Buran <bbu...@gmail.com> wrote: > Given the following function where: > > - y is a ND array > - g has one less dimension than y > - x is a 1D array > - the result is the same number of dimensions as g > > How do I write a Theano operation that wraps this function? I can get it > to work for the case where y is a 1D array and g is a scalar (see below). > However, when y is a 2D array, I get the following error. I understand why > I'm getting the error, but I'm not clear how to write a more suitably > polymorphic function that can handle broadcasting. Any pointers would be > appreciated. > > TypeError: We expected inputs of types '[TensorType(float64, vector), > TensorType(float64, scalar)]' but got types '[TensorType(float64, matrix), > TensorType(float64, vector)]' > > > class Threshold(theano.Op): > > __props__ = ('threshold', 'lower', 'upper', 'step') > > itypes = [theano.tensor.dvector, theano.tensor.dscalar] > otypes = [theano.tensor.dscalar] > > def __init__(self, threshold, lower, upper, step): > self.threshold = threshold > self.lower = lower > self.upper = upper > self.step = step > self.x = np.arange(lower, upper, step) > super().__init__() > > def perform(self, node, inputs, output_storage): > y = inputs[0] > g = inputs[1] > z = output_storage[0] > > y = norm.ppf(y)-norm.ppf(g) > fx = lambda y: np.interp([1], y, x)[0] > z[0] = np.apply_along_axis(fx, 0, y) > > > -- > > --- > 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 theano-users+unsubscr...@googlegroups.com. > 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 theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.