MSchnei / pyprf_feature

Population receptive field estimation with feature weights.
GNU General Public License v3.0
2 stars 2 forks source link

Tensorflow dependency #6

Closed ingo-m closed 7 years ago

ingo-m commented 7 years ago

Very nice to see that the GPU pRF finding functionality has been put into the main branch with commit a11134c.

There is one issue that I don't know how to solve in an 'elegant' way: In pRF_main.py, the GPU function is imported: from pRF_funcFindPrfGpu import funcFindPrfGpu. In that function, tensorflow is imported: import tensorflow as tf. Now this will throw an error if tensorflow is not available (which may be the case for most users). An easy way would be an if condition, like if cfg.strVersion == 'gpu': from pRF_funcFindPrfGpu import funcFindPrfGpu. But I have some doubts whether that would be in accordance with PEP8.

Some people say conditional imports are fine: https://stackoverflow.com/a/12861052 https://stackoverflow.com/a/21298234

Others suggest using try https://stackoverflow.com/a/40974488

So it's a matter of style.

MSchnei commented 7 years ago

Thanks for spotting this and suggesting the solutions. I decided to go with: try: import tensorflow as tf except ImportError: pass

If someone in the future comes up with a better/more stylish solution, we can go for that.