Exemplo n.º 1
0
    def mat_shape(self):
        """Get the shape of the represented matrix."""

        self.check_rows_cols()
        helpers.check_axis_names(self)
        nrows = 1

        for axis in self.rows:
            nrows *= self.shape[axis]

        ncols = 1

        for axis in self.cols:
            ncols *= self.shape[axis]

        return (nrows, ncols)
Exemplo n.º 2
0
    def mat_shape(self):
        """Get the shape of the represented matrix."""

        self.check_rows_cols()
        helpers.check_axis_names(self)
        nrows = 1

        for axis in self.rows:
            nrows *= self.shape[axis]

        ncols = 1

        for axis in self.cols:
            ncols *= self.shape[axis]

        return (nrows, ncols)
Exemplo n.º 3
0
    def __setattr__(self, name, value):
        if name == 'axes':
            helpers.check_axis_names(self, value)
            self.info['axes'] = value
        elif name == 'rows':
            for ind in value:
                if ind not in range(self.ndim):
                    raise ValueError("Invalid row axes.")

            self.info['rows'] = tuple(value)
        elif name == 'cols':
            for ind in value:
                if ind not in range(self.ndim):
                    raise ValueError("Invalid col axes.")

            self.info['cols'] = tuple(value)
        else:
            self.info_base.__setattr__(self, name, value)
Exemplo n.º 4
0
    def __setattr__(self, name, value):
        if name == 'axes':
            helpers.check_axis_names(self, value)
            self.info['axes'] = value
        elif name == 'rows':
            for ind in value:
                if ind not in range(self.ndim):
                    raise ValueError("Invalid row axes.")

            self.info['rows'] = tuple(value)
        elif name == 'cols':
            for ind in value:
                if ind not in range(self.ndim):
                    raise ValueError("Invalid col axes.")

            self.info['cols'] = tuple(value)
        else:
            self.info_base.__setattr__(self, name, value)
Exemplo n.º 5
0
    def __new__(cls,
                input_array,
                row_axes=None,
                col_axes=None,
                axis_names=None):

        if not isinstance(input_array, cls.info_base):
            raise ValueError("Array to convert must be instance of " +
                             str(cls.info_base))

        obj = input_array.view(cls)

        if 'type' in obj.info:
            if axis_names is not None or \
               row_axes is not None or \
               col_axes is not None:

                warnings.warn("Initialization argument ignored. Requisite "
                              "metadata for matrix already exists. "
                              "Clear info dictionary if you want opposite "
                              "behaviour.")

            if obj.info['type'] != 'mat':
                raise ValueError("Meta data present is incompatible.")
            helpers.check_axis_names(obj)
            helpers.check_rows_cols(obj)
        else:
            if row_axes is None and \
               col_axes is None and \
               (input_array.ndim == 2):

                row_axes = (0, )
                col_axes = (1, )
            else:
                helpers.check_rows_cols(input_array, row_axes, col_axes)
            helpers.set_type_axes(obj, 'mat', axis_names)
            obj.rows = row_axes
            obj.cols = col_axes
        return obj
Exemplo n.º 6
0
    def __new__(cls, input_array, axis_names=None):
        if not isinstance(input_array, cls.info_base):
            raise ValueError("Array to convert must be instance of " +
                             str(cls.info_base))

        obj = input_array.view(cls)

        if 'type' in obj.info:
            if axis_names is not None:
                warnings.warn("Initialization argument ignored. Requisite "
                              "metadata for vector already exists. "
                              "Clear info dictionary if you want opposite "
                              "behaviour.")

            if obj.info['type'] != 'vect':
                raise ValueError("Meta data present is incompatible.")

            helpers.check_axis_names(obj)

        else:
            helpers.set_type_axes(obj, 'vect', axis_names)

        return obj
Exemplo n.º 7
0
    def __new__(cls, input_array, axis_names=None):
        if not isinstance(input_array, cls.info_base):
            raise ValueError("Array to convert must be instance of " +
                             str(cls.info_base))

        obj = input_array.view(cls)

        if 'type' in obj.info:
            if axis_names is not None:
                warnings.warn("Initialization argument ignored. Requisite "
                              "metadata for vector already exists. "
                              "Clear info dictionary if you want opposite "
                              "behaviour.")

            if obj.info['type'] != 'vect':
                raise ValueError("Meta data present is incompatible.")

            helpers.check_axis_names(obj)

        else:
            helpers.set_type_axes(obj, 'vect', axis_names)

        return obj
Exemplo n.º 8
0
    def __new__(cls, input_array, row_axes=None, col_axes=None,
                axis_names=None):

        if not isinstance(input_array, cls.info_base):
            raise ValueError("Array to convert must be instance of " +
                             str(cls.info_base))

        obj = input_array.view(cls)

        if 'type' in obj.info:
            if axis_names is not None or \
               row_axes is not None or \
               col_axes is not None:

                warnings.warn("Initialization argument ignored. Requisite "
                              "metadata for matrix already exists. "
                              "Clear info dictionary if you want opposite "
                              "behaviour.")

            if obj.info['type'] != 'mat':
                raise ValueError("Meta data present is incompatible.")
            helpers.check_axis_names(obj)
            helpers.check_rows_cols(obj)
        else:
            if row_axes is None and \
               col_axes is None and \
               (input_array.ndim == 2):

                row_axes = (0,)
                col_axes = (1,)
            else:
                helpers.check_rows_cols(input_array, row_axes, col_axes)
            helpers.set_type_axes(obj, 'mat', axis_names)
            obj.rows = row_axes
            obj.cols = col_axes
        return obj
Exemplo n.º 9
0
 def __setattr__(self, name, value):
     if name == 'axes':
         helpers.check_axis_names(self, value)
         self.info['axes'] = value
     else:
         self.info_base.__setattr__(self, name, value)
Exemplo n.º 10
0
 def mat_shape(self):
     """Get the shape of the represented matrix (vector)."""
     helpers.check_axis_names(self)
     return (self.size, )
Exemplo n.º 11
0
 def __setattr__(self, name, value):
     if name == 'axes':
         helpers.check_axis_names(self, value)
         self.info['axes'] = value
     else:
         self.info_base.__setattr__(self, name, value)
Exemplo n.º 12
0
 def mat_shape(self):
     """Get the shape of the represented matrix (vector)."""
     helpers.check_axis_names(self)
     return (self.size,)