def setUp(self): super().setUp() try: self.enter_context(matrix.backend(self.backend)) except matrix.BackendNotAvailable: self.skipTest('backend is unavailable') self.exact = 2 * numpy.eye(self.n) - numpy.eye(self.n, self.n, -1) - numpy.eye(self.n, self.n, +1) data = sparse.prune(sparse.fromarray(self.exact), inplace=True) assert len(data) == self.n*3-2 self.matrix = matrix.fromsparse(data, inplace=True)
def setUp(self): super().setUp() self._backend = matrix.backend(self.backend) self._backend.__enter__() r = numpy.arange(self.n) index = numpy.concatenate([[r, r], [r[:-1], r[1:]], [r[1:], r[:-1]]], axis=1) data = numpy.hstack([2.] * self.n + [-1.] * (2*self.n-2)) self.matrix = matrix.assemble(data, index, shape=(self.n, self.n)) self.exact = 2 * numpy.eye(self.n) - numpy.eye(self.n, self.n, -1) - numpy.eye(self.n, self.n, +1) self.tol = self.args.get('atol', 1e-10)
def test_pickle(self): s = pickle.dumps(self.matrix) mat = pickle.loads(s) self.assertIsInstance(mat, type(self.matrix)) numpy.testing.assert_equal(mat.export('dense'), self.exact) with self.subTest('cross-pickle'), matrix.backend('Numpy'): mat = pickle.loads(s) from nutils.matrix._numpy import NumpyMatrix self.assertIsInstance(mat, NumpyMatrix) numpy.testing.assert_equal(mat.export('dense'), self.exact)
def setUp(self): super().setUp() self._backend = matrix.backend(self.backend) self._backend.__enter__() r = numpy.arange(self.n) index = numpy.concatenate([[r, r], [r[:-1], r[1:]], [r[1:], r[:-1]]], axis=1) data = numpy.hstack([2.] * self.n + [-1.] * (2 * self.n - 2)) self.matrix = matrix.assemble(data, index, shape=(self.n, self.n)) self.exact = 2 * numpy.eye(self.n) - numpy.eye( self.n, self.n, -1) - numpy.eye(self.n, self.n, +1) self.tol = self.args.get('atol', 1e-10)