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
2
2
import numpy
3
3
import numpy .linalg
4
4
@@ -44,3 +44,22 @@ def test_listof_from_sliced_numpy_array():
44
44
y = x [::2 ]
45
45
46
46
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):
1339
1339
1340
1340
self .assertLess (currentMemUsageMb (), usage + .5 )
1341
1341
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
+
1342
1365
def test_serialize_named_tuples_with_extra_fields (self ):
1343
1366
T1 = NamedTuple (x = int )
1344
1367
T2 = NamedTuple (x = int , y = float , z = str )
You can’t perform that action at this time.
0 commit comments