Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ArrayFire.js - ArrayFire for Node.js

License

NotificationsYou must be signed in to change notification settings

arrayfire/arrayfire-js

Repository files navigation

As of 0.16.0 this module has been renamed fromarrayfire_js toarrayfire-js. The oldarrayfire_js module will be available on the npm for a while.

ArrayFire.js

Please followthis issue for tracking the progress towards release of 1.0.0-beta.

About ArrayFire

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

You can read its introductionint its documentation's index page. It's basically a math accelerator C++ library supporting CPU and GPU based backends on Windows, Linux and Mac. And it's justawesome. 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.

About ArrayFire.js

ArrayFire.js is the Node.js bindings for ArrayFire, it usesCMake.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).

Requirements

  • Download and install ArrayFire (3.x RTM is supported right now). Don't forget to add%AF_PATH%\lib directory to PATH on Windows!
  • On Linux or Mac install dependencies (seeLinux andMac docs)
  • Don't forget to installCMake

Install

Before installing location of the ArrayFire installation directory have to be configured for CMake.js. There are two options:

1. Usingnpm config

for current user:

npm config set cmake_af_path "path_to_arrayfire_installation_directory"

for all users (global)

npm config set cmake_af_path "path_to_arrayfire_installation_directory" --global

2. Setting AF_PATH environment variable

AF_PATH="path_to_arrayfire_installation_directory"

On Windows the installer do this for you, so there is nothing to do on this platform, though.

The above have to be done only once. After you can install ArrayFire.js from the npm:

npm install arrayfire-js --save

Usage

// CPUvaraf=require("arrayfire-js")("CPU");// OpenCLvaraf=require("arrayfire-js")("OpenCL");// CUDAvaraf=require("arrayfire-js")("CUDA");

Examples

Calculating pi

Port of the PI calculator fromArrayFire documentation:

C++

// sample 40 million points on the GPUarray x = randu(20e6), y = randu(20e6);array dist = sqrt(x * x + y * y);// pi is ratio of how many fell in the unit circlefloat num_inside = sum<float>(dist <1);float pi =4.0 * num_inside /20e6;af_print(pi);

JavaScript

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 useES6 generators instead of callback hell or even instead of bare promises).

constnumberOfPoints=20000000;// ...letx=af.randu(numberOfPoints,af.dtype.f32);lety=af.randu(numberOfPoints,af.dtype.f32);letdist=af.sqrt(x.mul(x).add(y.mul(y)));letnumInside=yieldaf.sumAsync(dist.lt(1));letpiVal=(4.0*numInside)/numberOfPoints;console.log(`PI =${piVal}`);

It's included in theexamples folder. To run on:

  • io.js, enter:iojs examples/es6/bechmarks/pi.js
  • Node.js 0.12 or above, enter:node --harmony examples/es6/bechmarks/pi.js
  • Node.js below 0.12, enter:node examples/es5/bechmarks/pi.js

Neural Network

There is an example of a neural network with batch backpropagation trained to learn the famousMNIST data set. It will run on the fastest device available.

It's in theexamples folder. To run on:

  • io.js, enter:iojs examples/es6/machine-learning/neuralNetwork.js
  • Node.js 0.12 or above, enter:node --harmony examples/es6/machine-learning/neuralNetwork.js
  • Node.js below 0.12, enter:node examples/es5/machine-learning/neuralNetwork.js

Performance on Linux Mint x64, i5 3570, Radeon R9:

  • CPU platform: 0.8 sec / epoch
  • OpenCL platform on CPU: 1.0 sec / epoch
  • OpenCL platform on GPU:0.28 sec / epoch

API Docs

http://arrayfire.github.io/arrayfire-js

Wanna Contribute?

PRs are welcome, but please read theContributing Guide first.

License

New BSD

Copyright (c) 2014-2015, ArrayFireCopyright (c) 2015 Gábor Mező aka unbornchikken (gabor.mezo@outlook.com)All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this  list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this  list of conditions and the following disclaimer in the documentation and/or  other materials provided with the distribution. * Neither the name of the ArrayFire nor the names of its  contributors may be used to endorse or promote products derived from  this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

ArrayFire.js - ArrayFire for Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp