Closed LaurieGustavo closed 5 years ago
Thanks for the report; I'll take a look. I don't expect this one will be too difficult to fix. As a workaround, put unsafe
the beginning of the main
function (with no bounds checking, there will be no safety certificates that the compiler can screw up).
Smallest reproducible case:
type vector = (f64,f64)
let add(v1: vector)(v2: vector): vector =
let(a,b) = v1
let(c,d) = v2
in (a+c, b+d)
let mult(f: f64)(v: vector): vector =
let (a,b) = v
in (f*a, f*b)
let dotprod(v1: vector, v2: vector): f64 =
let(a,b) = v1
let(c,d) = v2
in a*c + b*d
let square(v: vector): f64 =
dotprod(v,v)
let init_matrix 't (nx: i32)(ny: i32)(x: t): [nx][ny]t =
map( \(_):[]t ->
map( \(_):t ->
x
) (0..<ny)
) (0..<nx)
let j(u: vector, tau: f64, g: vector): vector =
let a = mult tau g
in add a u
let f_eq(rho: f64, u: vector, g: vector, tau: f64): f64 =
let j_val = j(u,tau,g)
in rho*(1 + 3 + (9f64/2) - (3f64/2)*square(j_val))
let init_f_in [nx][ny] (rho: [nx][ny]f64, u: [nx][ny]vector, g: vector, tau: f64): [nx][ny][9]f64 =
map( \(x) ->
map( \(y) ->
replicate 9 (f_eq(rho[x,y], u[x,y], g, tau))
) (0..<ny)
) (0..<nx)
let main (nx: i32)(ny: i32)(g_x: f64)(g_y: f64)(tau: f64) =
let g: vector = (g_x, g_y)
let u = init_matrix(nx)(ny)((0f64, 0f64))
let rho = init_matrix(nx)(ny)(1f64)
let f_in = init_f_in(rho, u, g, tau)
in f_in
it seems the error disappears when using map2 instead of map , for example in function init_f_in in the smallest reproducible case :
let init_f_in [nx][ny] (rho: [nx][ny]f64, u: [nx][ny]vector, g: vector, tau: f64): [nx][ny][9]f64 =
map2(\rx ux ->
map2(\rxy uxy ->
replicate 9 (f_eq(rxy, uxy, g, tau))
) rx ux
) rho u
So know i can compile my main code to a Python module =)
Have you tried the newest release of the compiler? I am pretty sure I fixed this even for your original formulation.
Hello,
i have an internal compiler error for my program when trying to compile to a Python module. Would anybody have an idea about a fix ? thank you =)
it's a program for the Lattice-Baltzmann algorithm. Basically there are 4 matrices that need each other to be updated at each iteration (u: [nx][ny](f64, f64), rho: [nx][ny]f64, f_in: [nx][ny][9], f_out: [nx][ny][9]f64 ). The problem seems to be that it can't determine the size of f_in or f_out
futhark --version Futhark 0.11.0 git: cb04266 (Mon May 6 14:24:26 2019 +0200)
Lattice_Baltzmann.fut
vector.fut