gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.1k stars 652 forks source link

How to perform string operations using GPU? #655

Open contactmukulsaini opened 3 years ago

contactmukulsaini commented 3 years ago

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?

harshkhandeparkar commented 3 years ago

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.

danbulant commented 3 years ago

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("").