Ejemplo n.º 1
0
    def test_resolution_dense(self):
        #- dense with no offsets specified
        data = np.random.uniform(size=(10, 10))
        R = Resolution(data)
        Rdense = R.todense()
        self.assertTrue(np.all(Rdense == data))

        #- with offsets
        offsets = np.arange(-2, 4)
        R = Resolution(data, offsets)
        Rdense = R.todense()
        for i in offsets:
            self.assertTrue(np.all(Rdense.diagonal(i) == data.diagonal(i)), \
                "diagonal {} doesn't match".format(i))

        #- dense without offsets but larger than default_ndiag
        ndiag = desispec.resolution.default_ndiag + 5
        data = np.random.uniform(size=(ndiag, ndiag))
        Rdense = Resolution(data).todense()

        for i in range(ndiag):
            if i <= desispec.resolution.default_ndiag // 2:
                self.assertTrue(np.all(Rdense.diagonal(i) == data.diagonal(i)), \
                    "diagonal {} doesn't match".format(i))
                self.assertTrue(np.all(Rdense.diagonal(-i) == data.diagonal(-i)), \
                    "diagonal {} doesn't match".format(-i))
            else:
                self.assertTrue(np.all(Rdense.diagonal(i) == 0.0), \
                    "diagonal {} not 0s".format(i))
                self.assertTrue(np.all(Rdense.diagonal(-i) == 0.0), \
                    "diagonal {} not 0s".format(-i))
Ejemplo n.º 2
0
    def test_resolution_dense(self):
        #- dense with no offsets specified
        data = np.random.uniform(size=(10,10))
        R = Resolution(data)
        Rdense = R.todense()
        self.assertTrue(np.all(Rdense == data))        

        #- with offsets
        offsets = np.arange(-2,4)
        R = Resolution(data, offsets)
        Rdense = R.todense()
        for i in offsets:
            self.assertTrue(np.all(Rdense.diagonal(i) == data.diagonal(i)), \
                "diagonal {} doesn't match".format(i))

        #- dense without offsets but larger than default_ndiag
        ndiag = desispec.resolution.default_ndiag + 5
        data = np.random.uniform(size=(ndiag, ndiag))
        Rdense = Resolution(data).todense()

        for i in range(ndiag):
            if i <= desispec.resolution.default_ndiag//2:
                self.assertTrue(np.all(Rdense.diagonal(i) == data.diagonal(i)), \
                    "diagonal {} doesn't match".format(i))
                self.assertTrue(np.all(Rdense.diagonal(-i) == data.diagonal(-i)), \
                    "diagonal {} doesn't match".format(-i))
            else:
                self.assertTrue(np.all(Rdense.diagonal(i) == 0.0), \
                    "diagonal {} not 0s".format(i))
                self.assertTrue(np.all(Rdense.diagonal(-i) == 0.0), \
                    "diagonal {} not 0s".format(-i))
Ejemplo n.º 3
0
    def test_resolution_sparsedia(self):
        data = np.random.uniform(size=(5, 10))
        offsets = np.arange(-2, 3)

        #- Original case: symetric and odd number of diagonals
        Rdia = scipy.sparse.dia_matrix((data, offsets), shape=(10, 10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Non symetric but still odd number of diagonals
        Rdia = scipy.sparse.dia_matrix((data, offsets + 1), shape=(10, 10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Even number of diagonals
        Rdia = scipy.sparse.dia_matrix((data[1:, :], offsets[1:]),
                                       shape=(10, 10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Unordered diagonals
        data = np.random.uniform(size=(5, 10))
        offsets = [0, 1, -1, 2, -2]

        Rdia = scipy.sparse.dia_matrix((data, offsets), shape=(10, 10))
        R1 = Resolution(Rdia)
        R2 = Resolution(data, offsets)
        self.assertTrue(np.all(R1.diagonal() == Rdia.diagonal()))
        self.assertTrue(np.all(R2.diagonal() == Rdia.diagonal()))
        self.assertTrue(np.all(R1.data == R2.data))
Ejemplo n.º 4
0
    def test_resolution_sparsedia(self):
        data = np.random.uniform(size=(5,10))
        offsets = np.arange(-2,3)

        #- Original case: symetric and odd number of diagonals
        Rdia = scipy.sparse.dia_matrix((data, offsets), shape=(10,10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Non symetric but still odd number of diagonals
        Rdia = scipy.sparse.dia_matrix((data, offsets+1), shape=(10,10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Even number of diagonals
        Rdia = scipy.sparse.dia_matrix((data[1:,:], offsets[1:]), shape=(10,10))
        R = Resolution(Rdia)
        self.assertTrue(np.all(R.diagonal() == Rdia.diagonal()))

        #- Unordered diagonals
        data = np.random.uniform(size=(5,10))
        offsets = [0,1,-1,2,-2]

        Rdia = scipy.sparse.dia_matrix((data, offsets), shape=(10,10))
        R1 = Resolution(Rdia)
        R2 = Resolution(data, offsets)
        self.assertTrue(np.all(R1.diagonal() == Rdia.diagonal()))
        self.assertTrue(np.all(R2.diagonal() == Rdia.diagonal()))
        self.assertTrue(np.all(R1.data == R2.data))