How to use the fastcluster.nn_obj_approx_builder function in fastcluster

To help you get started, we’ve selected a few fastcluster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philbinj / fastcluster / fastcluster.py View on Github external
pnts_fobj = tables.openFile(pnts_fn, 'r')
    for pnts_obj in pnts_fobj.walkNodes('/', classname = 'Array'):
        break

    N = pnts_obj.shape[0]
    D = pnts_obj.shape[1]
    dtype = pnts_obj.atom.dtype
    
    if dtype not in [np.dtype('u1'), np.dtype('f4'), np.dtype('f8')]:
        raise TypeError, 'Datatype %s not supported' % dtype

    if dtype == np.dtype('u1'):
        dtype = np.dtype('f4')

    if approx:
        nn_builder = nn_obj_approx_builder(dtype, ntrees, nchecks)
    else:
        nn_builder = nn_obj_exact_builder(dtype)
    
    pnt_loader = hdf5_wrap(pnts_obj, dtype)

    # Callbacks
    LOAD_ROWS_FUNC = \
        ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint, 
                         ctypes.c_void_p)

    NN_BUILDER_FUNC = \
        ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, 
                         ctypes.c_uint, ctypes.c_uint)

    load_rows_func = LOAD_ROWS_FUNC(pnt_loader.read_rows)
    nn_builder_func = NN_BUILDER_FUNC(nn_builder.build_nn_obj)