@neuralforge/core 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@neuralforge/core",
3
+ "version": "0.9.0",
4
+ "description": "ML inference SDK for JavaScript",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "vitest",
10
+ "lint": "eslint src/"
11
+ },
12
+ "dependencies": {
13
+ "typescript": "^5.4.0"
14
+ },
15
+ "devDependencies": {
16
+ "vitest": "^1.6.0",
17
+ "eslint": "^8.57.0"
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * CPU backend
3
+ */
4
+
5
+ export interface BackendOptions {
6
+ device?: string;
7
+ precision?: 'float32' | 'float16';
8
+ }
9
+
10
+ export class CPUBackend {
11
+ private options: BackendOptions;
12
+
13
+ constructor(options: BackendOptions = {}) {
14
+ this.options = options;
15
+ }
16
+
17
+ async initialize(): Promise<void> { /* CPU init */ }
18
+ isSupported(): boolean { return true; }
19
+ getName(): string { return 'CPU'; }
20
+ dispose(): void { /* cleanup */ }
21
+ }
22
+
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Backend registry
3
+ */
4
+
5
+ export { WebGLBackend } from './webgl';
6
+ export { WebGPUBackend } from './webgpu';
7
+ export { WasmBackend } from './wasm';
8
+ export { CPUBackend } from './cpu';
9
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * WASM backend
3
+ */
4
+
5
+ export interface BackendOptions {
6
+ device?: string;
7
+ precision?: 'float32' | 'float16';
8
+ }
9
+
10
+ export class WasmBackend {
11
+ private options: BackendOptions;
12
+
13
+ constructor(options: BackendOptions = {}) {
14
+ this.options = options;
15
+ }
16
+
17
+ async initialize(): Promise<void> { /* Wasm init */ }
18
+ isSupported(): boolean { return true; }
19
+ getName(): string { return 'Wasm'; }
20
+ dispose(): void { /* cleanup */ }
21
+ }
22
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * WebGL backend
3
+ */
4
+
5
+ export interface BackendOptions {
6
+ device?: string;
7
+ precision?: 'float32' | 'float16';
8
+ }
9
+
10
+ export class WebGLBackend {
11
+ private options: BackendOptions;
12
+
13
+ constructor(options: BackendOptions = {}) {
14
+ this.options = options;
15
+ }
16
+
17
+ async initialize(): Promise<void> { /* WebGL init */ }
18
+ isSupported(): boolean { return true; }
19
+ getName(): string { return 'WebGL'; }
20
+ dispose(): void { /* cleanup */ }
21
+ }
22
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * WebGPU backend
3
+ */
4
+
5
+ export interface BackendOptions {
6
+ device?: string;
7
+ precision?: 'float32' | 'float16';
8
+ }
9
+
10
+ export class WebGPUBackend {
11
+ private options: BackendOptions;
12
+
13
+ constructor(options: BackendOptions = {}) {
14
+ this.options = options;
15
+ }
16
+
17
+ async initialize(): Promise<void> { /* WebGPU init */ }
18
+ isSupported(): boolean { return true; }
19
+ getName(): string { return 'WebGPU'; }
20
+ dispose(): void { /* cleanup */ }
21
+ }
22
+
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * NeuralForge Core SDK
3
+ */
4
+
5
+ export { Tensor } from './tensor';
6
+ export { Model } from './model';
7
+ export { InferenceSession } from './session';
8
+
package/src/model.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Model loading and management
3
+ */
4
+
5
+ import { Tensor } from './tensor';
6
+
7
+ export interface ModelConfig {
8
+ inputShape: number[];
9
+ outputShape: number[];
10
+ weights?: Record<string, Tensor>;
11
+ }
12
+
13
+ export class Model {
14
+ private config: ModelConfig;
15
+ private weights: Map<string, Tensor> = new Map();
16
+
17
+ constructor(config: ModelConfig) {
18
+ this.config = config;
19
+ if (config.weights) {
20
+ Object.entries(config.weights).forEach(([k, v]) => this.weights.set(k, v));
21
+ }
22
+ }
23
+
24
+ predict(input: Tensor): Tensor { return input; }
25
+ getWeight(name: string): Tensor | undefined { return this.weights.get(name); }
26
+ summary(): string { return JSON.stringify(this.config); }
27
+ }
28
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Activation ops
3
+ */
4
+
5
+ export function relu(x: Float32Array): Float32Array { return x.map(v => Math.max(0, v)) as unknown as Float32Array; }
6
+ export function sigmoid(x: Float32Array): Float32Array { return x; }
7
+
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Arithmetic ops
3
+ */
4
+
5
+ export function add(a: Float32Array, b: Float32Array): Float32Array { return a; }
6
+ export function mul(a: Float32Array, b: Float32Array): Float32Array { return a; }
7
+ export function sub(a: Float32Array, b: Float32Array): Float32Array { return a; }
8
+
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Convolution ops
3
+ */
4
+
5
+ export function conv2d(input: Float32Array, kernel: Float32Array, stride: number = 1): Float32Array { return input; }
6
+
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Operations
3
+ */
4
+
5
+ export * from './arithmetic';
6
+ export * from './matrix';
7
+ export * from './activation';
8
+ export * from './conv';
9
+
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Matrix ops
3
+ */
4
+
5
+ export function matmul(a: Float32Array, b: Float32Array, m: number, n: number, k: number): Float32Array { return new Float32Array(m * n); }
6
+
package/src/session.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Inference session
3
+ */
4
+
5
+ import { Model, ModelConfig } from './model';
6
+ import { Tensor } from './tensor';
7
+
8
+ export class InferenceSession {
9
+ private model: Model;
10
+ private initialized = false;
11
+
12
+ constructor(config: ModelConfig) {
13
+ this.model = new Model(config);
14
+ }
15
+
16
+ async initialize(): Promise<void> { this.initialized = true; }
17
+ run(inputs: Record<string, Tensor>): Record<string, Tensor> {
18
+ if (!this.initialized) throw new Error('Session not initialized');
19
+ return { output: this.model.predict(Object.values(inputs)[0]) };
20
+ }
21
+ dispose(): void { this.initialized = false; }
22
+ }
23
+
package/src/tensor.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Tensor implementation
3
+ */
4
+
5
+ export type DType = 'float32' | 'float16' | 'int32';
6
+
7
+ export class Tensor {
8
+ readonly data: Float32Array;
9
+ readonly shape: number[];
10
+ readonly dtype: DType;
11
+
12
+ constructor(data: Float32Array | number[], shape?: number[], dtype: DType = 'float32') {
13
+ this.data = data instanceof Float32Array ? data : new Float32Array(data);
14
+ this.shape = shape || [this.data.length];
15
+ this.dtype = dtype;
16
+ }
17
+
18
+ get size(): number { return this.data.length; }
19
+ reshape(newShape: number[]): Tensor { return new Tensor(this.data, newShape, this.dtype); }
20
+ slice(start: number, end: number): Tensor { return new Tensor(this.data.slice(start, end)); }
21
+ clone(): Tensor { return new Tensor(new Float32Array(this.data), [...this.shape], this.dtype); }
22
+ }
23
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Data type utils
3
+ */
4
+
5
+ export type DType = 'float32' | 'float16' | 'int32' | 'int8';
6
+ export function inferDtype(data: ArrayBufferView): DType { return 'float32'; }
7
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Utilities
3
+ */
4
+
5
+ export { inferDtype } from './dtype';
6
+ export { validateShape } from './shape';
7
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shape validation
3
+ */
4
+
5
+ export function validateShape(shape: number[]): boolean { return shape.every(d => d > 0); }
6
+ export function computeStrides(shape: number[]): number[] { return shape; }
7
+
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { Model } from '../src';
3
+
4
+ describe('Model', () => {
5
+ it('should be defined', () => {
6
+ expect(Model).toBeDefined();
7
+ });
8
+
9
+ it('should initialize correctly', () => {
10
+ const instance = new Model();
11
+ expect(instance).toBeInstanceOf(Model);
12
+ });
13
+ });
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { add } from '../src';
3
+
4
+ describe('add', () => {
5
+ it('should be defined', () => {
6
+ expect(add).toBeDefined();
7
+ });
8
+
9
+ it('should initialize correctly', () => {
10
+ const instance = new add();
11
+ expect(instance).toBeInstanceOf(add);
12
+ });
13
+ });
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { Tensor } from '../src';
3
+
4
+ describe('Tensor', () => {
5
+ it('should be defined', () => {
6
+ expect(Tensor).toBeDefined();
7
+ });
8
+
9
+ it('should initialize correctly', () => {
10
+ const instance = new Tensor();
11
+ expect(instance).toBeInstanceOf(Tensor);
12
+ });
13
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ }
7
+ }