您有我想要处理的浮点数据(单精度32位IEEE)的二进制文件. 我怎样才能最好地加载它以供进一步使用,理想情况下为(IOArray Int Float). bytesToFloats :: ByteString - [Float]bytesToFloatArray :: ByteString -
我怎样才能最好地加载它以供进一步使用,理想情况下为(IOArray Int Float).
bytesToFloats :: ByteString -> [Float] bytesToFloatArray :: ByteString -> IOArray Int Float如果你有标准的单精度浮点数,并且你只想在Haskell中使用它们,那么你总是会对它有所了解:
import Data.ByteString.Internal as BS import qualified Data.Vector.Storable as V bytesToFloats :: BS.ByteString -> V.Vector Float bytesToFloats = V.unsafeCast . aux . BS.toForeignPtr where aux (fp,offset,len) = V.unsafeFromForeignPtr fp offset len