def testFrexpExecution(self): data1 = np.random.random((5, 9, 4)) arr1 = tensor(data1.copy(), chunk_size=3) o1, o2 = frexp(arr1) o = o1 + o2 res = self.executor.execute_tensor(o, concat=True)[0] expected = sum(np.frexp(data1)) self.assertTrue(np.allclose(res, expected)) arr1 = tensor(data1.copy(), chunk_size=3) o1 = zeros(data1.shape, chunk_size=3) o2 = zeros(data1.shape, dtype='i8', chunk_size=3) frexp(arr1, o1, o2) o = o1 + o2 res = self.executor.execute_tensor(o, concat=True)[0] expected = sum(np.frexp(data1)) self.assertTrue(np.allclose(res, expected)) data1 = sps.random(5, 9, density=.1) arr1 = tensor(data1.copy(), chunk_size=3) o1, o2 = frexp(arr1) o = o1 + o2 res = self.executor.execute_tensor(o, concat=True)[0] expected = sum(np.frexp(data1.toarray())) np.testing.assert_equal(res.toarray(), expected)
def test_frexp_execution(setup): data1 = np.random.RandomState(0).random((5, 9, 4)) arr1 = tensor(data1.copy(), chunk_size=3) o1, o2 = frexp(arr1) o = o1 + o2 res = o.execute().fetch() expected = sum(np.frexp(data1)) np.testing.assert_array_almost_equal(res, expected) arr1 = tensor(data1.copy(), chunk_size=3) o1 = zeros(data1.shape, chunk_size=3) o2 = zeros(data1.shape, dtype='i8', chunk_size=3) frexp(arr1, o1, o2) o = o1 + o2 res = o.execute().fetch() expected = sum(np.frexp(data1)) np.testing.assert_array_almost_equal(res, expected, decimal=3) data1 = sps.random(5, 9, density=.1) arr1 = tensor(data1.copy(), chunk_size=3) o1, o2 = frexp(arr1) o = o1 + o2 res = o.execute().fetch() expected = sum(np.frexp(data1.toarray())) np.testing.assert_equal(res.toarray(), expected)
def testFrexpOrderExecution(self): data1 = np.random.random((5, 9)) t = tensor(data1, chunk_size=3) o1, o2 = frexp(t, order='F') res1, res2 = self.executor.execute_tileables([o1, o2]) expected1, expected2 = np.frexp(data1, order='F') np.testing.assert_allclose(res1, expected1) self.assertTrue(res1.flags['F_CONTIGUOUS']) self.assertFalse(res1.flags['C_CONTIGUOUS']) np.testing.assert_allclose(res2, expected2) self.assertTrue(res2.flags['F_CONTIGUOUS']) self.assertFalse(res2.flags['C_CONTIGUOUS'])
def test_frexp_order_execution(setup): data1 = np.random.random((5, 9)) t = tensor(data1, chunk_size=3) o1, o2 = frexp(t, order='F') res1, res2 = execute(o1, o2) expected1, expected2 = np.frexp(data1, order='F') np.testing.assert_allclose(res1, expected1) assert res1.flags['F_CONTIGUOUS'] is True assert res1.flags['C_CONTIGUOUS'] is False np.testing.assert_allclose(res2, expected2) assert res2.flags['F_CONTIGUOUS'] is True assert res2.flags['C_CONTIGUOUS'] is False
def test_frexp_order(): raw1 = np.asfortranarray(np.random.rand(2, 4)) t = tensor(raw1) o1 = tensor(np.random.rand(2, 4)) o1, o2 = frexp(t, out1=o1) assert o1.flags['C_CONTIGUOUS'] == np.frexp(raw1, np.empty( (2, 4)))[0].flags['C_CONTIGUOUS'] assert o1.flags['F_CONTIGUOUS'] == np.frexp(raw1, np.empty( (2, 4)))[0].flags['F_CONTIGUOUS'] assert o2.flags['C_CONTIGUOUS'] == np.frexp(raw1)[1].flags['C_CONTIGUOUS'] assert o2.flags['F_CONTIGUOUS'] == np.frexp(raw1)[1].flags['F_CONTIGUOUS']
def testFrexp(self): t1 = ones((3, 4, 5), chunk_size=2) t2 = empty((3, 4, 5), dtype=np.float_, chunk_size=2) op_type = type(t1.op) o1, o2 = frexp(t1) self.assertIs(o1.op, o2.op) self.assertNotEqual(o1.dtype, o2.dtype) o1, o2 = frexp(t1, t1) self.assertIs(o1, t1) self.assertIsNot(o1.inputs[0], t1) self.assertIsInstance(o1.inputs[0].op, op_type) self.assertIsNot(o2.inputs[0], t1) o1, o2 = frexp(t1, t2, where=t1 > 0) op_type = type(t2.op) self.assertIs(o1, t2) self.assertIsNot(o1.inputs[0], t1) self.assertIsInstance(o1.inputs[0].op, op_type) self.assertIsNot(o2.inputs[0], t1)
def test_frexp(): t1 = ones((3, 4, 5), chunk_size=2) t2 = empty((3, 4, 5), dtype=np.float_, chunk_size=2) op_type = type(t1.op) o1, o2 = frexp(t1) assert o1.op is o2.op assert o1.dtype != o2.dtype o1, o2 = frexp(t1, t1) assert o1 is t1 assert o1.inputs[0] is not t1 assert isinstance(o1.inputs[0].op, op_type) assert o2.inputs[0] is not t1 o1, o2 = frexp(t1, t2, where=t1 > 0) op_type = type(t2.op) assert o1 is t2 assert o1.inputs[0] is not t1 assert isinstance(o1.inputs[0].op, op_type) assert o2.inputs[0] is not t1
def testFrexpOrder(self): raw1 = np.asfortranarray(np.random.rand(2, 4)) t = tensor(raw1) o1 = tensor(np.random.rand(2, 4)) o1, o2 = frexp(t, out1=o1) self.assertEqual(o1.flags['C_CONTIGUOUS'], np.frexp(raw1, np.empty((2, 4)))[0].flags['C_CONTIGUOUS']) self.assertEqual(o1.flags['F_CONTIGUOUS'], np.frexp(raw1, np.empty((2, 4)))[0].flags['F_CONTIGUOUS']) self.assertEqual(o2.flags['C_CONTIGUOUS'], np.frexp(raw1)[1].flags['C_CONTIGUOUS']) self.assertEqual(o2.flags['F_CONTIGUOUS'], np.frexp(raw1)[1].flags['F_CONTIGUOUS'])