File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1- from typed_python import ListOf , Entrypoint
1+ from typed_python import ListOf , Entrypoint , SerializationContext
22import numpy
33import numpy .linalg
44
@@ -44,3 +44,22 @@ def test_listof_from_sliced_numpy_array():
4444 y = x [::2 ]
4545
4646 assert ListOf (int )(y ) == [0 , 2 ]
47+
48+
49+ def test_can_serialize_numpy_ufuncs ():
50+ assert numpy .sin == SerializationContext ().deserialize (SerializationContext ().serialize (numpy .sin ))
51+ assert numpy .max == SerializationContext ().deserialize (SerializationContext ().serialize (numpy .max ))
52+
53+
54+ def test_can_serialize_numpy_array_from_builtin ():
55+ x = numpy .ones (10 )
56+ assert (x == SerializationContext ().deserialize (SerializationContext ().serialize (x ))).all ()
57+
58+
59+ def test_can_serialize_numpy_array_from_list ():
60+ x = numpy .array ([1 , 2 , 3 ])
61+ assert (x == SerializationContext ().deserialize (SerializationContext ().serialize (x ))).all ()
62+
63+
64+ def test_can_serialize_numpy_array_constructor ():
65+ assert numpy .array == SerializationContext ().deserialize (SerializationContext ().serialize (numpy .array ))
Original file line number Diff line number Diff line change @@ -1339,6 +1339,29 @@ def f(self, x=10):
13391339
13401340 self .assertLess (currentMemUsageMb (), usage + .5 )
13411341
1342+ def test_serialize_class_with_bound_methods (self ):
1343+ class SomeClass :
1344+ pass
1345+
1346+ class SomeSubclass (SomeClass ):
1347+ def __init__ (self , x ):
1348+ self .x = x
1349+
1350+ class ClassWithBoundMethod (Class , Final ):
1351+ x = Member (OneOf (None , SomeClass ))
1352+
1353+ def __init__ (self ):
1354+ self .x = None
1355+
1356+ def increment (self , y ):
1357+ if self .x is None :
1358+ self .x = SomeSubclass (y )
1359+ else :
1360+ self .x = SomeSubclass (self .x .x + y )
1361+
1362+ self .assertEqual (ClassWithBoundMethod , ping_pong (ClassWithBoundMethod ))
1363+ self .assertEqual (ClassWithBoundMethod .increment , ping_pong (ClassWithBoundMethod .increment ))
1364+
13421365 def test_serialize_named_tuples_with_extra_fields (self ):
13431366 T1 = NamedTuple (x = int )
13441367 T2 = NamedTuple (x = int , y = float , z = str )
You can’t perform that action at this time.
0 commit comments