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

Added python3 support #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyflann/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from index import *
from io.dataset import load, save
from __future__ import absolute_import
from .index import *
from .io.dataset import load, save
try:
from io.hdf5_dataset import load_range
from .io.hdf5_dataset import load_range
except:
pass
3 changes: 2 additions & 1 deletion pyflann/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import absolute_import
#from pyflann import *
#from pyflann_parameters import parameter_list, algorithm_names
#from pyflann_parameters import centers_init_names, log_level_names
from flann_ctypes import *
from .flann_ctypes import *
16 changes: 12 additions & 4 deletions pyflann/bindings/flann_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def __init__(self):
self.update(self._defaults_)

def update(self, dict):
for k, v in dict.iteritems():
try:
iteritems = dict.iteritems()
except AttributeError:
iteritems = dict.items()
for k, v in iteritems:
if k in self.__field_names:
setattr(self, k, self.__translate(k, v))

Expand All @@ -75,7 +79,11 @@ def __translate(self, k, v):

def __translate_back(self, k, v):
if k in self._translation_:
for tk, tv in self._translation_[k].iteritems():
try:
iteritems = self._translation_[k].iteritems()
except AttributeError:
iteritems = self._translation_[k].items()
for tk, tv in iteritems:
if tv == v:
return tk
return v
Expand Down Expand Up @@ -148,7 +156,7 @@ def load_flann_library():
try:
flannlib = cdll[os.path.join(root_dir, libdir, libname)]
return flannlib
except Exception, e:
except Exception as e:
pass
tmp = os.path.dirname(root_dir)
if tmp == root_dir:
Expand Down Expand Up @@ -198,7 +206,7 @@ class FlannLib:

def define_functions(str):
for type in type_mappings:
exec str % {'C': type[0], 'numpy': type[1]}
exec(str % {'C': type[0], 'numpy': type[1]})

flann.build_index = {}
define_functions(r"""
Expand Down
5 changes: 3 additions & 2 deletions pyflann/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from bindings.flann_ctypes import *
from io.dataset import *
from __future__ import absolute_import
from .bindings.flann_ctypes import *
from .io.dataset import *
import numpy.random as _rn


Expand Down
3 changes: 2 additions & 1 deletion pyflann/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from dataset import *
from __future__ import absolute_import
from .dataset import *
12 changes: 6 additions & 6 deletions pyflann/io/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import with_statement
from __future__ import with_statement, absolute_import

from pyflann.exceptions import FLANNException
import binary_dataset
import dat_dataset
import npy_dataset
import hdf5_dataset
from . import binary_dataset
from . import dat_dataset
from . import npy_dataset
from . import hdf5_dataset

import os.path
from numpy import float32
Expand Down Expand Up @@ -58,5 +58,5 @@ def save(dataset, filename, format = None, **kwargs):
format = extension[1:]
handler = dataset_formats[format]
handler.save(dataset, filename, **kwargs)
except Exception,e:
except Exception as e:
raise FLANNException(e)
6 changes: 3 additions & 3 deletions pyflann/io/hdf5_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
have_h5py = True
try:
import h5py
except Exception,e:
except Exception as e:
have_h5py = False

if not have_h5py:
Expand Down Expand Up @@ -64,7 +64,7 @@ def save(dataset, filename, **kwargs):
h5file = h5py.File(filename)
h5file.create_dataset(dataset_name, data=dataset)
h5file.close()
except Exception,e:
except Exception as e:
h5file.close()
raise FLANNException(e)

Expand All @@ -82,7 +82,7 @@ def load(filename, rows = -1, cols = -1, dtype = numpy.float32, **kwargs):
data = numpy.array(h5file[node])
h5file.close()
return data
except Exception,e:
except Exception as e:
h5file.close()
raise FLANNException(e)

Expand Down