def test_from_array(): x = array([1, 2, 3]) assert x.shape == (3, ) y = array([x, x]) assert y.shape == (2, 3) z = array((x, x, x)) assert z.shape == (3, 3)
def testFromArray(self): x = array([1, 2, 3]) self.assertEqual(x.shape, (3, )) y = array([x, x]) self.assertEqual(y.shape, (2, 3)) z = array((x, x, x)) self.assertEqual(z.shape, (3, 3))
def testHistogramBinEdges(self): a = array([0, 0, 0, 1, 2, 3, 3, 4, 5], chunk_size=3) with self.assertRaises(ValueError): histogram_bin_edges(a, bins='unknown') with self.assertRaises(TypeError): # bins is str, weights cannot be provided histogram_bin_edges(a, bins='scott', weights=a) with self.assertRaises(ValueError): histogram_bin_edges(a, bins=-1) with self.assertRaises(ValueError): # not asc histogram_bin_edges(a, bins=[3, 2, 1]) with self.assertRaises(ValueError): # bins cannot be 2d histogram_bin_edges(a, bins=np.random.rand(2, 3)) with self.assertRaises(ValueError): histogram_bin_edges(a, range=(5, 0)) with self.assertRaises(ValueError): histogram_bin_edges(a, range=(np.nan, np.nan)) bins = histogram_bin_edges(a, bins=3, range=(0, 5)) # if range specified, no error will occur bins.tiles()
def testArray(self): a = tensor([0, 1, 2], chunk_size=2) b = array(a) self.assertIsNot(a, b) c = asarray(a) self.assertIs(a, c)
def test_array(): a = tensor([0, 1, 2], chunk_size=2) b = array(a) assert a is not b c = asarray(a) assert a is c
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 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_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 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 testDtypeFromOut(self): x = array([-np.inf, 0., np.inf]) y = array([2, 2, 2]) t3 = isfinite(x, y) self.assertEqual(t3.dtype, y.dtype)
def test_dtype_from_out(): x = array([-np.inf, 0., np.inf]) y = array([2, 2, 2]) t3 = isfinite(x, y) assert t3.dtype == y.dtype