def __processSparseMatrix(self, stream, matrixSize):
        from scipy.sparse import csc_matrix
        from serpentTools.parsers.base import CSCStreamProcessor

        cscProcessor = CSCStreamProcessor(stream, DEPMTX_REGEX, longfloat)
        line = cscProcessor.process()
        self.depmtx = csc_matrix(
            (cscProcessor.data[:,
                               0], cscProcessor.indices, cscProcessor.indptr),
            dtype=longfloat,
            shape=matrixSize)

        return line
Exemple #2
0
    def test_badRegex(self):
        """
        Verify that something with a search method can be used as the regex.
        """
        dummyStream = StringIO(u"Hello world\n")
        with self.assertRaises(AttributeError):
            CSCStreamProcessor(dummyStream, 1.0)

        class ObjWithSearchAttr(object):
            """Dummy object that contains a search attribute"""
            search = False

        with self.assertRaises(AttributeError):
            CSCStreamProcessor(dummyStream, ObjWithSearchAttr())
Exemple #3
0
class CSCStreamTester(TestCase):
    """
    Class for testing the CSCStreamProcessor.

    Matrices are 2x2 diagonal matrices for simplicity
    Therefore the underlying indices and index pointer
    vectors can be shared across all test cases
    """

    FINAL_LINE = u"THIS SHOULD BE THE FINAL LINE"

    EXP_INDPTR = array([0, 1, 2])
    EXP_INDICES = array([0, 1])

    def setUp(self):
        readable = StringIO(self.testString.lstrip() + self.FINAL_LINE)
        self.processor = CSCStreamProcessor(
            readable, self.regex, self.datatype)
        self.finalLine = self.processor.process()
        self.EXP_DATA = array(self.EXP_DATA_AS_LIST, self.datatype)

    def test_processor(self):
        """Verify the processor properly stores data in the CSC format"""
        self.assertEqual(self.finalLine, self.FINAL_LINE)
        assert_array_equal(self.processor.indptr, self.EXP_INDPTR)
        assert_array_equal(self.processor.indices, self.EXP_INDICES)
        assert_allclose(self.processor.data, self.EXP_DATA)
        # Convert a simple dtype, like float, to the numpy representation
        self.assertIs(self.processor.data.dtype, dtype(self.datatype))
Exemple #4
0
 def setUp(self):
     readable = StringIO(self.testString.lstrip() + self.FINAL_LINE)
     self.processor = CSCStreamProcessor(
         readable, self.regex, self.datatype)
     self.finalLine = self.processor.process()
     self.EXP_DATA = array(self.EXP_DATA_AS_LIST, self.datatype)