Fix ifelse crash and gpu support

- [x] fix ifelse crash
- [ ] gpu/cpu support
v isn't a Theano variable, so you need to find the corresponding theano variable for each v.