{"id":13408167,"url":"https://github.com/nodeca/multimath","last_synced_at":"2025-04-13T08:25:01.021Z","repository":{"id":57305306,"uuid":"88389416","full_name":"nodeca/multimath","owner":"nodeca","description":"WebAssembly wrapper to simplify fast math coding","archived":false,"fork":false,"pushed_at":"2021-05-11T14:16:11.000Z","size":94,"stargazers_count":72,"open_issues_count":0,"forks_count":5,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-13T08:24:58.436Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodeca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-16T03:48:00.000Z","updated_at":"2025-04-06T10:10:32.000Z","dependencies_parsed_at":"2022-09-20T20:52:25.226Z","dependency_job_id":null,"html_url":"https://github.com/nodeca/multimath","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fmultimath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fmultimath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fmultimath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fmultimath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeca","download_url":"https://codeload.github.com/nodeca/multimath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248682173,"owners_count":21144806,"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":"2024-07-30T20:00:51.152Z","updated_at":"2025-04-13T08:25:00.984Z","avatar_url":"https://github.com/nodeca.png","language":"JavaScript","readme":"multimath\n=========\n\n[![Build Status](https://travis-ci.org/nodeca/multimath.svg?branch=master)](https://travis-ci.org/nodeca/multimath)\n[![NPM version](https://img.shields.io/npm/v/multimath.svg)](https://www.npmjs.org/package/multimath)\n\n\u003e Core to create fast image math in WebAssembly and JS.\n\n`multimath` simplifies creation of small CPU-intensive webassembly modules\nwith fallback to JavaScript implementations.\n\n- It cares about modules init, memory management and other things.\n- Has built-in helpers to write webassembly code without additional runtimes.\n- Use shared memory to chain webassembly calls without memory copy.\n\nBuilt-in functions (curently - unsharp mask) are available as examples for your\nextensions.\n\n\nInstall\n-------\n\n```bash\nnpm install multimath\n```\n\n\nUse\n---\n\n```js\nconst mm = require('multimath')()\n             .use(require('multimath/lib/unsharp_mask'))\n             .use(require('your_custom_module'))\n\n// Simple sync call. Will use sync wasm compile. Ok for webworkers.\n// Can freeze interface at first call if wasm source is too big.\nmm.unsharp_mask(rgba_buffer, width, height);\n\n// Async init, compile all modules at once in async way.\nmm.init().then(() =\u003e {\n  mm.unsharp_mask(rgba_buffer, width, height);\n});\n```\n\n\nAPI\n---\n\n\n### new multimath(options)\n\nCreate library instance. Sugar - `multimath()` (without `new`).\n\n```js\nconst mm = require('multimath')({\n  // Options are not mandatory, but you can disable js or ww\n  // implementations for testing\n  js:   true,\n  wasm: true\n});\n```\n\n\n### .use(module)\n\nRegister new module, format is:\n\n```js\n{\n  name:     String,    // default wasm module \u0026 function name to expose\n  fn:       Function,  // JS implementation\n  wasm_fn:  Function,  // WebAssembly glue\n  wasm_src: String     // Base64 encoded WebAssembly module\n}\n```\n\nSee example implementation in `lib/` folder.\n\n\n### .init() -\u003e Promise\n\nOptional. Compile all wasm modules in async way. May be useful in this cases:\n\n1. If you have wasm module \u003e 4K AND run multimath in the main thread (not in\n   webworker). Some browsers prohibit sync wasm creation in this case.\n2. If you have a lot of small modules and wish to init everything before run\n   in the main thread, withoutinterface freeze.\n\nProbably, you will never need to use this method. Note, 3K was file is\ninitialized in ~ 3ms.\n\n\n### .\u003cyour_method\u003e\n\nAll modules, loaded via `.use()`, pin their methods to current `Multimath`\ninstance. The best implementation will be selected automatically (depends on\nbrowser features and constructor options);\n\n\n### Development\n\nWays to go with your own modules:\n\n- See `package.json`\n- See `./lib/unsharp_mask` as example and... of cause `./index.js`.\n\nAlso, see how [pica](https://github.com/nodeca/pica)\nuse this library.\n\n\nLicence\n-------\n\n[MIT](https://github.com/nodeca/multimath/blob/master/LICENSE)\n","funding_links":[],"categories":["Packages","Repository","包","目录","Math"],"sub_categories":["Math","数学"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fmultimath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeca%2Fmultimath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fmultimath/lists"}