I have ByteStringone that contains a view of Floats. Each Floatis represented by 3 bytes per ByteString.
ByteString
Float
I need to do some processing of values Float, so I would like to do this processing with Vectorvalues Float. What would be the best way to do this?
Vector
I have a function toFloat :: [Word8] -> Floatthat converts 3 bytes ByteStringto Float. So I was thinking of iterating over ByteStringwith a 3 byte step and converting each step to Floatfor Vector.
toFloat :: [Word8] -> Float
I looked through the library functions for Vector, but I can not find anything that is suitable for this purpose. Data.Vector.Storable.ByteString.byteStringToVectorIt looked promising, but it converts every byte (instead of every 3 bytes) and gives me no control over how the conversion ByteStringto should happen Float.
Data.Vector.Storable.ByteString.byteStringToVector
Just use Data.Vector.generate:
Data.Vector.generate
V.generate (BS.length bs `div` 3) $ \i -> myToFloat (bs BS.! 3*i) (bs BS.! 3*i+1) (bs BS.! 3*i+2)
It will select the vector all at once and fill it. Data.ByteString.!- O (1), therefore it is quite effective.
Data.ByteString.!
Try using
splitAt :: Int -> ByteString -> (ByteString, ByteString)
ByteString : 3 , - . , 3 ( Data.List.Split.chunksOf), unpack , [Word8], . toFloat Vector.fromList.
Data.List.Split.chunksOf
unpack
[Word8]
toFloat
Vector.fromList
, , , , , , , , , , /fromList. ByteString O (1), , . , .
Source: https://habr.com/ru/post/1667742/More articles:Returns an array of a key => value pair, using Lambda in C # - c #Set header in node.js express framework middleware - node.jsLaravel Links - Access to Appropriate Value - laravelIs element initialization a side effect of the initializer clause? - c ++Как определить, когда пользователь прокручивал верхнюю часть элемента в RecyclerView - androidRandom loop iteration in R - loopsMySQL: группировка только связанными строками - sqlЭквивалент Spark Dataset для scala "собирать", принимая частичную функцию - scalaMySQL sequential group - sqlUsing (templated) overloaded functions to prevent common arithmetic conversions - c ++All Articles