{"id":28538112,"url":"https://github.com/arrayfire/arrayfire-js","last_synced_at":"2025-07-08T08:32:06.453Z","repository":{"id":32659676,"uuid":"36247322","full_name":"arrayfire/arrayfire-js","owner":"arrayfire","description":"ArrayFire.js - ArrayFire for Node.js","archived":false,"fork":false,"pushed_at":"2017-01-04T21:22:53.000Z","size":1621,"stargazers_count":119,"open_issues_count":9,"forks_count":11,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-09T18:11:38.712Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arrayfire.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-25T18:25:18.000Z","updated_at":"2024-10-24T08:35:28.000Z","dependencies_parsed_at":"2022-09-14T08:50:25.484Z","dependency_job_id":null,"html_url":"https://github.com/arrayfire/arrayfire-js","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/arrayfire/arrayfire-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Farrayfire-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Farrayfire-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Farrayfire-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Farrayfire-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arrayfire","download_url":"https://codeload.github.com/arrayfire/arrayfire-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arrayfire%2Farrayfire-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264231738,"owners_count":23576684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T18:11:18.307Z","updated_at":"2025-07-08T08:32:06.428Z","avatar_url":"https://github.com/arrayfire.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NOTICE: \n\nAs of 0.16.0 this module has been renamed from `arrayfire_js` to `arrayfire-js`. The old `arrayfire_js` module will be available on the npm for a while.\n\n# ArrayFire.js\n\n**Please follow [this issue](https://github.com/arrayfire/arrayfire-js/issues/1) for tracking the progress towards release of 1.0.0-beta.**\n\n## About ArrayFire\n\n*\"ArrayFire is a high performance software library for parallel computing with an easy-to-use API. Its array based function set makes parallel programming more accessible.\"*\n\nYou can read its introduction [int its documentation's index page](http://www.arrayfire.com/docs/index.htm). It's basically a math accelerator C++ library supporting CPU and GPU based backends on Windows, Linux and Mac. And it's just **awesome**. It's extremely simple to write the most complex mathematical, statistical, logical computations, image transformations and computer vision algorigthms with it, just a few lines of code. It has excellent batching capability that takes simple operations, make a big computation from them, and runs all at once on the GPU device.\n\n## About ArrayFire.js\n\nArrayFire.js is the Node.js bindings for ArrayFire, it uses [CMake.js](https://github.com/unbornchikken/cmake-js) as of its build system. It takes Node.js' insane level of productivity and mix that with ArrayFire's insane level of performance and simplicity. You'll get something like Matlab just in familiar JavaScript with performance level of x100+ compared to V8 computation preformance (with a good GPU).\n\n## Requirements\n\n- [Download](http://arrayfire.com/download/) and install ArrayFire (3.x RTM is supported right now). Don't forget to add `%AF_PATH%\\lib` directory to PATH on Windows!    \n- On Linux or Mac install dependencies (see [Linux](https://github.com/arrayfire/arrayfire/wiki/Build-Instructions-for-Linux#installing-dependencies) and [Mac docs](https://github.com/arrayfire/arrayfire/wiki/Build-Instructions-for-OSX#installing-dependencies))\n- Don't forget to install [CMake](http://www.cmake.org/)\n\n## Install\n\nBefore installing location of the ArrayFire installation directory have to be configured for CMake.js. There are two options:\n\n**1. Using [npm config](https://github.com/unbornchikken/cmake-js#npm-config-integration)**\n\n**for current user:**\n\n```\nnpm config set cmake_af_path \"path_to_arrayfire_installation_directory\"\n```\n\n**for all users (global)**\n\n```\nnpm config set cmake_af_path \"path_to_arrayfire_installation_directory\" --global\n```\n\n**2. Setting AF_PATH environment variable**\n\n```\nAF_PATH=\"path_to_arrayfire_installation_directory\"\n```\n\nOn Windows the installer do this for you, so there is nothing to do on this platform, though.\n\nThe above have to be done only once. After you can install ArrayFire.js from the npm:\n\n```\nnpm install arrayfire-js --save\n```\n\n## Usage\n\n```js\n// CPU\nvar af = require(\"arrayfire-js\")(\"CPU\");\n// OpenCL\nvar af = require(\"arrayfire-js\")(\"OpenCL\");\n// CUDA\nvar af = require(\"arrayfire-js\")(\"CUDA\");\n```\n\n## Examples\n\n### Calculating pi\n\nPort of the PI calculator from [ArrayFire documentation](http://www.arrayfire.com/docs/index.htm):\n\n**C++**\n\n```C++\n// sample 40 million points on the GPU\narray x = randu(20e6), y = randu(20e6);\narray dist = sqrt(x * x + y * y);\n\n// pi is ratio of how many fell in the unit circle\nfloat num_inside = sum\u003cfloat\u003e(dist \u003c 1);\nfloat pi = 4.0 * num_inside / 20e6;\naf_print(pi);\n```\n\n**JavaScript**\n\n*Notice: Remember, in Node.js everything that blocks or might blocks should be asynchronous, so it is advised to call asynchronous variants of ArrayFire.js functions, however there are synchronous counterparts available too for supporting REPL scenarios. (I suggest use [ES6 generators](http://arrayfire.github.io/arrayfire-js/#how-to-use-es6-generators) instead of callback hell or even instead of bare promises).*\n\n```js\nconst numberOfPoints = 20000000;\n\n// ...\n\nlet x = af.randu(numberOfPoints, af.dtype.f32);\nlet y = af.randu(numberOfPoints, af.dtype.f32);\nlet dist = af.sqrt(x.mul(x).add(y.mul(y)));\nlet numInside = yield af.sumAsync(dist.lt(1));\nlet piVal = (4.0 *  numInside) / numberOfPoints;\n\nconsole.log(`PI = ${piVal}`);\n```\n\nIt's included in the [examples folder](https://github.com/arrayfire/arrayfire-js/blob/master/examples/es6/bechmarks/pi.js). To run on:\n\n- io.js, enter: `iojs examples/es6/bechmarks/pi.js`\n- Node.js 0.12 or above, enter: `node --harmony examples/es6/bechmarks/pi.js`\n- Node.js below 0.12, enter: `node examples/es5/bechmarks/pi.js`\n\n### Neural Network\n\nThere is an example of a neural network with batch backpropagation trained to learn the famous [MNIST](http://yann.lecun.com/exdb/mnist/) data set. It will run on the fastest device available.\n\nIt's in the [examples folder](https://github.com/arrayfire/arrayfire-js/blob/master/examples/es6/machine-learning/neuralNetwork.js). To run on:\n\n- io.js, enter: `iojs examples/es6/machine-learning/neuralNetwork.js`\n- Node.js 0.12 or above, enter: `node --harmony examples/es6/machine-learning/neuralNetwork.js`\n- Node.js below 0.12, enter: `node examples/es5/machine-learning/neuralNetwork.js`\n\nPerformance on Linux Mint x64, i5 3570, Radeon R9:\n\n- CPU platform: 0.8 sec / epoch\n- OpenCL platform on CPU: 1.0 sec / epoch\n- OpenCL platform on GPU: **0.28 sec / epoch**\n\n## API Docs\n\n[http://arrayfire.github.io/arrayfire-js](http://arrayfire.github.io/arrayfire-js/)\n\n## Wanna Contribute?\n\nPRs are welcome, but please read the [Contributing Guide](https://github.com/arrayfire/arrayfire-js/blob/master/CONTRIBUTING.md) first.\n\n## License\n\n[New BSD](https://github.com/arrayfire/arrayfire-js/blob/master/LICENSE)\n\n```\nCopyright (c) 2014-2015, ArrayFire\nCopyright (c) 2015 Gábor Mező aka unbornchikken (gabor.mezo@outlook.com)\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n * Redistributions in binary form must reproduce the above copyright notice, this\n  list of conditions and the following disclaimer in the documentation and/or\n  other materials provided with the distribution.\n\n * Neither the name of the ArrayFire nor the names of its\n  contributors may be used to endorse or promote products derived from\n  this software without specific prior written permission.\n \nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farrayfire%2Farrayfire-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farrayfire%2Farrayfire-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farrayfire%2Farrayfire-js/lists"}