Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Oct 8, 2024
1 parent 7817104 commit 1c97573
Show file tree
Hide file tree
Showing 10 changed files with 3,571 additions and 3 deletions.
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

0 comments on commit 1c97573

Please sign in to comment.