lindahua / Devectorize.jl

A Julia framework for delayed expression evaluation
MIT License
115 stars 17 forks source link

Add @devec_transform for devectorizing operations with associative types #17

Closed tshort closed 11 years ago

tshort commented 11 years ago

I wrote this mainly to work with DataFrames (https://github.com/HarlanH/DataFrames.jl/issues/179), but since it is designed to work with all associative types, maybe you would like to include it with DeExpr. Here is an example:

julia> d = {:x => rand(2), :y => rand(2), :z => rand(2)}
{:x=>[0.938044, 0.638445],:y=>[0.899549, 0.122162],:z=>[0.339539, 0.136685]}

julia> @devec_transform d  z2 = sqr(z)
{:z2=>[0.115287, 0.0186828],:x=>[0.938044, 0.638445],:y=>[0.899549, 0.122162],:z=>[0.339539, 0.136685]}

julia> @devec_transform(d, xyz => x + y + z)
{:z2=>[0.115287, 0.0186828],:x=>[0.938044, 0.638445],:y=>[0.899549, 0.122162],:z=>[0.339539, 0.136685],:xyz=>[2.17713, 0.897292]}

julia> @devec_transform(d, y => y .* 2)
{:z2=>[0.115287, 0.0186828],:x=>[0.938044, 0.638445],:y=>[1.7991, 0.244324],:z=>[0.339539, 0.136685],:xyz=>[2.17713, 0.897292]}
lindahua commented 11 years ago

I am refactoring the internals DeExpr to expand its capability (e.g. allowing fields (x.abc) and more kinds of references (e.g. x[i0:i1, j0:j1], etc). I will look into these changes and see how they interact after my current refactoring work is done.