Пример #1
0
 def test_complex_array(self):
     """Test complex array is correctly formatted"""
     A = np.array([[0.453 - 0.543j, 1, 0.213 + 8j],
                   [-0.543j, 1.342 + 0.5j, 1e-4 - 2e2j]])
     res = "\n".join(numpy_to_blackbird(A, "A"))
     expected = dedent("""\
         complex array A[2, 3] =
             0.453-0.543j, 1.0+0.0j, 0.213+8.0j
             -0.0-0.543j, 1.342+0.5j, 0.0001-200.0j
         """)
     assert res == expected
Пример #2
0
    def test_unknown_array(self):
        """Test non-numeric array raises an exception"""
        A = np.array([True, False])

        with pytest.raises(ValueError, match="unsupported type"):
            numpy_to_blackbird(A, "A")
Пример #3
0
 def test_int_array(self):
     """Test integer array is correctly formatted"""
     A = np.array([[1, -0, -15]])
     res = "\n".join(numpy_to_blackbird(A, "A"))
     expected = "int array A[1, 3] =\n    1, 0, -15\n"
     assert res == expected
Пример #4
0
 def test_real_array(self):
     """Test real array is correctly formatted"""
     A = np.array([[0.453, 1, 0.213], [-0.543, 1.342, 1e-4]])
     res = "\n".join(numpy_to_blackbird(A, "A"))
     expected = "float array A[2, 3] =\n    0.453, 1.0, 0.213\n    -0.543, 1.342, 0.0001\n"
     assert res == expected