Added Cythonized interface for TSNE.#69
Open
sadaszewski wants to merge 1 commit intolvdmaaten:masterfrom
Open
Conversation
Owner
|
Thanks, the current approach of writing data to a file and running an executable that reads those files is, indeed, super-clunky. I'm wondering if/why we need the Cython dependency though? Wouldn't this be much easier solved by calling import ctypes
tsne_lib = ctypes.cdll.LoadLibrary('libtsne.so')
c_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
c_mappedX = mappedX.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
tsne_lib.tsne_run(
c_data,
ctypes.c_int(N),
ctypes.c_int(D),
c_mappedX,
ctypes.c_int(numDims),
ctypes.c_double(perplexity),
ctypes.c_double(theta),
ctypes.c_int(randomSeed),
ctypes.c_int(skipRandomInit),
ctypes.c_int(maxIter),
ctypes.c_int(stopLyingIter),
ctypes.c_int(momSwitchIter),
)This wouldn't require any additional dependencies. What do you think? |
Author
|
Hi, thank you for a fast response. I think it is one of several
alternatives. For reference: https://stackoverflow.com/a/5686873 . I found
it quite straightforward with Cython. Also syntax sugar for specifying what
type of NumPy arrays it takes in is quite nice. It makes perfect sense to
provide ctypes interface with bhtsne and split Cython interface into a
separate package or just stick to ctypes as long as correct handling of
NumPy arrays is taken care of. Best, -- S.
…On 19 March 2018 at 19:44, Laurens van der Maaten ***@***.***> wrote:
Thanks, the current approach of writing data to a file and running an
executable that reads those files is, indeed, super-clunky.
I'm wondering if/why we need the Cython dependency though? Wouldn't this
be much easier solved by calling tsne_run via FFI? Something along these
lines ought to work:
import ctypes
tsne_lib = ctypes.cdll.LoadLibrary('libtsne.so')
c_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
c_mappedX = mappedX.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
tsne_lib.tsne_run(
c_data,
ctypes.c_int(N),
ctypes.c_int(D),
c_mappedX,
ctypes.c_int(numDims),
ctypes.c_double(perplexity),
ctypes.c_double(theta),
ctypes.c_int(randomSeed),
ctypes.c_int(skipRandomInit),
ctypes.c_int(maxIter),
ctypes.c_int(stopLyingIter),
ctypes.c_int(momSwitchIter),
)
This wouldn't require any additional dependencies. What do you think?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#69 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABUI3XaAknkg2juNl__vsAbP0eZA5yrtks5tf_ylgaJpZM4SuRYF>
.
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.