How to use the fastcluster.hdf5_wrap 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
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)

    # Space for the clusters
    clusters = np.empty((K, D), dtype = dtype)
    clusters_ptr = clusters.ctypes.data_as(ctypes.c_void_p)