Пример #1
0
ctypes_fvec_150_t = ctypes.c_float * 150

ctypes_fvec = ctypes_fvec_150_t()

ctypes_fvec[0] = 1001
ctypes_fvec[1] = 1002

print "  read in Yael:",

yael_fvec = yael.fvec_from_pointer_long(ctypes.addressof(ctypes_fvec))
yael_fvec = yael.fvec.frompointer(yael_fvec)

print yael_fvec[0], yael_fvec[1]

print "Yael -> ctypes"

print "  init in Yael"

yael_fvec = yael.fvec(30)

yael_fvec[0] = 2001
yael_fvec[1] = 2002

print "  read in ctypes",

ctypes_fvec_t = ctypes.POINTER(ctypes.c_float)
ctypes_fvec = ctypes.cast(yael.fvec_to_pointer_long(yael_fvec), ctypes_fvec_t)

print ctypes_fvec[0], ctypes_fvec[1]
Пример #2
0
        d = int(args.pop(0))
    elif a == '-nt':
        nt = threads.parse_nt(args.pop(0))
    else:
        print >> sys.stderr, "unknown arg", a
        sys.exit(1)

(nb, sizeb, szb) = yutils.vecfile_stats(fb_name, d, fmt_b)
(nq, sizeq, szq) = yutils.vecfile_stats(fq_name, d, fmt_q)

(vb, nb) = yutils.load_vectors_fmt(fb_name, fmt_b, d)

print 'nb=%d  db=%d  nq=%d  ' % (nb, sizeb, nq)

nn = yael.ivec(slice_size * k)
nndis = yael.fvec(slice_size * k)

fnn = open(fnn_name, 'w')
fdis = open(fdis_name, 'w')

t0 = time.time()
for istart in xrange(0, nq, slice_size):

    iend = min(istart + slice_size, nq)
    nqslice = iend - istart

    # Read the queries
    (vq, nqslice2) = yutils.load_vectors_fmt(fq_name,
                                             fmt_q,
                                             d,
                                             nqslice,
import time

from yael import yael

yael.common_srandom(12345)

d = 16
n = 1024
k = 4

pts = yael.fvec_new_rand(d * n)

pts = yael.fvec.acquirepointer(pts)

cents = yael.fvec(d * k)

nt = 1
assign = yael.ivec(n)


def d_chi2(a, b):
    return (a - b)**2 / (a + b)


print "clustering %d uniform %dD pts in %d centroids" % (n, d, k)

for name, flags in ("L2", 0), ("L1", yael.KMEANS_L1), ("Chi2",
                                                       yael.KMEANS_CHI2):
    print "%s clustering" % name

    t0 = time.time()
Пример #4
0
ctypes_fvec = ctypes_fvec_150_t()

ctypes_fvec[0] = 1001 
ctypes_fvec[1] = 1002

print "  read in Yael:",

yael_fvec = yael.fvec_from_pointer_long(ctypes.addressof(ctypes_fvec))
yael_fvec = yael.fvec.frompointer(yael_fvec)

print yael_fvec[0], yael_fvec[1]

print "Yael -> ctypes"

print "  init in Yael"

yael_fvec = yael.fvec(30)

yael_fvec[0] = 2001
yael_fvec[1] = 2002


print "  read in ctypes",

ctypes_fvec_t = ctypes.POINTER(ctypes.c_float)
ctypes_fvec = ctypes.cast(yael.fvec_to_pointer_long(yael_fvec), ctypes_fvec_t)

print ctypes_fvec[0], ctypes_fvec[1]

Пример #5
0
import time

from yael import yael

yael.common_srandom(12345)

d=16
n=1024
k=4

pts = yael.fvec_new_rand(d * n)

pts = yael.fvec.acquirepointer(pts)

cents = yael.fvec(d * k)

nt = 1
assign = yael.ivec(n)
  

def d_chi2(a, b):
  return (a - b) ** 2 / (a + b)

print "clustering %d uniform %dD pts in %d centroids" % (n, d, k) 

for name, flags in ("L2", 0), ("L1", yael.KMEANS_L1), ("Chi2", yael.KMEANS_CHI2):
  print "%s clustering" % name 

  t0 = time.time()
  
Пример #6
0
     elif a=='-nt': 
         nt = threads.parse_nt(args.pop(0))
     else: 
         print >> sys.stderr, "unknown arg",a
         sys.exit(1)

(nb, sizeb, szb) = yutils.vecfile_stats (fb_name, d, fmt_b)
(nq, sizeq, szq) = yutils.vecfile_stats (fq_name, d, fmt_q)

(vb, nb) = yutils.load_vectors_fmt (fb_name, fmt_b, d)

print 'nb=%d  db=%d  nq=%d  ' % (nb, sizeb, nq)


nn = yael.ivec (slice_size * k)
nndis = yael.fvec (slice_size * k)

fnn = open (fnn_name, 'w')
fdis = open (fdis_name, 'w')

t0 = time.time()
for istart in xrange (0, nq, slice_size):

    iend = min (istart + slice_size, nq)
    nqslice = iend - istart

    # Read the queries
    (vq, nqslice2) = yutils.load_vectors_fmt (fq_name, fmt_q, d, nqslice, istart, verbose=False)
    assert nqslice == nqslice2

    yael.knn_full_thread(distance_type, nqslice, nb, d, k,