Socket
Socket
Sign inDemoInstall

cwise-compiler

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cwise-compiler

cwise's internal compiler


Version published
Weekly downloads
427K
increased by7.17%
Maintainers
1
Created
Weekly downloads
 

Package description

What is cwise-compiler?

The cwise-compiler npm package is a tool for compiling high-performance, multidimensional array operations in JavaScript. It allows users to define custom operations on arrays that are optimized for performance, making it suitable for scientific computing, image processing, and other tasks that require efficient manipulation of large datasets.

What are cwise-compiler's main functionalities?

Element-wise Operations

This feature allows you to perform element-wise operations on arrays. In the example, the `add` function adds a scalar value to each element of the input array `b` and stores the result in array `a`.

const cwise = require('cwise-compiler');

const add = cwise({
  args: ['array', 'array', 'scalar'],
  body: function(a, b, c) {
    a = b + c;
  }
});

const a = [1, 2, 3];
const b = [4, 5, 6];
add(a, b, 10);
console.log(a); // Output: [14, 15, 16]

Custom Reduction Operations

This feature allows you to define custom reduction operations. In the example, the `sum` function calculates the sum of all elements in the input array `a`.

const cwise = require('cwise-compiler');

const sum = cwise({
  args: ['array'],
  pre: function() {
    this.sum = 0;
  },
  body: function(a) {
    this.sum += a;
  },
  post: function() {
    return this.sum;
  }
});

const a = [1, 2, 3, 4];
const result = sum(a);
console.log(result); // Output: 10

Conditional Operations

This feature allows you to perform conditional operations on arrays. In the example, the `threshold` function sets elements of the input array `a` to 0 if they are less than the scalar threshold value `t`.

const cwise = require('cwise-compiler');

const threshold = cwise({
  args: ['array', 'scalar'],
  body: function(a, t) {
    if (a < t) {
      a = 0;
    }
  }
});

const a = [1, 5, 3, 7];
threshold(a, 4);
console.log(a); // Output: [0, 5, 0, 7]

Other packages similar to cwise-compiler

Readme

Source

cwise-compiler

Just the compiler from cwise. You can call this directly if you know what you are doing and want to skip calling cwise-parser and including esprima. This is only recommended in extreme cases though. Otherwise you should stick to the default interface in cwise and not mess around with this craziness.

Install

npm install cwise-compiler

require("cwise-compiler")(procedure)

Compiles a cwise procedure for the given procedure. The object procedure must have the following fields:

  • args An array of argument types (as in cwise)
  • pre A parsed pre function
  • body A parsed body function
  • post A parsed post function
  • funcName
  • blockSize
  • debug

Credits

(c) 2013 Mikola Lysenko. MIT License

Keywords

FAQs

Last updated on 16 Jul 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc