pybrain/pybrain — pull request #140 by SBretz (2014-11-30 06:10:12+00:00)
Title: Python 3 compatability fixes

# Changes
* First, I ran 2to3 on the library. This made basic syntax fixes to most of the library (if they had not been made in prior commits). Most commonly, these changes:
* Change the print statement to the print function.
* change instances of xrange to range and instances of range to list(range) (since range gives a xrange like iterator in 3).
* make explicit list conversions on objects that no longer return lists in python 3.
* Second, full python 3 print functionality is not backported to python 2. To cover this, I inserted from __future__ import print_function in files using print to maintain the intended effects in python 2.
* Third, many of the tests failed due to one of two issues.
* Differences in default float precision in 2 and 3. Tests that expect a certain precision were made to explicitly demand that precision.
* Unspecified integer division. This was the trickiest change. Python 3 allows the division of two integers to return a float by default, which resulted in a variety of unexpected errors and exceptions. I made integer division explicit (using int(int/int) or // rather than /) where appropriate and where I could be sure an integer result is what was expected.

# Going Forward
* Because of the difficulty of finding all explicit integers divisions, I only made fixes where I was sure they were needed (I did search all modules and examined each one). Those who find future bugs while running python 3 should check the modules utilized for division operations if there are odd errors in results, keyerrors in dictionaries, etc.
* Scipy weave is still not availible in python 3 (and likely never will be). Since it is only used in one module, and only for faster computation I simply catch the import error and ignore it for 3 users. Although there is quite some slowdown in near_optimal, it still runs. Perhaps cython should be considered for replacing the weave functionality.

# Unittests
* Below are results for the unittests on python 2.7 and 3.4

2.7

```
python2.7 pybrain/tests/runtests.py
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/structure
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/rl
INFO Tests found: pybrain.tests.unittests.datasets.test_datasets_datasets
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/optimization
INFO Tests found: pybrain.tests.unittests.auxiliary.test_pca
WARNING Module pybrain.tests.unittests.tools.test_rlgluebridge is missing dependencies: rlglue
INFO Tests found: pybrain.tests.unittests.tools.test_ibp_leftordered
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/supervised
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/unsupervised
INFO Tests found: pybrain.tests.unittests.structure.connections.test_subsampling_connection
INFO Tests found: pybrain.tests.unittests.structure.connections.test_sliced_connections
INFO Tests found: pybrain.tests.unittests.structure.connections.test_shared_connections
INFO Tests found: pybrain.tests.unittests.structure.modules.test_peephole_mdlstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_simple_lstm_network
INFO Tests found: pybrain.tests.unittests.structure.modules.test_simple_mdlstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_peephole_lstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_samplelayer
INFO No fast networks available: No module named arac.pybrainbridge
INFO Tests found: pybrain.tests.unittests.structure.networks.test_nested_ffn_and_rnn
INFO Tests found: pybrain.tests.unittests.structure.networks.test_borderswipingnetwork
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_decomposition
INFO Tests found: pybrain.tests.unittests.structure.networks.test_recurrent_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_sort
INFO Tests found: pybrain.tests.unittests.structure.networks.test_bidirectional_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_cyclic_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_swiping_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_forward_backward
INFO Tests found: pybrain.tests.unittests.structure.networks.test_no_gravity_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_nested_network
INFO Tests found: pybrain.tests.unittests.structure.networks.custom.test_capturegame_network
INFO Tests found: pybrain.tests.unittests.structure.networks.custom.test_convolutional_nets
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/rl/environments
INFO Tests found: pybrain.tests.unittests.rl.environments.twoplayergames.test_pente
INFO Tests found: pybrain.tests.unittests.rl.environments.twoplayergames.test_capture_game
INFO Tests found: pybrain.tests.unittests.optimization.populationbased.test_pso_ring
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/supervised/knn
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_rprop
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_backprop
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_evolino
INFO Tests found: pybrain.tests.unittests.supervised.knn.lsh.test_minhash
INFO Tests found: pybrain.tests.unittests.supervised.knn.lsh.test_nearoptimal
...............................
----------------------------------------------------------------------
Ran 31 tests in 19.448s

OK

```
```
python3.4 pybrain/tests/runtests.py
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/structure
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/rl
INFO Tests found: pybrain.tests.unittests.datasets.test_datasets_datasets
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/optimization
INFO Tests found: pybrain.tests.unittests.auxiliary.test_pca
WARNING Module pybrain.tests.unittests.tools.test_rlgluebridge is missing dependencies: rlglue
INFO Tests found: pybrain.tests.unittests.tools.test_ibp_leftordered
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/supervised
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/unsupervised
INFO Tests found: pybrain.tests.unittests.structure.connections.test_subsampling_connection
INFO Tests found: pybrain.tests.unittests.structure.connections.test_sliced_connections
INFO Tests found: pybrain.tests.unittests.structure.connections.test_shared_connections
INFO Tests found: pybrain.tests.unittests.structure.modules.test_peephole_mdlstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_simple_lstm_network
INFO Tests found: pybrain.tests.unittests.structure.modules.test_simple_mdlstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_peephole_lstm
INFO Tests found: pybrain.tests.unittests.structure.modules.test_samplelayer
INFO No fast networks available: No module named 'arac'
INFO Tests found: pybrain.tests.unittests.structure.networks.test_nested_ffn_and_rnn
INFO Tests found: pybrain.tests.unittests.structure.networks.test_borderswipingnetwork
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_decomposition
INFO Tests found: pybrain.tests.unittests.structure.networks.test_recurrent_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_sort
INFO Tests found: pybrain.tests.unittests.structure.networks.test_bidirectional_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_cyclic_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_swiping_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_network_forward_backward
INFO Tests found: pybrain.tests.unittests.structure.networks.test_no_gravity_network
INFO Tests found: pybrain.tests.unittests.structure.networks.test_nested_network
INFO Tests found: pybrain.tests.unittests.structure.networks.custom.test_capturegame_network
INFO Tests found: pybrain.tests.unittests.structure.networks.custom.test_convolutional_nets
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/rl/environments
INFO Tests found: pybrain.tests.unittests.rl.environments.twoplayergames.test_pente
INFO Tests found: pybrain.tests.unittests.rl.environments.twoplayergames.test_capture_game
INFO Tests found: pybrain.tests.unittests.optimization.populationbased.test_pso_ring
INFO No tests found in /home/hal/Desktop/pybrain/pybrain/tests/unittests/supervised/knn
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_rprop
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_backprop
INFO Tests found: pybrain.tests.unittests.supervised.trainers.test_evolino
INFO Tests found: pybrain.tests.unittests.supervised.knn.lsh.test_minhash
INFO Tests found: pybrain.tests.unittests.supervised.knn.lsh.test_nearoptimal
...............................
----------------------------------------------------------------------
Ran 31 tests in 28.228s

OK
```