futhark literate
I think it could actually be pretty good for general engineering students.
I am a bit confused by this error:
Cannot apply "reduce_by_index_stream" to "interaction" (invalid type).
Expected: *acc [n](((f32, f32, f32), (f32, f32, f32)), tââ) -> bââ
-> *acc [n](((f32, f32, f32), (f32, f32, f32)), tââ)
Actual: (acc: *acc [kââ](((f32, f32, f32), (f32, f32, f32)), f32)) -> ((i64,
i64),
(i32,
i32,
i32))
-> *acc [kââ](((f32, f32, f32), (f32, f32, f32)), f32)
Would consume variable "potential", which is not allowed.
from the code
let associatedInteraction [n] potential box (coordinates:[n](v3,quaternion)) associations =
191 let interaction [k] (acc: *acc ([k](ft, f32))) ((i, j), jump) : (*acc ([k](ft, f32)))
=
192 let cI = coordinates[i]
193 let cJ = triadMap f32.i32 jump |> mvMult box |> translate coordinates[j]
194 let (ftI, ftJ, p) = particleInteraction potential cI cJ
195 in write (write acc i (ftI, 0)) j (ftJ, p)
196 let ne = (zeroFT, 0)
197 let (fts, ps) = reduce_by_index_stream
198 (replicate n ne)
199 (\(ft1, p1) (ft2, p2) -> (addFT ft1 ft2, p1 + p2))
200 ne
201 interaction
202 |> unzip
203 in (fts, f32.sum ps)
176 let associatedInteraction [n] potential box (coordinates:[n](v3,quaternion)) associations =
177 let interaction ((i, j), jump) =
178 let cI = coordinates[i]
179 let cJ = triadMap f32.i32 jump |> mvMult box |> translate coordinates[j]
180 let (ftI, ftJ, p) = particleInteraction potential cI cJ
181 in ((i, ftI), (j, ftJ), p)
182 let (ftIs, ftJs, ps) = map interaction associations |> unzip3
183 let reduction
184 = unzip
185 >-> (\(idx, fts) -> reduce_by_index
186 (replicate n zeroFT) addFT zeroFT
187 (map i64.i32 idx) fts)
188 in (addFTs (reduction ftIs) (reduction ftJs), f32.sum ps)
205 let associatedInteractionRed [n] 'a 'b (ne:b) (add: b-> b -> b)(potential: a -> a -> b) (co
ordinates:[n]a) associations =
206 let interaction [k] (acc: *acc ([k]b)) (i, j) : (*acc ([k]b)) =
207 let cI = coordinates[i]
208 let cJ = coordinates[j]
209 let v = potential cI cJ
210 in write (write acc i v) j v
211 let fts = reduce_by_index_stream
212 (replicate n ne)
213 add
214 ne
215 interaction
216 |> unzip
217 in fts
acc
), because we haven't really had any of those before.
accumulators
, we haven't really tested it at all yet!