-
Notifications
You must be signed in to change notification settings - Fork 58
Migrate to PyTorch tokenizers #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
306a916
6d49443
ff95301
ed3298e
c8ecf50
cc00c58
7e36a05
8aaf940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,12 @@ getValue<std::vector<int64_t>>(const jsi::Value &val, jsi::Runtime &runtime) { | |
| return getArrayAsVector<int64_t>(val, runtime); | ||
| } | ||
|
|
||
| template <> | ||
| inline std::vector<uint64_t> | ||
| getValue<std::vector<uint64_t>>(const jsi::Value &val, jsi::Runtime &runtime) { | ||
| return getArrayAsVector<uint64_t>(val, runtime); | ||
| } | ||
|
|
||
| // Template specializations for std::span<T> types | ||
| template <> | ||
| inline std::span<float> getValue<std::span<float>>(const jsi::Value &val, | ||
|
|
@@ -273,6 +279,12 @@ inline std::span<int64_t> getValue<std::span<int64_t>>(const jsi::Value &val, | |
| return getTypedArrayAsSpan<int64_t>(val, runtime); | ||
| } | ||
|
|
||
| template <> | ||
| inline std::span<uint64_t> | ||
| getValue<std::span<uint64_t>>(const jsi::Value &val, jsi::Runtime &runtime) { | ||
| return getTypedArrayAsSpan<uint64_t>(val, runtime); | ||
| } | ||
|
|
||
| // Conversion from C++ types to jsi -------------------------------------------- | ||
|
|
||
| // Implementation functions might return any type, but in a promise we can only | ||
|
|
@@ -293,6 +305,15 @@ inline jsi::Value getJsiValue(const std::vector<int32_t> &vec, | |
| return {runtime, array}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(const std::vector<uint64_t> &vec, | ||
msluszniak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| jsi::Runtime &runtime) { | ||
| jsi::Array array(runtime, vec.size()); | ||
| for (size_t i = 0; i < vec.size(); i++) { | ||
| array.setValueAtIndex(runtime, i, jsi::Value(static_cast<double>(vec[i]))); | ||
| } | ||
| return {runtime, array}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(const std::vector<float> &vec, | ||
| jsi::Runtime &runtime) { | ||
| jsi::Array array(runtime, vec.size()); | ||
|
|
@@ -302,6 +323,16 @@ inline jsi::Value getJsiValue(const std::vector<float> &vec, | |
| return {runtime, array}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(const std::vector<std::string> &vec, | ||
| jsi::Runtime &runtime) { | ||
| jsi::Array array(runtime, vec.size()); | ||
| for (size_t i = 0; i < vec.size(); i++) { | ||
| array.setValueAtIndex(runtime, i, | ||
| jsi::String::createFromUtf8(runtime, vec[i])); | ||
| } | ||
| return {runtime, array}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(const std::vector<char> &vec, | ||
| jsi::Runtime &runtime) { | ||
| jsi::Array array(runtime, vec.size()); | ||
|
|
@@ -311,10 +342,28 @@ inline jsi::Value getJsiValue(const std::vector<char> &vec, | |
| return {runtime, array}; | ||
| } | ||
|
|
||
| // Conditional as on android, size_t and uint64_t reduce to the same type, | ||
| // introducing ambiguity | ||
| template <typename T, | ||
| typename = std::enable_if_t<std::is_same_v<T, size_t> && | ||
| !std::is_same_v<size_t, uint64_t>>> | ||
| inline jsi::Value getJsiValue(T val, jsi::Runtime &runtime) { | ||
| return jsi::Value(static_cast<double>(val)); | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(uint64_t val, jsi::Runtime &runtime) { | ||
| jsi::BigInt bigInt = jsi::BigInt::fromUint64(runtime, val); | ||
| return {runtime, bigInt}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(int val, jsi::Runtime &runtime) { | ||
| return {runtime, val}; | ||
| } | ||
|
|
||
| inline jsi::Value getJsiValue(bool val, jsi::Runtime &runtime) { | ||
| return jsi::Value(val); | ||
| } | ||
|
Comment on lines
+363
to
+365
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be above the template and below
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you tell the reason for that, aesthetic one?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for msluszniak.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aesthetic one |
||
|
|
||
| inline jsi::Value getJsiValue(const std::shared_ptr<OwningArrayBuffer> &buf, | ||
| jsi::Runtime &runtime) { | ||
| jsi::ArrayBuffer arrayBuffer(runtime, buf); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.