Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifications for zero vectors needed? #26

Open
baggepinnen opened this issue Nov 12, 2015 · 1 comment
Open

Simplifications for zero vectors needed? #26

baggepinnen opened this issue Nov 12, 2015 · 1 comment

Comments

@baggepinnen
Copy link

The following small example seems to produce very strange code, especially all the call to zeros() seem unnecessary?

x = randn(3)
g = randn(3)
test = quote
    d  = sum((x-g).^2)
    cs = d + log(d)
end
rdiff(ex,x=x)

julia> rdiff(ex,x=x)
quote
_tmp1 = xp - x
_tmp2 = x - goal
_tmp3 = _tmp1 .^ 2
_tmp4 = size(_tmp3)
_tmp5 = _tmp2 .^ 2
_tmp6 = sum(_tmp5)
_tmp7 = size(_tmp5)
_tmp8 = _tmp6 + c3
(((c1 * _tmp6 + c2 * log(_tmp8)) + sum(_tmp3)) + sum(u .^ 2),(zeros(size(x)) + -((zeros(size(_tmp1)) + (2_tmp1) .* (zeros(_tmp4) + ones(_tmp4))))) + (zeros(size(_tmp2)) + (2_tmp2) .* (zeros(_tmp7) + ones(_tmp7) .* (c2 / _tmp8 + c1))))
end

@baggepinnen baggepinnen changed the title Simplifications needed? Simplifications for zero vectors needed? Nov 12, 2015
@fredo-dedup
Copy link
Contributor

This is a needed enhancement. The problem is that the simplification pass on the code cannot reduce zeros(..) + x to x without knowing the type of x (it simplifies if x is an Array, but not if x is a scalar); and the type of the variables are not always known at the simplification stage.

The change needed is not too complicated but it may make rdiff() significantly slower on more complex functions. I am trying to find a better solution involving larger changes in the code.

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

No branches or pull requests

2 participants