def testEmptyExecution(self): t = empty((20, 30), dtype='i8', chunk_size=5) res = self.executor.execute_tensor(t, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.int64) t = empty((20, 30), chunk_size=5) res = self.executor.execute_tensor(t, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.float64) t2 = empty_like(t) res = self.executor.execute_tensor(t2, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.float64) t = empty((20, 30), dtype='i8', chunk_size=5, order='F') res = self.executor.execute_tensor(t, concat=True)[0] expected = np.empty((20, 30), dtype='i8', order='F') self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS']) self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS'])
def testStackExecution(self): raw = [np.random.randn(3, 4) for _ in range(10)] arrs = [tensor(a, chunk_size=3) for a in raw] arr2 = stack(arrs) res = self.executor.execute_tensor(arr2, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw))) arr3 = stack(arrs, axis=1) res = self.executor.execute_tensor(arr3, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=1))) arr4 = stack(arrs, axis=2) res = self.executor.execute_tensor(arr4, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=2))) raw2 = [np.asfortranarray(np.random.randn(3, 4)) for _ in range(10)] arr5 = [tensor(a, chunk_size=3) for a in raw2] arr6 = stack(arr5) res = self.executor.execute_tensor(arr6, concat=True)[0] expected = np.stack(raw2).copy('A') np.testing.assert_array_equal(res, expected) self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS']) self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS']) arr7 = stack(arr5, out=empty((10, 3, 4), order='F')) res = self.executor.execute_tensor(arr7, concat=True)[0] expected = np.stack(raw2, out=np.empty((10, 3, 4), order='F')).copy('A') np.testing.assert_array_equal(res, expected) self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS']) self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS'])
def testEmptyExecution(self): t = empty((20, 30), dtype='i8', chunk_size=5) res = self.executor.execute_tensor(t, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.int64) t = empty((20, 30), chunk_size=5) res = self.executor.execute_tensor(t, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.float64) t2 = empty_like(t) res = self.executor.execute_tensor(t2, concat=True) self.assertEqual(res[0].shape, (20, 30)) self.assertEqual(res[0].dtype, np.float64)
def test_compress(): a = np.array([[1, 2], [3, 4], [5, 6]]) with pytest.raises(TypeError): compress([0, 1], a, axis=0, out=1) with pytest.raises(TypeError): compress([0, 1], array([[1, 2], [3, 4], [5, 6]], dtype='i8'), axis=0, out=empty((1, 2), dtype='f8'))
def testCompress(self): a = np.array([[1, 2], [3, 4], [5, 6]]) with self.assertRaises(TypeError): compress([0, 1], a, axis=0, out=1) with self.assertRaises(TypeError): compress([0, 1], array([[1, 2], [3, 4], [5, 6]], dtype='i8'), axis=0, out=empty((1, 2), dtype='f8'))
def testStackExecution(self): raw = [np.random.randn(3, 4) for _ in range(10)] arrs = [tensor(a, chunk_size=3) for a in raw] arr2 = stack(arrs) res = self.executor.execute_tensor(arr2, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw))) arr3 = stack(arrs, axis=1) res = self.executor.execute_tensor(arr3, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=1))) arr4 = stack(arrs, axis=2) res = self.executor.execute_tensor(arr4, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=2))) raw2 = [np.asfortranarray(np.random.randn(3, 4)) for _ in range(10)] arr5 = [tensor(a, chunk_size=3) for a in raw2] arr6 = stack(arr5) res = self.executor.execute_tensor(arr6, concat=True)[0] expected = np.stack(raw2).copy('A') np.testing.assert_array_equal(res, expected) self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS']) self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS']) arr7 = stack(arr5, out=empty((10, 3, 4), order='F')) res = self.executor.execute_tensor(arr7, concat=True)[0] expected = np.stack(raw2, out=np.empty((10, 3, 4), order='F')).copy('A') np.testing.assert_array_equal(res, expected) self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS']) self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS']) # test stack with unknown shapes t = tensor(raw[0], chunk_size=3) t2 = t[t[:, 0] > 0.0] t3 = t2 + 1 with self.ctx: arr8 = stack([t2, t3]) result = self.executor.execute_tensors([arr8])[0] e = raw[0] e2 = e[e[:, 0] > 0.0] e3 = e2 + 1 np.testing.assert_array_equal(result, np.stack([e2, e3]))
def test_empty_execution(setup): t = empty((20, 30), dtype='i8', chunk_size=5) res = t.execute().fetch() assert res.shape == (20, 30) assert res.dtype == np.int64 t = empty((20, 30), chunk_size=10) res = t.execute().fetch() assert res.shape == (20, 30) assert res.dtype == np.float64 t2 = empty_like(t) res = t2.execute().fetch() assert res.shape == (20, 30) assert res.dtype == np.float64 t = empty((20, 30), dtype='i8', chunk_size=5, order='F') res = t.execute().fetch() expected = np.empty((20, 30), dtype='i8', order='F') assert res.flags['C_CONTIGUOUS'] == expected.flags['C_CONTIGUOUS'] assert res.flags['F_CONTIGUOUS'] == expected.flags['F_CONTIGUOUS']
def testStack(self): raw_arrs = [ones((3, 4), chunk_size=2) for _ in range(10)] arr2 = stack(raw_arrs, axis=0) self.assertEqual(arr2.shape, (10, 3, 4)) arr2.tiles() self.assertEqual(arr2.nsplits, ((1, ) * 10, (2, 1), (2, 2))) arr3 = stack(raw_arrs, axis=1) self.assertEqual(arr3.shape, (3, 10, 4)) arr3.tiles() self.assertEqual(arr3.nsplits, ((2, 1), (1, ) * 10, (2, 2))) arr4 = stack(raw_arrs, axis=2) self.assertEqual(arr4.shape, (3, 4, 10)) arr4.tiles() self.assertEqual(arr4.nsplits, ((2, 1), (2, 2), (1, ) * 10)) with self.assertRaises(ValueError): raw_arrs2 = [ ones((3, 4), chunk_size=2), ones((4, 3), chunk_size=2) ] stack(raw_arrs2) with self.assertRaises(np.AxisError): stack(raw_arrs, axis=3) arr5 = stack(raw_arrs, -1).tiles() self.assertEqual(arr5.nsplits, ((2, 1), (2, 2), (1, ) * 10)) arr6 = stack(raw_arrs, -3).tiles() self.assertEqual(arr6.nsplits, ((1, ) * 10, (2, 1), (2, 2))) with self.assertRaises(np.AxisError): stack(raw_arrs, axis=-4) with self.assertRaises(TypeError): stack(raw_arrs, out=1) with self.assertRaises(ValueError): stack(raw_arrs, empty((1, 10, 3, 4)))
def testLogWithOutWhere(self): t1 = ones((3, 4), chunk_size=2) t2 = log(t1, out=t1) self.assertIsInstance(t2.op, TensorLog) self.assertEqual(t1.op.out.key, t1.op.input.key) self.assertIs(t2, t1) self.assertEqual(t2.op.input.extra_params.raw_chunk_size, 2) self.assertNotEqual(t2.key, t2.op.input.key) t3 = empty((3, 4), chunk_size=2) t4 = log(t1, out=t3, where=t1 > 0) self.assertIsInstance(t4.op, TensorLog) self.assertIs(t4, t3) self.assertEqual(t2.op.input.extra_params.raw_chunk_size, 2) self.assertNotEqual(t2.key, t2.op.input.key)
def test_log_without_where(): t1 = ones((3, 4), chunk_size=2) t2 = log(t1, out=t1) assert isinstance(t2.op, TensorLog) assert t1.op.out.key == t1.op.input.key assert t2 is t1 assert t2.op.input.extra_params.raw_chunk_size == 2 assert t2.key != t2.op.input.key t3 = empty((3, 4), chunk_size=2) t4 = log(t1, out=t3, where=t1 > 0) assert isinstance(t4.op, TensorLog) assert t4 is t3 assert t2.op.input.extra_params.raw_chunk_size == 2 assert t2.key != t2.op.input.key
def testDatatimeArith(self): t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) t2 = t1 + np.timedelta64(1) self.assertIsInstance(t2.op, TensorAdd) t3 = t1 - np.datetime64('2005-02-02') self.assertIsInstance(t3.op, TensorSubtract) self.assertEqual(t3.dtype, (np.array(['2005-02-02', '2005-02-03'], dtype=np.datetime64) - np.datetime64('2005-02-02')).dtype) t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) subtract(t1, np.datetime64('2005-02-02'), out=empty(t1.shape, dtype=t3.dtype)) t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) add(t1, np.timedelta64(1, 'D'), out=t1)
def test_stack(): raw_arrs = [ones((3, 4), chunk_size=2) for _ in range(10)] arr2 = stack(raw_arrs, axis=0) assert arr2.shape == (10, 3, 4) arr2 = tile(arr2) assert arr2.nsplits == ((1,) * 10, (2, 1), (2, 2)) arr3 = stack(raw_arrs, axis=1) assert arr3.shape == (3, 10, 4) arr3 = tile(arr3) assert arr3.nsplits == ((2, 1), (1,) * 10, (2, 2)) arr4 = stack(raw_arrs, axis=2) assert arr4.shape == (3, 4, 10) arr4 = tile(arr4) assert arr4.nsplits == ((2, 1), (2, 2), (1,) * 10) with pytest.raises(ValueError): raw_arrs2 = [ones((3, 4), chunk_size=2), ones((4, 3), chunk_size=2)] stack(raw_arrs2) with pytest.raises(np.AxisError): stack(raw_arrs, axis=3) arr5 = tile(stack(raw_arrs, -1)) assert arr5.nsplits == ((2, 1), (2, 2), (1,) * 10) arr6 = tile(stack(raw_arrs, -3)) assert arr6.nsplits == ((1,) * 10, (2, 1), (2, 2)) with pytest.raises(np.AxisError): stack(raw_arrs, axis=-4) with pytest.raises(TypeError): stack(raw_arrs, out=1) with pytest.raises(ValueError): stack(raw_arrs, empty((1, 10, 3, 4)))
def test_stack_execution(setup): raw = [np.random.randn(3, 4) for _ in range(10)] arrs = [tensor(a, chunk_size=3) for a in raw] arr2 = stack(arrs) res = arr2.execute().fetch() assert np.array_equal(res, np.stack(raw)) is True arr3 = stack(arrs, axis=1) res = arr3.execute().fetch() assert np.array_equal(res, np.stack(raw, axis=1)) is True arr4 = stack(arrs, axis=2) res = arr4.execute().fetch() assert np.array_equal(res, np.stack(raw, axis=2)) is True raw2 = [np.asfortranarray(np.random.randn(3, 4)) for _ in range(10)] arr5 = [tensor(a, chunk_size=3) for a in raw2] arr6 = stack(arr5) res = arr6.execute().fetch() expected = np.stack(raw2).copy('A') np.testing.assert_array_equal(res, expected) arr7 = stack(arr5, out=empty((10, 3, 4), order='F')) res = arr7.execute().fetch() expected = np.stack(raw2, out=np.empty((10, 3, 4), order='F')).copy('A') np.testing.assert_array_equal(res, expected) assert res.flags['C_CONTIGUOUS'] == expected.flags['C_CONTIGUOUS'] assert res.flags['F_CONTIGUOUS'] == expected.flags['F_CONTIGUOUS'] # test stack with unknown shapes t = tensor(raw[0], chunk_size=3) t2 = t[t[:, 0] > 0.0] t3 = t2 + 1 arr8 = stack([t2, t3]) result = arr8.execute().fetch() e = raw[0] e2 = e[e[:, 0] > 0.0] e3 = e2 + 1 np.testing.assert_array_equal(result, np.stack([e2, e3]))
def test_datatime_arith(): t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) t2 = t1 + np.timedelta64(1) assert isinstance(t2.op, TensorAdd) t3 = t1 - np.datetime64('2005-02-02') assert isinstance(t3.op, TensorSubtract) assert t3.dtype == ( np.array(['2005-02-02', '2005-02-03'], dtype=np.datetime64) - np.datetime64('2005-02-02')).dtype t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) subtract(t1, np.datetime64('2005-02-02'), out=empty(t1.shape, dtype=t3.dtype)) t1 = array([np.datetime64('2005-02-02'), np.datetime64('2005-02-03')]) add(t1, np.timedelta64(1, 'D'), out=t1)
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 testQuantileExecution(self): # test 1 chunk, 1-d raw = np.random.rand(20) a = tensor(raw, chunk_size=20) raw2 = raw.copy() raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: r = quantile(a, q, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r, concat=True)[0] expected = np.quantile(raw, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) r2 = quantile(a2, q, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r2, concat=True)[0] expected = np.quantile(raw2, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) # test 1 chunk, 2-d raw = np.random.rand(20, 10) a = tensor(raw, chunk_size=20) raw2 = raw.copy() raw2.flat[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: for axis in [None, 0, 1]: r = quantile(a, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r, concat=True)[0] expected = np.quantile(raw, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) r2 = quantile(a2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r2, concat=True)[0] expected = np.quantile(raw2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) # test multi chunks, 1-d raw = np.random.rand(20) a = tensor(raw, chunk_size=3) raw2 = raw.copy() raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: r = quantile(a, q, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r, concat=True)[0] expected = np.quantile(raw, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) r2 = quantile(a2, q, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r2, concat=True)[0] expected = np.quantile(raw2, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) # test multi chunk, 2-d raw = np.random.rand(20, 10) a = tensor(raw, chunk_size=(12, 6)) raw2 = raw.copy() raw2.flat[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=(12, 6)) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: for axis in [None, 0, 1]: r = quantile(a, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r, concat=True)[0] expected = np.quantile(raw, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) r2 = quantile(a2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = self.executor.execute_tensor(r2, concat=True)[0] expected = np.quantile(raw2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) # test out, 1 chunk raw = np.random.rand(20) q = np.random.rand(11) a = tensor(raw, chunk_size=20) out = empty((5, 11)) quantile(a, q, out=out) result = self.executor.execute_tensor(out, concat=True)[0] expected = np.quantile(raw, q, out=np.empty((5, 11))) np.testing.assert_array_equal(result, expected) # test out, multi chunks raw = np.random.rand(20) q = np.random.rand(11) a = tensor(raw, chunk_size=3) out = empty((5, 11)) quantile(a, q, out=out) result = self.executor.execute_tensor(out, concat=True)[0] expected = np.quantile(raw, q, out=np.empty((5, 11))) np.testing.assert_almost_equal(result, expected) # test q which is a tensor q_raw = np.random.RandomState(0).rand(5) q = tensor(q_raw, chunk_size=3) ctx, executor = self._create_test_context(self.executor) with ctx: r = quantile(a, q, axis=None) result = executor.execute_tensors([r])[0] expected = np.quantile(raw, q_raw, axis=None) np.testing.assert_almost_equal(result, expected) with self.assertRaises(ValueError): q[0] = 1.1 r = quantile(a, q, axis=None) _ = executor.execute_tensors(r)[0]
def test_quantile_execution(setup): # test 1 chunk, 1-d raw = np.random.rand(20) a = tensor(raw, chunk_size=20) raw2 = raw.copy() raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: r = quantile(a, q, interpolation=interpolation, keepdims=keepdims) result = r.execute().fetch() expected = np.quantile(raw, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) r2 = quantile(a2, q, interpolation=interpolation, keepdims=keepdims) result = r2.execute().fetch() expected = np.quantile(raw2, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) # test 1 chunk, 2-d raw = np.random.rand(20, 10) a = tensor(raw, chunk_size=20) raw2 = raw.copy() raw2.flat[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: for axis in [None, 0, 1]: r = quantile(a, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = r.execute().fetch() expected = np.quantile(raw, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) r2 = quantile(a2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = r2.execute().fetch() expected = np.quantile(raw2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_array_equal(result, expected) # test multi chunks, 1-d raw = np.random.rand(20) a = tensor(raw, chunk_size=6) raw2 = raw.copy() raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=20) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: r = quantile(a, q, interpolation=interpolation, keepdims=keepdims) result = r.execute().fetch() expected = np.quantile(raw, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) r2 = quantile(a2, q, interpolation=interpolation, keepdims=keepdims) result = r2.execute().fetch() expected = np.quantile(raw2, q, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) # test multi chunk, 2-d raw = np.random.rand(20, 10) a = tensor(raw, chunk_size=(12, 6)) raw2 = raw.copy() raw2.flat[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan a2 = tensor(raw2, chunk_size=(12, 6)) for q in [ np.random.RandomState(0).rand(), np.random.RandomState(0).rand(5) ]: for interpolation in INTERPOLATION_TYPES: for keepdims in [True, False]: for axis in [None, 0, 1]: r = quantile(a, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = r.execute().fetch() expected = np.quantile(raw, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) r2 = quantile(a2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) result = r2.execute().fetch() expected = np.quantile(raw2, q, axis=axis, interpolation=interpolation, keepdims=keepdims) np.testing.assert_almost_equal(result, expected) # test out, 1 chunk raw = np.random.rand(20) q = np.random.rand(11) a = tensor(raw, chunk_size=20) out = empty((5, 11)) quantile(a, q, out=out) result = out.execute().fetch() expected = np.quantile(raw, q, out=np.empty((5, 11))) np.testing.assert_array_equal(result, expected) # test out, multi chunks raw = np.random.rand(20) q = np.random.rand(11) a = tensor(raw, chunk_size=6) out = empty((5, 11)) quantile(a, q, out=out) result = out.execute().fetch() expected = np.quantile(raw, q, out=np.empty((5, 11))) np.testing.assert_almost_equal(result, expected) # test q which is a tensor q_raw = np.random.RandomState(0).rand(5) q = tensor(q_raw, chunk_size=6) r = quantile(a, q, axis=None) result = r.execute().fetch() expected = np.quantile(raw, q_raw, axis=None) np.testing.assert_almost_equal(result, expected) with pytest.raises(ValueError): q[0] = 1.1 r = quantile(a, q, axis=None) _ = r.execute()