Beispiel #1
0
 def testBlkDiagMatrixCompat(self):
     """ Check incompatible matrix raises exception. """
     # Create a differently shaped matrix
     x = BlkDiagMatrix.from_list(self.blk_a[1:-1])
     # code should raise
     with pytest.raises(RuntimeError):
         _ = x + self.blk_a
    def setUp(self):

        self.num_blks = 10

        self.blk_partition = [(i, i) for i in range(self.num_blks, 0, -1)]
        self.dense_shape = np.sum(self.blk_partition, axis=0)

        n = np.sum(np.prod(np.array(self.blk_partition), axis=1))
        self.flat = np.arange(n)
        self.revflat = self.flat[::-1].copy()

        diag_ind = np.array([0, 0])
        ind = 0
        zeros = []
        ones = []
        eyes = []
        A = []
        B = []
        self.dense = np.zeros(self.dense_shape)
        for blk_shp in self.blk_partition:
            zeros.append(np.zeros(blk_shp))
            ones.append(np.ones(blk_shp))
            eyes.append(np.eye(blk_shp[0]))

            offt = np.prod(blk_shp)
            blk = self.flat[ind : ind + offt].reshape(blk_shp)
            A.append(blk)
            B.append(self.revflat[ind : ind + offt].reshape(blk_shp))

            ind += offt

            # Also build a dense array.
            self.dense[
                diag_ind[0] : diag_ind[0] + blk_shp[0],
                diag_ind[1] : diag_ind[1] + blk_shp[1],
            ] = blk
            diag_ind += blk_shp

        self.blk_a = BlkDiagMatrix.from_list(A)
        self.blk_b = BlkDiagMatrix.from_list(B)
        self.blk_zeros = BlkDiagMatrix.from_list(zeros)
        self.blk_ones = BlkDiagMatrix.from_list(ones)
        self.blk_eyes = BlkDiagMatrix.from_list(eyes)