File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from __future__ import absolute_import , print_function , unicode_literals
22
33import struct
4+ from functools import reduce
5+ from operator import mul
46
57from wolframclient .exception import WolframLanguageException
68from wolframclient .serializers .wxfencoder import constants
1214 from collections import Sequence
1315
1416
17+ def pack (format , * elements ):
18+ return struct .pack (b"<%i%s" % (len (elements ), force_bytes (format )), * elements )
19+
20+
1521class NumericArray (Sequence ):
1622 def __init__ (self , array , type , shape = None ):
1723
@@ -29,15 +35,13 @@ def _valid_type_or_fail(self, type):
2935 return type
3036
3137 def tobytes (self ):
32- return struct .pack (
33- b"<%i%s" % (len (self ), force_bytes (self .struct .format [1 ])), * self .array
34- )
38+ return pack (self .struct .format [1 ], * self .array )
3539
3640 def __getitem__ (self , k ):
3741 return self .array [k ]
3842
3943 def __len__ (self ):
40- return len ( self .array )
44+ return reduce ( mul , self .shape , 1 )
4145
4246
4347class PackedArray (NumericArray ):
You can’t perform that action at this time.
0 commit comments