gpu.js icon indicating copy to clipboard operation
gpu.js copied to clipboard

How to perform string operations using GPU?

Open contactmukulsaini opened this issue 4 years ago • 2 comments

I want to perform the string operations on 1D array which is currently not possible to do with GPU.js. Is it in the roadmap and by when can can we expect that?

contactmukulsaini avatar Dec 25 '20 17:12 contactmukulsaini

Strings are unfortunately not supported at all. This is because GPU.js transpiles the JS into a much lower-level language called GLSL which runs on the GPU. This language doesn't even have strings as a data type so strings in js are not supported :( But you can convert the strings into a number (maybe ASCII numbers) and then manipulate that somehow.

harshkhandeparkar avatar Dec 25 '20 18:12 harshkhandeparkar

You can convert the string into an array of numbers using string.split("").map(t => t.charCodeAt(0)). You can then manipulate that string in the GPU and convert it back using result.map(t => String.fromCharCode(t)).join("").

danbulant avatar Apr 03 '21 08:04 danbulant