Closed naufraghi closed 8 months ago
Your operator is not associative. It will function in the sequential backend because the neutral element is never given as the first argument to the operator, but has to be compatible with this.
ne `op` a == a
a`op` ne == a
(a `op` b) `op` c == a `op` (b `op` c)
To correct your code you can write
def minmax [n] (pts: [n]f32) : (f32, f32) =
let decorated_pts = (map (\(num) -> (num, num)) pts)
let (min, max) = reduce (\(amin, amax) (bmin, bmax) -> (f32.min amin bmin, f32.max amax bmax))
(f32.highest, f32.lowest) decorated_pts
in (min, max)
FluxusMagna is correct. There is a bit more information here: https://futhark-lang.org/examples/scan-reduce.html
And here: https://futhark-lang.org/examples/no-neutral-element.html
It is deceptively easy to think of reduce
as foldl
, but that is not what it is.
Thanks, I'll digest it :)
Hi, I just started testing Futhark, so my code may be "wrong" in many ways, but I think that the output of the
c
andmulticore
executable should match or not compile.Here is the code of
minmax.fut
and the output:The input is the repr of a big Python array, generated with: