1- from mathics .core .atoms import Integer , NumericArray , String
2- from mathics .core .convert .python import from_python
31from test .helper import check_evaluation , evaluate
42
53import numpy as np
64import pytest
75
6+ from mathics .core .atoms import Integer , NumericArray , String
7+ from mathics .core .convert .python import from_python
8+
89#
910# Python API tests
1011#
1112
13+
1214def test_numericarray_atom_preserves_array_reference ():
1315 array = np .array ([1 , 2 , 3 ], dtype = np .int64 )
1416 atom = NumericArray (array )
1517 assert atom .value is array
1618
19+
1720def test_numericarray_atom_preserves_equality ():
1821 array = np .array ([1 , 2 , 3 ], dtype = np .int64 )
1922 atom = NumericArray (array , dtype = np .float64 )
@@ -26,6 +29,7 @@ def test_numericarray_expression_from_python_array():
2629 assert isinstance (atom , NumericArray )
2730 assert atom .value is array
2831
32+
2933def test_numericarray_hash ():
3034 a = [[1 , 2 ], [3 , 4 ]]
3135 array1a = np .array (a , dtype = np .float32 )
@@ -34,16 +38,20 @@ def test_numericarray_hash():
3438 atom1b = from_python (array1a )
3539 array2 = np .array (a , dtype = np .float64 )
3640 atom2 = from_python (array2 )
37- assert hash (atom1a ) == hash (atom1b ), "hashes of different arrays with same value should be same"
38- assert hash (atom1a ) != hash (atom2 ), "hashes of arrays with different values should be different"
41+ assert hash (atom1a ) == hash (
42+ atom1b
43+ ), "hashes of different arrays with same value should be same"
44+ assert hash (atom1a ) != hash (
45+ atom2
46+ ), "hashes of arrays with different values should be different"
3947
4048
4149#
4250# WL tests
4351# Will not work yet
4452#
4553
46- #@pytest.mark.parametrize(
54+ # @pytest.mark.parametrize(
4755# ("str_expr", "str_expected"),
4856# [
4957# ("NumericArray[{{1,2},{3,4}}]", "<Integer64, 2×2>"),
@@ -56,15 +64,13 @@ def test_numericarray_hash():
5664# ("Last[NumericArray[{{1,2}, {3,4}}]]", "<Integer64, 2>"),
5765# ("Normal[NumericArray[{{1,2}, {3,4}}]]", "{{1, 2}, {3, 4}}"),
5866# ]
59- #)
60- #def test_basics(str_expr, str_expected):
67+ # )
68+ # def test_basics(str_expr, str_expected):
6169# check_evaluation(str_expr, str_expected, hold_expected=True)
6270#
63- #def test_type_conversion():
71+ # def test_type_conversion():
6472# expr = evaluate("NumericArray[{1,2}]")
6573# assert isinstance(expr, NumericArray)
6674# assert expr.value.dtype == np.int64
6775# expr = evaluate('NumericArray[{1,2}, "ComplexReal32"]')
6876# assert expr.value.dtype == np.complex64
69-
70-
0 commit comments