Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Comprehensions Error #114

Open
Wajihulhassan opened this issue Aug 10, 2016 · 1 comment
Open

Comprehensions Error #114

Wajihulhassan opened this issue Aug 10, 2016 · 1 comment

Comments

@Wajihulhassan
Copy link
Collaborator

I am trying out following example of Comprehensions with ParallelAccelerator but it is throwing error.

julia> @acc f(a,b)=[ x for x in a ]
f (generic function with 1 method)

julia> f([1,2,3],2)
OptFramework failed to optimize function ##f#11563 in optimization pass ParallelAccelerator.Driver.toDomainIR with error from_expr: unknown Expr head :static_typeof
ERROR: MethodError: `step` has no method matching step(::Array{Int64,1})
 in anonymous at /home/whassan/.julia/v0.4/ParallelAccelerator/src/comprehension.jl:76
 in cartesianarray at /home/whassan/.julia/v0.4/ParallelAccelerator/src/api.jl:174
 [inlined code] from /home/whassan/.julia/v0.4/ParallelAccelerator/src/comprehension.jl:73
 in ##f#11563 at none:1
 in f at /home/whassan/.julia/v0.4/CompilerTools/src/OptFramework.jl:577

I also added type annotation like in black-scholes example but it didn't work either.

@ninegua
Copy link
Contributor

ninegua commented Aug 10, 2016

Unfortunately I realized that our macro translation for comprehension does not yet support syntax such as [... for x in a] when a is an array. ParallelAccelerator only works when a is a range. I'm not even sure there is a simple fix to this, unless we move to using generators as in Julia's own implementation. But generators are sequential by nature, and hard to parallelize.

So I would suggest instead using map for situations like this. For example, map(x -> x, a) would be equivalent.

I also tried map(x -> x ? 1 : 0, (a .== b)), as you raised the question of converting bitarray to array of int in the other thread. This had a problem with Julia 0.4, and is now fixed by commit bbd8796. However, Julia 0.5 itself (not ParallelAccelerator) has trouble dealing with this expression. So the conversion is still best handed by multiplying Bool with Int.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants