{"id":25151,"library":"cwise-compiler","title":"cwise-compiler","description":"cwise-compiler is the internal compiler component of the cwise library for ndarray-optimized operations. Version 1.1.3 is the current stable release. It provides a lower-level API to compile cwise procedures directly, bypassing the parser (cwise-parser) and esprima. This package is intended for advanced users who need to skip the standard cwise interface. It compiles a procedure object containing parsed pre, body, and post functions into optimized JavaScript. The main differentiator is its role as a core piece of the cwise ecosystem, offering a minimal, direct compilation path for ndarray operations.","status":"maintenance","version":"1.1.3","language":"javascript","source_language":"en","source_url":"git://github.com/scijs/cwise-compiler","tags":["javascript","cwise","ndarray","compiler"],"install":[{"cmd":"npm install cwise-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add cwise-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add cwise-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to parse procedure code if not already parsed; optional if user provides parsed functions","package":"cwise-parser","optional":true}],"imports":[{"note":"Default export is the compiler function; named import is incorrect.","wrong":"const { compiler } = require('cwise-compiler')","symbol":"default export","correct":"import compiler from 'cwise-compiler'"},{"note":"CommonJS require gives the function directly; no .default needed.","wrong":"const compiler = require('cwise-compiler').default","symbol":"compiler function","correct":"const compiler = require('cwise-compiler')"},{"note":"The module has no named exports; namespace import is incorrect.","wrong":"import * as compiler from 'cwise-compiler'","symbol":"TypeScript import","correct":"import compiler from 'cwise-compiler'"}],"quickstart":{"code":"const compiler = require('cwise-compiler');\n\nconst procedure = {\n  args: ['array', 'array'],\n  pre: { body: 'function pre() { var a = 0; }', args: [], thisVars: ['a'], localVars: [] },\n  body: { body: 'function body(a, b) { a = b + 1; }', args: ['a', 'b'], thisVars: [], localVars: [] },\n  post: { body: 'function post() { }', args: [], thisVars: [], localVars: [] },\n  funcName: 'addOne',\n  blockSize: 64,\n  debug: false\n};\n\nconst compiled = compiler(procedure);\nconsole.log(typeof compiled); // function","lang":"javascript","description":"Demonstrates compiling a simple procedure that adds one to each element of an ndarray."},"warnings":[{"fix":"Ensure procedure object includes all required fields: args, pre, body, post, funcName, blockSize, debug.","message":"Procedure object must have exactly specified fields; missing or extra fields cause errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use cwise package instead of calling cwise-compiler directly.","message":"This package is deprecated in favor of using the higher-level cwise API directly. Direct use is not recommended.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use cwise-parser to parse raw function strings into the required format, or ensure you provide correctly structured objects.","message":"The pre, body, post functions must be parsed objects with specific structure (body, args, thisVars, localVars), not raw functions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Match the args array to the types and order of arrays passed to the compiled function.","message":"The compiled function expects ndarray arguments in the order specified by args; mismatched types cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Check that the procedure object has correctly formed pre, body, post sub-objects each with a 'body' string property.","cause":"Missing or misspelled 'body' field in the procedure object; likely a typo in pre/body/post.","error":"TypeError: Cannot read property 'body' of undefined"},{"fix":"Ensure args is an array of strings like 'array', 'scalar', 'index', 'shape', etc., as defined by cwise.","cause":"The args array contains unsupported type strings or numbers.","error":"Error: Invalid args array passed to compiler"},{"fix":"Add 'a' to the localVars array of the corresponding pre/body/post object, or ensure it's an argument.","cause":"The body function uses variable 'a' but it is not listed in localVars or args.","error":"ReferenceError: a is not defined (in compiled function)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}