def test_simple(self): # Default is a count of 50. For these simple cases of integers, # the result should be exact self.assertEqual(nd.as_py(nd.linspace(0, 49)), list(range(50))) self.assertEqual(nd.as_py(nd.linspace(49, 0)), list(range(49, -1, -1))) self.assertEqual(nd.as_py(nd.linspace(0, 10, count=11)), list(range(11))) self.assertEqual(nd.as_py(nd.linspace(1, -1, count=2)), [1, -1]) self.assertEqual(nd.as_py(nd.linspace(1j, 50j)), [i*1j for i in range(1, 51)])
def test_default_dtype(self): # Defaults to float64 when given ints self.assertEqual(nd.dtype_of(nd.linspace(0, 1)), ndt.float64) # Gives float64 when given floats self.assertEqual(nd.dtype_of(nd.linspace(0, 1.0)), ndt.float64) self.assertEqual(nd.dtype_of(nd.linspace(0.0, 1)), ndt.float64) # Gives complex[float64] when given complex self.assertEqual(nd.dtype_of(nd.linspace(1.0, 1.0j)), ndt.complex_float64) self.assertEqual(nd.dtype_of(nd.linspace(0.0j, 1.0)), ndt.complex_float64)
def test_specified_dtype(self): # Linspace only supports real-valued outputs self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.bool) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.int8) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.int16) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.int32) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.int64) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.uint8) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.uint16) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.uint32) self.assertRaises(RuntimeError, nd.linspace, 0, 1, dtype=ndt.uint64) # Should obey the float/complex type requests self.assertEqual(nd.dtype_of(nd.linspace(0, 1, dtype=ndt.float32)), ndt.float32) self.assertEqual(nd.dtype_of(nd.linspace(0, 1, dtype=ndt.float64)), ndt.float64) self.assertEqual(nd.dtype_of(nd.linspace(0, 1, dtype=ndt.complex_float32)), ndt.complex_float32) self.assertEqual(nd.dtype_of(nd.linspace(0, 1, dtype=ndt.complex_float64)), ndt.complex_float64)