@@ -24,9 +24,22 @@ extension MfArray: CustomStringConvertible{
2424 var shape = self . shape
2525 var strides = self . strides
2626
27+ #if os(WASI)
28+ let formatter : NumberFormatter ? = nil
29+ #else
2730 let formatter = NumberFormatter ( )
2831 formatter. positivePrefix = formatter. plusSign
2932 formatter. maximumFractionDigits = self . storedType == . Float ? 7 : 14
33+ #endif
34+
35+ func imagString( _ value: Any ) -> String {
36+ #if os(WASI)
37+ // Avoid NumberFormatter on WASI (Foundation formatter crashes in wasm)
38+ return " \( value) "
39+ #else
40+ return formatter? . string ( for: value) ?? " \( value) "
41+ #endif
42+ }
3043
3144 if self . size > 1000 { //if size > 1000, some elements left out will be viewed
3245 let flattenLOIndSeq = FlattenLOIndSequence ( storedSize: self . storedSize, shape: & shape, strides: & strides)
@@ -39,7 +52,7 @@ extension MfArray: CustomStringConvertible{
3952 desc += " \t \( flattenData [ flattenIndex + self . offsetIndex] ) , \t "
4053 }
4154 else {
42- desc += " \t \( flattenData [ flattenIndex + self . offsetIndex] ) \( formatter . string ( for : flattenImagData![ flattenIndex + self . offsetIndex] ) ?? " " ) j, \t "
55+ desc += " \t \( flattenData [ flattenIndex + self . offsetIndex] ) \( imagString ( flattenImagData![ flattenIndex + self . offsetIndex] ) ) j, \t "
4356 }
4457
4558 if indices. last! == shape. last! - 1 {
@@ -81,7 +94,7 @@ extension MfArray: CustomStringConvertible{
8194 desc += " \t \( flattenData [ ret. flattenIndex + self . offsetIndex] ) , \t "
8295 }
8396 else {
84- desc += " \t \( flattenData [ ret. flattenIndex + self . offsetIndex] ) \( formatter . string ( for : flattenImagData![ ret. flattenIndex + self . offsetIndex] ) ?? " " ) j, \t "
97+ desc += " \t \( flattenData [ ret. flattenIndex + self . offsetIndex] ) \( imagString ( flattenImagData![ ret. flattenIndex + self . offsetIndex] ) ) j, \t "
8598 }
8699
87100 if ret. indices. last! == shape. last! - 1 {
0 commit comments