Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vector sdk #431

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Remove HTTP Timeout, Add Context Timeout on Collections [#422](https://github.com/hypermodeinc/modus/pull/422)
- Add Modus AssemblyScript SDK [#423](https://github.com/hypermodeinc/modus/pull/423)
- Add models to Modus AssemblyScript SDK [#428](https://github.com/hypermodeinc/modus/pull/428)
- Add Vectors SDK support [#431](https://github.com/hypermodeinc/modus/pull/431)
- Update Readme files [#432](https://github.com/hypermodeinc/modus/pull/432)
- Fix vulnerability in AssemblyScript SDK install script [#435](https://github.com/hypermodeinc/modus/pull/435)
- Fix potential array out of bounds in the runtime [#437](https://github.com/hypermodeinc/modus/pull/437)
Expand Down
3 changes: 3 additions & 0 deletions sdk/assemblyscript/examples/vectors/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["assemblyscript-prettier"]
}
3 changes: 3 additions & 0 deletions sdk/assemblyscript/examples/vectors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hypermode Vectors Example Plugin

This is an example displaying the capabilities of Modus's vector support.
6 changes: 6 additions & 0 deletions sdk/assemblyscript/examples/vectors/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./node_modules/@hypermode/modus-sdk-as/plugin.asconfig.json",
"options": {
"transform": ["@hypermode/modus-sdk-as/transform", "json-as/transform"]
}
}
106 changes: 106 additions & 0 deletions sdk/assemblyscript/examples/vectors/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* This example is part of the Modus project, licensed under the Apache License 2.0.
* You may modify and use this example in accordance with the license.
* See the LICENSE file that accompanied this code for further details.
*/

import { vectors } from "@hypermode/modus-sdk-as";

export function add(a: f64[], b: f64[]): f64[] {
return vectors.add(a, b);
}

export function addInPlace(a: f64[], b: f64[]): f64[] {
vectors.addInPlace(a, b);
return a;
}

export function subtract(a: f64[], b: f64[]): f64[] {
return vectors.subtract(a, b);
}

export function subtractInPlace(a: f64[], b: f64[]): f64[] {
vectors.subtractInPlace(a, b);
return a;
}

export function addNumber(a: f64[], b: f64): f64[] {
return vectors.addNumber(a, b);
}

export function addNumberInPlace(a: f64[], b: f64): f64[] {
vectors.addNumberInPlace(a, b);
return a;
}

export function subtractNumber(a: f64[], b: f64): f64[] {
return vectors.subtractNumber(a, b);
}

export function subtractNumberInPlace(a: f64[], b: f64): f64[] {
vectors.subtractNumberInPlace(a, b);
return a;
}

export function multiplyNumber(a: f64[], b: f64): f64[] {
return vectors.multiplyNumber(a, b);
}

export function multiplyNumberInPlace(a: f64[], b: f64): f64[] {
vectors.multiplyNumberInPlace(a, b);
return a;
}

export function divideNumber(a: f64[], b: f64): f64[] {
return vectors.divideNumber(a, b);
}

export function divideNumberInPlace(a: f64[], b: f64): f64[] {
vectors.divideNumberInPlace(a, b);
return a;
}

export function dot(a: f64[], b: f64[]): f64 {
return vectors.dot(a, b);
}

export function magnitude(a: f64[]): f64 {
return vectors.magnitude(a);
}

export function normalize(a: f64[]): f64[] {
return vectors.normalize(a);
}

export function sum(a: f64[]): f64 {
return vectors.sum(a);
}

export function product(a: f64[]): f64 {
return vectors.product(a);
}

export function mean(a: f64[]): f64 {
return vectors.mean(a);
}

export function min(a: f64[]): f64 {
return vectors.min(a);
}

export function max(a: f64[]): f64 {
return vectors.max(a);
}

export function abs(a: f64[]): f64[] {
return vectors.abs(a);
}

export function absInPlace(a: f64[]): f64[] {
vectors.absInPlace(a);
return a;
}

export function euclidianDistance(a: f64[], b: f64[]): f64 {
return vectors.euclidianDistance(a, b);
}
4 changes: 4 additions & 0 deletions sdk/assemblyscript/examples/vectors/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": ["./**/*.ts"]
}
11 changes: 11 additions & 0 deletions sdk/assemblyscript/examples/vectors/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import aseslint from "@hypermode/modus-sdk-as/tools/assemblyscript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
aseslint.config,
);
12 changes: 12 additions & 0 deletions sdk/assemblyscript/examples/vectors/hypermode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://manifest.hypermode.com/hypermode.json",
"models": {
// No models are used by this example, but if you add any, they would go here.
},
"hosts": {
// No hosts are used by this example, but if you add any, they would go here.
},
"collections": {
// No collections are used by this example, but if you add any, they would go here.
}
}
Loading
Loading