diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.38k stars 165 forks source link

How to compare two arrays for equality? #2165

Closed INIT-REF closed 2 months ago

INIT-REF commented 2 months ago

Hi all,

I'm just starting out with Futhark by solving Project Euler problems and I'm looking for the best/most simple/fastest way to compare two arrays of the same type (int or bool) for equality.

The compiler was so kind to inform me that "==" is not the way to do it, so given two arrays a and b I'm using

map2(\x y -> x == y) a b |> and

for now. Is this ok or would you recommend something different?

Cheers, Matthias

athas commented 2 months ago

That is how you do it. See also https://futhark-lang.org/examples/array-equality.html

It feels quite roundabout, but array comparison turns out to be fairly rare in most programs.