[squeak-dev] Re: [Vm-dev] MadgwickAHRS plugin and support code

Levente Uzonyi leves at elte.hu
Mon Sep 14 21:33:35 UTC 2015


We might as well have primitives which write their result into an object 
passed as parameter, or primitives which update the receiver, like the 
ones provided by KedamaFloatArray. But with SmallFloat64 being on the way, 
it's not that tempting to write such primitives.

Levente

On Mon, 14 Sep 2015, Eliot Miranda wrote:

> Hi Herbert,
> 
> On Sun, Sep 13, 2015 at 4:34 AM, Herbert König <herbertkoenig at gmx.net> wrote:
>       Hi,
>
>       Am 13.09.2015 um 06:31 schrieb David T. Lewis:
>             Well it's basically the only convenient way to deal with float (as opposed to double) floating point values. In Squeak, a
>             Float is a C double, and AFIK the only thing that directly represents single precision floats is FloatArray. You would be
>             justified in being scared of them, especially if any of this sounds like it makes sense. But it does work and it might be
>             more efficient than arrays of Float (C doubles). Or maybe not, I don't have any way to measure it. But I tried to set
>             things up so that the FloatArray things can be reused to avoid allocations and type conversions, so maybe it will help.
> 
>
>       FloatArray offers a lot of speed up as long as the operations provided by Float array are sufficient. Getting Squeak Floats into and
>       out of Float Array is expensive.
>       This:
>       Time millisecondsToRun:
>           [|array1 array2|
>           array1 := (1.0 to: 10000.0 by: 0.1) asArray.
>           array2 := (10000.0 to: 1.0 by: -0.1) asArray.
>           1000 timesRepeat: [|result|
>               result := array1  * array2]]
>       22 seconds
>       is not much slower than using FloatArray
>       Time millisecondsToRun:
>           [|array1 array2|
>           array1 := (1.0 to: 10000.0 by: 0.1) asArray.
>           array2 := (10000.0 to: 1.0 by: -0.1) asArray.
>           1000 timesRepeat: [|result|
>               result := (array1 asFloatArray * array2 asFloatArray)]]
>       19 seconds
>       If you change the last line to use more operations supported by FloatArray like:
>               result := (array1 asFloatArray * array2 asFloatArray + 7.0 * 3.0) sum
>       with FloatArrays you get the same speed, without the conversion to FloatArray it takes three times as long.
>
>       If you need to use FloatArray>>at: and #at:put very often FloatArrays may get slower than Arrays of Float.
>       So benchmark and benchmark again.
> 
> 
> That's right.  Using FloatArray implies an object allocation on every at:, to construct the (boxed) Float result.  64-bit Spur will change this
> equation because most of the time the floats fetched will be immediate, instances of SmallFloat64.  And indeed they may make it attractive to have
> a 64-bit float array type.
> 
>
>       And if your values get small, FloatArray may round them to zero which is bad for division.
>
>       I used FloatArray a lot for  Audio processing and neural networks but they need to be handled with care.
>       I ended up using both depending on the algorithm.
>
>       Cheers,
>
>       Herbert
> 
> 
> 
> 
> 
> 
> --
> _,,,^..^,,,_
> best, Eliot
> 
>


More information about the Squeak-dev mailing list