athas / vector

Futhark vectors with statically known size
3 stars 2 forks source link

[help-wanted] The example does't work #2

Open wusualis opened 3 years ago

wusualis commented 3 years ago

Hello. When I follow the Usage example:

import "lib/github.com/athas/vector/vector"
module vector_2 = cat_vector vector_1 vector_1
module vector_3 = cat_vector vector_2 vector_1
module vector_5 = cat_vector vector_2 vector_3
module vector_8 = cat_vector vector_5 vector_3

let main (xs: [vector_8.length]i32) =
  xs
  |> vector_8.from_array
  |> vector_8.map (+1)
  |> vector_8.to_array

this error ocurried: Dimensions "vector_8.length" and "8" do not match.

I can't fix it. Please help. image

athas commented 3 years ago

Which version of the Futhark compiler are you using? This works for me.

wusualis commented 3 years ago

Which version of the Futhark compiler are you using? This works for me.

My version is Futhark 0.20.0

I use it in interactive interface,does it matter?

athas commented 3 years ago

That shouldn't matter. I have tried passing the exact code you list to the compiler, loading it into the REPL, and copied it line-by-line into the REPL (with Futhark 0.20.0) and it works for me.

wusualis commented 3 years ago

That shouldn't matter. I have tried passing the exact code you list to the compiler, loading it into the REPL, and copied it line-by-line into the REPL (with Futhark 0.20.0) and it works for me.

I have uploaded the img at the top.

athas commented 3 years ago

Due to limitations in the type system, vector_8.length is not statically known to be 8 by the type checker, so you need an ugly size coercion:

main (xs :> [vector_8.length]i32)

I usually define a wrapper function:

let vec xs = vector_8.from_array (take vector_8.length)

I'll keep the issue open to remind me to improve the example in the README.