def make_node(self, *inputs): inputs = list(map(as_variable, inputs)) for input in inputs: if not isinstance(input.type, MyType): raise Exception("Error 1") outputs = [MyType(sum([input.type.thingy for input in inputs]))()] return Apply(self, inputs, outputs)
def make_node(self, img, topgrad, shape=None): img = as_tensor_variable(img) topgrad = as_tensor_variable(topgrad) img, topgrad = self.as_common_dtype(img, topgrad) if img.type.ndim != 5: raise TypeError("img must be 5D tensor") if topgrad.type.ndim != 5: raise TypeError("topgrad must be 5D tensor") if shape is None: if self.subsample != (1, 1, 1) or self.border_mode == "half": raise ValueError( "shape must be given if subsample != (1, 1, 1)" ' or border_mode == "half"') height_width_depth = [] else: height_width_depth = [ as_tensor_variable(shape[0]).astype("int64"), as_tensor_variable(shape[1]).astype("int64"), as_tensor_variable(shape[2]).astype("int64"), ] broadcastable = [ topgrad.type.broadcastable[1], img.type.broadcastable[1], False, False, False, ] dtype = img.type.dtype return Apply( self, [img, topgrad] + height_width_depth, [TensorType(dtype, broadcastable)()], )
def make_node(self, x, scale, bias, estimated_mean, estimated_variance, epsilon=1e-4): x = as_tensor_variable(x) scale = as_tensor_variable(scale) bias = as_tensor_variable(bias) estimated_mean = as_tensor_variable(estimated_mean) estimated_variance = as_tensor_variable(estimated_variance) epsilon = as_tensor_variable(epsilon) # Upcast to common dtype on the non-scalar # Keep as is dtype of scalar (epsilon) x, scale, bias, estimated_mean, estimated_variance = as_common_dtype( x, scale, bias, estimated_mean, estimated_variance) assert (x.ndim == scale.ndim == bias.ndim == estimated_mean.ndim == estimated_variance.ndim) return Apply( self, [x, scale, bias, estimated_mean, estimated_variance, epsilon], [x.type()], )
def make_node(self, *inputs): assert len(inputs) == self.nin inputs = [as_variable(i) for i in inputs] for input in inputs: if input.type is not tdouble: raise Exception("Error 1") outputs = [double(self.name + "_R")] return Apply(self, inputs, outputs)
def make_node(self, *inputs): assert len(inputs) == self.nin inputs = list(map(as_variable, inputs)) for input in inputs: if not isinstance(input.type, MyType): raise Exception("Error 1") outputs = [MyVariable(self.name + "_R") for i in range(self.nout)] return Apply(self, inputs, outputs)
def make_node(self, o, x, y, xIdx, yIdx, alpha=None): """ Compute the dot product of the specified pieces of vectors and matrices. The parameter types are actually their expected shapes relative to each other. Parameters ---------- o : xBlocks, yBlocks, xSize, ySize x : batch, xWin, xSize y : batch, yWin, ySize xIdx : batch, iWin indexes of the x blocks yIdx : batch, oWin indexes of the y blocks Returns ------- (xBlocks, yBlocks, xSize, ySize) outer(x[i], y[j]) + o[i, j] Notes ----- - `batch` is the number of examples in a minibatch (batch size). - `xBlocks` is the total number of blocks in x. - `xSize` is the size of each of these x blocks. - `xWin` is the number of blocks that will be used as x. Which blocks will be used is specified in `xIdx`. - `yBlocks` is the number or possible y blocks. - `ySize` is the size of each of these y blocks. - `yWin` is the number of y blocks that will actually be computed. Which blocks will be computed is specified in `yIdx`. """ one = aesara.tensor.constant(np.asarray(1.0, dtype="float32")) o = aesara.tensor.as_tensor_variable(o) x = aesara.tensor.as_tensor_variable(x) y = aesara.tensor.as_tensor_variable(y) if alpha is None: alpha = one return Apply(self, [o, x, y, xIdx, yIdx, alpha], [o.type()])
def make_node(self, img, kern): img = as_tensor_variable(img) kern = as_tensor_variable(kern) img, kern = self.as_common_dtype(img, kern) if img.type.ndim != 5: raise TypeError("img must be 5D tensor") if kern.type.ndim != 5: raise TypeError("kern must be 5D tensor") broadcastable = [ img.type.broadcastable[0], kern.type.broadcastable[0], False, False, False, ] dtype = img.type.dtype return Apply(self, [img, kern], [TensorType(dtype, broadcastable)()])
def make_node(self, x, dy, scale, x_mean, x_invstd, epsilon=1e-4): x = as_tensor_variable(x) dy = as_tensor_variable(dy) scale = as_tensor_variable(scale) x_mean = as_tensor_variable(x_mean) x_invstd = as_tensor_variable(x_invstd) epsilon = as_tensor_variable(epsilon) # Upcast to common dtype on the non-scalar # Keep as is dtype of scalar (epsilon) x, dy, scale, x_mean, x_invstd = as_common_dtype( x, dy, scale, x_mean, x_invstd) assert x.ndim == dy.ndim == scale.ndim == x_mean.ndim == x_invstd.ndim return Apply( self, [x, dy, scale, x_mean, x_invstd, epsilon], [x.type(), scale.type(), scale.type()], )
def make_node( self, x, scale, bias, epsilon=1e-4, running_average_factor=0.1, running_mean=None, running_var=None, ): x = as_tensor_variable(x) scale = as_tensor_variable(scale) bias = as_tensor_variable(bias) epsilon = as_tensor_variable(epsilon) running_average_factor = as_tensor_variable(running_average_factor) if running_mean is not None: running_mean = as_tensor_variable(running_mean) if running_var is not None: running_var = as_tensor_variable(running_var) assert x.ndim == scale.ndim == bias.ndim assert (running_mean is None and running_var is None) or (running_mean is not None and running_var is not None) assert running_mean is None or running_mean.ndim == x.ndim assert running_var is None or running_var.ndim == x.ndim # Upcast to common dtype on the non-scalar # Keep as is dtype of scalar (epsilon and running_average_factor) if running_mean: x, scale, bias, running_mean, running_var = as_common_dtype( x, scale, bias, running_mean, running_var) else: x, scale, bias = as_common_dtype(x, scale, bias) inputs = [x, scale, bias, epsilon, running_average_factor] output_types = [x.type(), scale.type(), scale.type()] if running_mean is not None and running_var is not None: inputs.append(running_mean) inputs.append(running_var) output_types.append(scale.type()) output_types.append(scale.type()) return Apply(self, inputs, output_types)
def make_node(self, kern, topgrad, shape=None): kern = as_tensor_variable(kern) topgrad = as_tensor_variable(topgrad) kern, topgrad = self.as_common_dtype(kern, topgrad) if kern.type.ndim != 5: raise TypeError("kern must be 5D tensor") if topgrad.type.ndim != 5: raise TypeError("topgrad must be 5D tensor") if shape is None: if self.subsample != (1, 1, 1): raise ValueError( "shape must be given if subsample != (1, 1, 1)") height_width_depth = [] else: height_width_depth = [ as_tensor_variable(shape[0]).astype("int64"), as_tensor_variable(shape[1]).astype("int64"), as_tensor_variable(shape[2]).astype("int64"), ] if self.num_groups > 1: broadcastable = [ topgrad.type.broadcastable[0], False, False, False, False ] else: broadcastable = [ topgrad.type.broadcastable[0], kern.type.broadcastable[1], False, False, False, ] dtype = kern.type.dtype return Apply( self, [kern, topgrad] + height_width_depth, [TensorType(dtype, broadcastable)()], )
def make_node(self, i): return Apply(self, [i], [scalar.uint64()])
def make_node(self): return Apply(self, [], [MyType("test")()])
def make_node(self, input): input = scalar.as_scalar(input) output = input.type() return Apply(self, [input], [output])
def make_node(self, o, W, h, inputIdx, outputIdx): """ Compute the dot product of the specified pieces of vectors and matrices. The parameter types are actually their expected shapes relative to each other. Parameters ---------- o : batch, oWin, oSize output vector W : iBlocks, oBlocks, iSize, oSize weight matrix h : batch, iWin, iSize input from lower layer (sparse) inputIdx : batch, iWin indexes of the input blocks outputIdx : batch, oWin indexes of the output blocks Returns ------- (batch, oWin, oSize) dot(W[i, j], h[i]) + o[j] Notes ----- - `batch` is the number of examples in a minibatch (batch size). - `iBlocks` is the total number of blocks in the input (from lower layer). - `iSize` is the size of each of these input blocks. - `iWin` is the number of blocks that will be used as inputs. Which blocks will be used is specified in `inputIdx`. - `oBlocks` is the number or possible output blocks. - `oSize` is the size of each of these output blocks. - `oWin` is the number of output blocks that will actually be computed. Which blocks will be computed is specified in `outputIdx`. """ o = aesara.tensor.as_tensor_variable(o) W = aesara.tensor.as_tensor_variable(W) h = aesara.tensor.as_tensor_variable(h) inputIdx = aesara.tensor.as_tensor_variable(inputIdx) outputIdx = aesara.tensor.as_tensor_variable(outputIdx) if o.ndim != 3: raise TypeError("The output o must be a 2D tensor") if W.ndim != 4: raise TypeError("The weight matrix W must be a 4D tensor") if h.ndim != 3: raise TypeError("The input h must be a 3D tensor") if inputIdx.ndim != 2: raise TypeError("The input indices inputIdx must be a 2D tensor") if outputIdx.ndim != 2: raise TypeError("The output indices outputIdx must be a 2D tensor") assert inputIdx.type.dtype in discrete_dtypes assert outputIdx.type.dtype in discrete_dtypes return Apply(self, [o, W, h, inputIdx, outputIdx], [o.type()])