def make_node(self, activations, labels, input_lengths): t_activations = tt.as_tensor_variable(activations) # Ensure activations array is C-contiguous t_activations = cpu_contiguous(t_activations) t_labels = tt.as_tensor_variable(labels) t_input_lengths = tt.as_tensor_variable(input_lengths) if t_activations.type.dtype != "float32": raise TypeError("activations must use the float32 type!") if t_activations.ndim != 3: raise ValueError("activations must have 3 dimensions.") if t_labels.type.dtype != "int32": raise TypeError("labels must use the int32 type!") if t_labels.ndim != 2: raise ValueError("labels must have 2 dimensions.") if t_input_lengths.type.dtype != "int32": raise TypeError("input_lengths must use the int32 type!") if t_input_lengths.ndim != 1: raise ValueError("input_lengths must have 1 dimension.") costs = tt.fvector(name="ctc_cost") outputs = [costs] if self.compute_grad: gradients = tt.ftensor3(name="ctc_grad") outputs += [gradients] return gof.Apply( self, inputs=[t_activations, t_labels, t_input_lengths], outputs=outputs )
def make_node(self, a, b): a = aesara.tensor.as_tensor_variable(a) b = aesara.tensor.as_tensor_variable(b) assert a.type.dtype == "float32" assert a.type.dtype == b.type.dtype assert a.type.ndim == 2 r = gof.Apply(self, [a, b], [a.type()]) return r
def make_node(self, v): if not isinstance(v, gof.Variable): v = aesara.tensor.as_tensor_variable(v) assert v.type.ndim == 1 type_class = type(v.type) out_r_type = type_class(dtype=v.dtype, broadcastable=(True, False)) out_c_type = type_class(dtype=v.dtype, broadcastable=(False, True)) return gof.Apply(self, [v], [out_r_type(), out_c_type()])
def make_node(self): return gof.Apply( self, [], [ aesara.Variable(Generic()), tensor(self.dtype, broadcastable=self.broadcastable), ], )
def make_node(self, n, p, shape): n = tensor.as_tensor_variable(n) p = tensor.as_tensor_variable(p) shape = tensor.as_tensor_variable(shape) assert n.dtype in discrete_dtypes assert p.dtype in float_dtypes assert shape.dtype in discrete_dtypes return gof.Apply(self, [n, p, shape], [SparseType(dtype=self.dtype, format=self.format)()])
def make_node(self, r, shape, *args): """ Parameters ---------- r A numpy.random.RandomState instance, or a Variable of Type RandomStateType that will contain a RandomState instance. shape An lvector with a shape defining how many samples to draw. In the case of scalar distributions, it is the shape of the tensor output by this Op. In that case, at runtime, the value associated with this lvector must have a length equal to the number of dimensions promised by `self.outtype`. In a more general case, the number of output dimensions, len(self.outtype), is equal to len(shape)+self.ndim_added. The special case where len(shape) == 0 means that the smallest shape compatible with the argument's shape will be used. args The values associated with these variables will be passed to the RandomState function during perform as extra "*args"-style arguments. These should be castable to variables of Type TensorType. Returns ------- Apply Apply with two outputs. The first output is a gof.generic Variable from which to draw further random numbers. The second output is the outtype() instance holding the random draw. """ shape_ = tensor.as_tensor_variable(shape, ndim=1) if shape == (): shape = shape_.astype("int64") else: shape = shape_ assert shape.type.ndim == 1 assert (shape.type.dtype == "int64") or (shape.type.dtype == "int32") if not isinstance(r.type, RandomStateType): print( "WARNING: RandomState instances should be in RandomStateType", file=sys.stderr, ) # the following doesn't work because we want to ignore the # broadcastable flags in shape.type # assert shape.type == tensor.lvector # convert args to TensorType instances # and append enough None's to match the length of self.args args = list(map(tensor.as_tensor_variable, args)) return gof.Apply(self, [r, shape] + args, [r.type(), self.outtype()])
def make_node(self, *inputs): num_expected_inps = len(self.local_inputs) - len(self.shared_inputs) if len(inputs) != num_expected_inps: raise ValueError("Expected %d inputs, got %d" % (num_expected_inps, len(inputs))) inputs = [ inp_t.filter_variable(inp) for inp, inp_t in zip(inputs, self.input_types) ] apply_node = gof.Apply( self, list(inputs) + self.shared_inputs, [type() for type in self.output_types], ) apply_node.local_inputs = self.local_inputs apply_node.local_outputs = self.local_outputs return apply_node
def make_node(self, a, s=None): a = tt.as_tensor_variable(a) if a.ndim < 2: raise TypeError( "%s: input must have dimension > 2, with first dimension batches" % self.__class__.__name__ ) if s is None: s = a.shape[1:] s = tt.as_tensor_variable(s) else: s = tt.as_tensor_variable(s) if s.dtype not in tt.integer_dtypes: raise TypeError( "%s: length of the transformed axis must be" " of type integer" % self.__class__.__name__ ) return gof.Apply(self, [a, s], [self.output_type(a)()])
def make_node(self, a, s=None): a = tt.as_tensor_variable(a) if a.ndim < 3: raise TypeError( "%s: input must have dimension >= 3, with " % self.__class__.__name__ + "first dimension batches and last real/imag parts" ) if s is None: s = a.shape[1:-1] s = tt.set_subtensor(s[-1], (s[-1] - 1) * 2) s = tt.as_tensor_variable(s) else: s = tt.as_tensor_variable(s) if s.dtype not in tt.integer_dtypes: raise TypeError( "%s: length of the transformed axis must be" " of type integer" % self.__class__.__name__ ) return gof.Apply(self, [a, s], [self.output_type(a)()])
def make_node(self, a, n, axis): a = tensor.as_tensor_variable(a) if a.ndim < 1: raise TypeError("%s: input must be an array, not a scalar" % self.__class__.__name__) if axis is None: axis = a.ndim - 1 axis = tensor.as_tensor_variable(axis) else: axis = tensor.as_tensor_variable(axis) if axis.dtype not in tensor.integer_dtypes: raise TypeError("%s: index of the transformed axis must be" " of type integer" % self.__class__.__name__) elif axis.ndim != 0 or (isinstance(axis, tensor.TensorConstant) and (axis.data < 0 or axis.data > a.ndim - 1)): raise TypeError("%s: index of the transformed axis must be" " a scalar not smaller than 0 and smaller than" " dimension of array" % self.__class__.__name__) if n is None: n = a.shape[axis] n = tensor.as_tensor_variable(n) else: n = tensor.as_tensor_variable(n) if n.dtype not in tensor.integer_dtypes: raise TypeError("%s: length of the transformed axis must be" " of type integer" % self.__class__.__name__) elif n.ndim != 0 or (isinstance(n, tensor.TensorConstant) and n.data < 1): raise TypeError("%s: length of the transformed axis must be a" " strictly positive scalar" % self.__class__.__name__) return gof.Apply( self, [a, n, axis], [tensor.TensorType("complex128", a.type.broadcastable)()], )
def make_node(self, n, p): n = tensor.as_tensor_variable(n) p = as_sparse_variable(p) assert p.format in ["csr", "csc"] return gof.Apply(self, [n, p], [p.type()])
def make_node(self, request, data): return gof.Apply( self, [request, data], [tensor(data.dtype, broadcastable=data.broadcastable)], )
def make_node(self, a, b): c = a.type() d = a.type() return gof.Apply(self, [a, b], [c, d])
def make_node(self, x): x = as_sparse_variable(x) return gof.Apply(self, [x], [x.type()])
def make_node(self, a, b): c = b.type() return gof.Apply(self, [a, b], [c])
def make_node(self, a): a_ = aesara.tensor.as_tensor_variable(a) r = gof.Apply(self, [a_], [a_.type()]) return r
def make_node(self, path): if isinstance(path, str): path = Constant(Generic(), path) return gof.Apply( self, [path], [tensor(self.dtype, broadcastable=self.broadcastable)])
def make_node(self, *args): # HERE `args` must be THEANO VARIABLES return gof.Apply(op=self, inputs=args, outputs=[tensor.lscalar()])
def make_node(self, *inputs): outputs = [aesara.tensor.vector()] return gof.Apply(self, inputs, outputs)
def make_node(self, x): return gof.Apply(self, [x], [x.type()])
def make_node(self, data): return gof.Apply(self, [data], [aesara.Variable(Generic()), data.type()])
def make_node(self): inputs = [aesara.tensor.matrix()] outputs = [aesara.tensor.scalar(), aesara.tensor.scalar()] return gof.Apply(self, inputs, outputs)
def make_node(self, request, data): return gof.Apply(self, [request, data], [aesara.Variable(Generic())])