Beispiel #1
0
 def test_multi_dim_array_np(self):
     a1 = ['1 2, 3, -4', '1 2, -3, -4']
     a2 = ['1 2, 3, -4', '1 2, -3, -4']
     aa = [a1, a2]
     a = array_int_np(aa)
     b = np.array([array_int_np(r) for r in aa])
     pass_val = np.any(np.equal(a, b))
     self.assertTrue(pass_val)
     a_shape = np.array(a.shape)
     t_shape = np.array((2, 2, 4))
     self.assertTrue(np.any(np.equal(a_shape, t_shape)))
Beispiel #2
0
 def test_bad_np(self):
     a1 = ['1 2, 3, a', '1 2, -3, -4']
     a = array_int_np(a1)
     self.assertIsNone(a)
     a1 = ['1 2, 3, 4.', '1 2, -3, -4']
     a = array_int_np(a1)
     self.assertIsNone(a)
     a1 = ['1 2, 3.0, -4.0', '1. 2, -3.0, -4.0']
     a2 = ['1. 2, 3.0, a', '1. 2, -3.0, -4.0']
     aa = [a1, a2]
     a = array_int_np(aa)
     self.assertIsNone(a)
Beispiel #3
0
 def test_multi_dim_array_np_4(self):
     a1 = [[1, 2, 3, -4], [1, 2, -3, -4]]
     a3 = [[1, 2, 3, -4], [1, 2, -3, -4]]
     aa = [a1, a3]
     a = array_int_np(aa)
     a_shape = a.shape
     b = array_int_np(aa)
     a_n = (np.array(a.tolist()).astype(
         np.int64)).flatten().reshape(a_shape)
     self.assertTrue(np.array_equal(a_n, b))
     a_shape = np.array(a.shape)
     t_shape = np.array((2, 2, 4))
     self.assertTrue(np.array_equal(a_shape, t_shape))
Beispiel #4
0
 def test_tuple_true(self):
     a = (1, 2, 3, -4)
     b = np.array(a)
     b_shape = b.shape
     a_vals = array_int_np(a)
     a_vals_shape = a_vals.shape
     self.assertTrue(np.array_equal(a_vals_shape, b_shape))
     self.assertTrue(np.array_equal(a_vals, b))
Beispiel #5
0
 def test_two_dim_array_int(self):
     a1 = ['1 2, 3, -4', '1 2, -3, -4']
     a = array_int_np(a1)
     b = np.array([[1, 1, 3, -4], [1, 2, -3, -4]])
     pass_val = np.any(np.equal(a, b))
     self.assertTrue(pass_val)
     a_shape = np.array(a.shape)
     t_shape = np.array((2, 4))
     self.assertTrue(np.any(np.equal(a_shape, t_shape)))
Beispiel #6
0
 def test_multi_dim_array_np_5(self):
     a1 = [[1, 2, 3 - 4], [1, 2, -3,
                           -4]]  #Notice there is no comma between 3 and -4
     #In this instance python does the arithmetic first, but this tries to
     #  make and unbalanced matrix.  These routines don't support such matrices
     #  If you use strings, then the string is split on the spaces and the
     #  operation is not done first
     a3 = [[1, 2, 3, -4], [1, 2, -3, -4]]
     aa = [a1, a3]
     a = array_int_np(aa)
     self.assertTrue(a is None)
Beispiel #7
0
 def test_tuple_false_2(self):
     a = (1, 'a', 3, 4)
     a_vals = array_int_np(a)
     self.assertIsNone(a_vals)
Beispiel #8
0
 def test_array_false_2(self):
     a = [1, 'a', 3, 4]
     a_vals = array_int_np(a)
     self.assertIsNone(a_vals)
Beispiel #9
0
 def test_array_int_np(self):
     str1 = '1 2, ,3,, -4'
     res = array_int_np(str1)
     self.assertIsNotNone(res)
     r = [isinstance(x, np.int64) for x in res]
     r = reduce(lambda x, y: x and y, r)