bhtsne icon indicating copy to clipboard operation
bhtsne copied to clipboard

Use of `os.fork` breaks Windows support

Open jlorince opened this issue 7 years ago • 3 comments

Changes in 5d347d14d4e9b81823865b19408067926caa205a breaks Windows support, as Windows doesn't support os.fork. Wish I could propose a fix, but I'm not sure if/how to achieve the same sort of functionality in Windows. As a stopgap, I suppose the use of the forked process could just be conditional on platform...

jlorince avatar Oct 04 '16 14:10 jlorince

Yeah that doesn't sound like a bad solution for now. I don't have access to a Windows-machine, so would you mind taking a crack at it @jlorince?

lvdmaaten avatar Oct 20 '16 19:10 lvdmaaten

@jlorince It would be helpful if you can elaborate on the stopgap solution. I'm trying to run this in windows and os.fork is causing the issues. Thanks in advance.

nitheshj avatar Oct 18 '18 15:10 nitheshj

I ended up modifying the code to remove the fork. Turns out, fork is just used to make the command prompt responsive to keyboard interrupts. Removing that also makes this compatible with jupyter and spyder.

Just replace the function with this one:

def run_bh_tsne(data, no_dims=2, perplexity=50, theta=0.5, randseed=-1, verbose=False, initial_dims=50, use_pca=True, max_iter=1000):
    '''
    Run TSNE based on the Barnes-HT algorithm

    Parameters:
    ----------
    data: file or numpy.array
        The data used to run TSNE, one sample per row
    no_dims: int
    perplexity: int
    randseed: int
    theta: float
    initial_dims: int
    verbose: boolean
    use_pca: boolean
    max_iter: int
    '''

    tmp_dir_path = mkdtemp()

    if _is_filelike_object(data):
        data = load_data(data)

    init_bh_tsne(data, tmp_dir_path, no_dims=no_dims, perplexity=perplexity, theta=theta, randseed=randseed,verbose=verbose, initial_dims=initial_dims, use_pca=use_pca, max_iter=max_iter)

    res = []
    for result in bh_tsne(tmp_dir_path, verbose):
        sample_res = []
        for r in result:
            sample_res.append(r)
        res.append(sample_res)
    rmtree(tmp_dir_path)
    return np.asarray(res, dtype='float64')

AliFlux avatar Jun 06 '19 17:06 AliFlux