def siftgeo_read(filename, outfmt='bvec'): # I/O via double pointers (too lazy to make proper swig interface) v_out = yael.BytePtrArray(1) meta_out = yael.FloatPtrArray(1) d_out = yael.ivec(2) n = yael.bvecs_new_from_siftgeo(filename, d_out, v_out.cast(), d_out.plus(1), meta_out.cast()) if n < 0: raise IOError("cannot read " + filename) if n == 0: v = None meta = None return v, meta, n d = d_out[0] d_meta = d_out[1] assert d_meta == 9 v = yael.bvec.acquirepointer(v_out[0]) if outfmt == 'fvec': v = yael.bvec2fvec(v_out[0], n * d) v = yael.fvec.acquirepointer(v) meta = yael.fvec.acquirepointer(meta_out[0]) return v, meta, n
def siftgeo_read(filename): # I/O via double pointers (too lazy to make proper swig interface) v_out = yael.BytePtrArray(1) meta_out = yael.FloatPtrArray(1) d_out = yael.ivec(2) n = yael.bvecs_new_from_siftgeo(filename, d_out, v_out.cast(), d_out.plus(1), meta_out.cast()) if n < 0: raise IOError("cannot read " + filename) if n == 0: v = numpy.array([[]], dtype = numpy.uint8) meta = numpy.array([[]*9], dtype = numpy.float32) return v, meta v_out = yael.bvec.acquirepointer(v_out[0]) meta_out = yael.fvec.acquirepointer(meta_out[0]) d = d_out[0] d_meta = d_out[1] assert d_meta == 9 v = yael.bvec_to_numpy(v_out, n * d) v = v.reshape((n, d)) meta = yael.fvec_to_numpy(meta_out, n * d_meta) meta = meta.reshape((n, d_meta)) return v, meta