def set_shape(self): # Override. num_unique_words = self._metadata["num_unique_words"] self._shape = utilities.Shape(num_unique_words, 1) doc_idx = str(self._metadata["doc_idx"]) self._name = "w_" + doc_idx
def init_dcp_attr(self): shape = u.Shape(*intf.size(self.value)) # If scalar, check sign. Else unknown sign. if shape.size == (1, 1): sign = u.Sign.val_to_sign(self.value) else: sign = u.Sign.UNKNOWN self._dcp_attr = u.DCPAttr(sign, u.Curvature.CONSTANT, shape)
def init_dcp_attr(self): """Determines the curvature, sign, and shape from the arguments. """ sign = self.args[0].objective.args[0]._dcp_attr.sign if isinstance(self.args[0].objective, Minimize): curvature = u.curvature.Curvature.CONVEX elif isinstance(self.args[0].objective, Maximize): curvature = u.curvature.Curvature.CONCAVE else: raise Exception( ("You called partial_optimize with a Problem object that " "contains neither a Minimize nor a Maximize statement; " "this is not supported.")) self._dcp_attr = u.DCPAttr(sign, curvature, u.Shape(1, 1))
def set_shape(self): shape = () if self.has_val_map(): val = self._val_map.values()[0] if isinstance(val, int) or isinstance(val, float): shape = (1,1) elif isinstance(val, numpy.ndarray): numpy_shape = val.shape if len(numpy_shape) == 1: shape = (numpy_shape[0], 1) elif len(numpy_shape) == 2: shape = (numpy_shape[0], numpy_shape[1]) else: raise Exception(strings.BAD_RV_DIMS) else: raise Exception(strings.BAD_VAL_MAP) else: pymc_shape = () if isinstance(self._rv, pymc.CompletedDirichlet): pymc_shape = self._rv.parents["D"].shape else: pymc_shape = self._rv.shape if len(pymc_shape) == 0: shape = (1,1) elif len(pymc_shape) == 1: shape = (pymc_shape[0], 1) elif len(pymc_shape) == 2: shape = (pymc_shape[0], pymc_shape[1]) else: raise Exception(strings.BAD_RV_DIMS) self._shape = utilities.Shape(*shape)
def shape_from_args(self): """Returns the shape of the transpose expression. """ rows, cols = self.args[0].size return u.Shape(cols, rows)
def shape_from_args(self): """The sum of the argument dimensions - 1. """ lh_length = self.args[0].size[0] rh_length = self.args[1].size[0] return u.Shape(lh_length + rh_length - 1, 1)
def shape_from_args(self): """Always scalar. """ return u.Shape(1, 1)
def shape_from_args(self): """The sum of the argument dimensions - 1. """ rows = self.args[0].size[0] * self.args[1].size[0] cols = self.args[0].size[1] * self.args[1].size[1] return u.Shape(rows, cols)
def init_dcp_attr(self): shape = u.Shape(self._rows, self._cols) sign = u.Sign(self.sign_str) self._dcp_attr = u.DCPAttr(sign, u.Curvature.CONSTANT, shape)
def shape_from_args(self): """A square matrix. """ rows, _ = self.args[0].size return u.Shape(rows, rows)
def shape_from_args(self): """A column vector. """ rows, _ = self.args[0].size return u.Shape(rows, 1)
def shape_from_args(self): """Returns the shape of the index expression. """ return u.Shape(*ku.size(self.key, self.args[0]._dcp_attr.shape))
def shape_from_args(self): cols = sum(arg.size[1] for arg in self.args) rows = self.args[0].size[0] return u.Shape(rows, cols)
def init_dcp_attr(self): """Override. """ self._dcp_attr = utils.DCPAttr(utils.Sign.POSITIVE, utils.Curvature.AFFINE, utils.Shape(self._rows, self._cols))
def init_dcp_attr(self): shape = u.Shape(*intf.size(self.value)) sign = intf.sign(self.value) self._dcp_attr = u.DCPAttr(sign, u.Curvature.CONSTANT, shape)
def shape_from_args(self): return u.Shape(1, 1)
def shape_from_args(self): """Resolves to a scalar. """ return u.Shape(1, 1)
def shape_from_args(self): """A vector. """ rows, cols = self.args[0].size return u.Shape(rows * (cols - 1) // 2, 1)
def shape_from_args(self): """Returns the shape from the rows, cols arguments. """ return u.Shape(self.rows, self.cols)
def shape_from_args(self): """The sum of the argument dimensions - 1. """ return u.Shape(self.args[0].size[0] + self.args[1].size[0] - 1, self.args[0].size[1] + self.args[1].size[1] - 1)