@isidorus/cpu 0.0.0-alpha.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/README.md +47 -0
- package/binding.gyp +103 -0
- package/dist/ts/_native.d.ts +13 -0
- package/dist/ts/_native.d.ts.map +1 -0
- package/dist/ts/_native.js +22 -0
- package/dist/ts/_native.js.map +1 -0
- package/dist/ts/graph.d.ts +91 -0
- package/dist/ts/graph.d.ts.map +1 -0
- package/dist/ts/graph.js +95 -0
- package/dist/ts/graph.js.map +1 -0
- package/dist/ts/index.d.ts +47 -0
- package/dist/ts/index.d.ts.map +1 -0
- package/dist/ts/index.js +58 -0
- package/dist/ts/index.js.map +1 -0
- package/dist/ts/inference-pool.d.ts +84 -0
- package/dist/ts/inference-pool.d.ts.map +1 -0
- package/dist/ts/inference-pool.js +625 -0
- package/dist/ts/inference-pool.js.map +1 -0
- package/dist/ts/inference_pool.d.ts +99 -0
- package/dist/ts/inference_pool.d.ts.map +1 -0
- package/dist/ts/inference_pool.js +370 -0
- package/dist/ts/inference_pool.js.map +1 -0
- package/dist/ts/install-libtensorflow.d.ts +34 -0
- package/dist/ts/install-libtensorflow.d.ts.map +1 -0
- package/dist/ts/install-libtensorflow.js +254 -0
- package/dist/ts/install-libtensorflow.js.map +1 -0
- package/dist/ts/ops/array_ops.d.ts +29 -0
- package/dist/ts/ops/array_ops.d.ts.map +1 -0
- package/dist/ts/ops/array_ops.js +54 -0
- package/dist/ts/ops/array_ops.js.map +1 -0
- package/dist/ts/ops/index.d.ts +5 -0
- package/dist/ts/ops/index.d.ts.map +1 -0
- package/dist/ts/ops/index.js +5 -0
- package/dist/ts/ops/index.js.map +1 -0
- package/dist/ts/ops/math_ops.d.ts +96 -0
- package/dist/ts/ops/math_ops.d.ts.map +1 -0
- package/dist/ts/ops/math_ops.js +277 -0
- package/dist/ts/ops/math_ops.js.map +1 -0
- package/dist/ts/ops/nn_ops.d.ts +130 -0
- package/dist/ts/ops/nn_ops.d.ts.map +1 -0
- package/dist/ts/ops/nn_ops.js +340 -0
- package/dist/ts/ops/nn_ops.js.map +1 -0
- package/dist/ts/ops/variable_ops.d.ts +128 -0
- package/dist/ts/ops/variable_ops.d.ts.map +1 -0
- package/dist/ts/ops/variable_ops.js +267 -0
- package/dist/ts/ops/variable_ops.js.map +1 -0
- package/dist/ts/session.d.ts +83 -0
- package/dist/ts/session.d.ts.map +1 -0
- package/dist/ts/session.js +81 -0
- package/dist/ts/session.js.map +1 -0
- package/package.json +63 -0
- package/scripts/install.js +100 -0
- package/scripts/test-install.js +82 -0
- package/scripts/test.js +45 -0
- package/src/native/addon.cc +12 -0
- package/src/native/graph.cc +442 -0
- package/src/native/graph.h +52 -0
- package/src/native/platform_tf.h +8 -0
- package/src/native/session.cc +716 -0
- package/src/native/session.h +92 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* install-libtensorflow.ts
|
|
3
|
+
*
|
|
4
|
+
* Alpha-phase libtensorflow resolver.
|
|
5
|
+
*
|
|
6
|
+
* Resolution order:
|
|
7
|
+
* 1. LIBTENSORFLOW_PATH env var
|
|
8
|
+
* 2. Hardcoded platform default paths
|
|
9
|
+
* 3. Interactive prompt — install automatically or print instructions
|
|
10
|
+
*
|
|
11
|
+
* Called once at package load time (from index.ts) before the native
|
|
12
|
+
* addon is required. If resolution fails the process exits with a
|
|
13
|
+
* clear diagnostic rather than a cryptic "cannot find module" error.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "fs";
|
|
16
|
+
import { createWriteStream, mkdirSync } from "fs";
|
|
17
|
+
import { join } from "path";
|
|
18
|
+
import { platform, arch } from "os";
|
|
19
|
+
import { get } from "https";
|
|
20
|
+
import { exec } from "child_process";
|
|
21
|
+
import { promisify } from "util";
|
|
22
|
+
import * as readline from "readline";
|
|
23
|
+
const execAsync = promisify(exec);
|
|
24
|
+
// ─── TF version to download if the user accepts auto-install ────────────────
|
|
25
|
+
const TF_VERSION = "2.18.1";
|
|
26
|
+
const TF_BASE = `https://storage.googleapis.com/tensorflow/versions/${TF_VERSION}`;
|
|
27
|
+
function getPlatformConfig() {
|
|
28
|
+
const os = platform();
|
|
29
|
+
const cpu = arch();
|
|
30
|
+
if (os === "win32") {
|
|
31
|
+
return {
|
|
32
|
+
libFile: "tensorflow.dll",
|
|
33
|
+
defaultPaths: [
|
|
34
|
+
"C:\\libtensorflow\\lib",
|
|
35
|
+
"C:\\Program Files\\libtensorflow\\lib",
|
|
36
|
+
],
|
|
37
|
+
downloadUrl: `${TF_BASE}/libtensorflow-cpu-windows-x86_64.zip`,
|
|
38
|
+
installDir: "C:\\libtensorflow",
|
|
39
|
+
extractCmd: (archive, dest) => `powershell -Command "Expand-Archive -Path '${archive}' -DestinationPath '${dest}' -Force"`,
|
|
40
|
+
envInstructions: [
|
|
41
|
+
` Set-Item -Path Env:LIBTENSORFLOW_PATH -Value 'C:\\libtensorflow'`,
|
|
42
|
+
` [Environment]::SetEnvironmentVariable('LIBTENSORFLOW_PATH', 'C:\\libtensorflow', 'User')`,
|
|
43
|
+
` # Also add C:\\libtensorflow\\lib to PATH so tensorflow.dll is found at runtime`,
|
|
44
|
+
].join("\n"),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (os === "darwin") {
|
|
48
|
+
const isArm = cpu === "arm64";
|
|
49
|
+
const archStr = isArm ? "arm64" : "x86_64";
|
|
50
|
+
return {
|
|
51
|
+
libFile: "libtensorflow.dylib",
|
|
52
|
+
defaultPaths: [
|
|
53
|
+
"/usr/local/lib",
|
|
54
|
+
"/opt/homebrew/lib", // Homebrew ARM
|
|
55
|
+
"/usr/local/opt/libtensorflow/lib",
|
|
56
|
+
],
|
|
57
|
+
downloadUrl: `${TF_BASE}/libtensorflow-cpu-darwin-${archStr}.tar.gz`,
|
|
58
|
+
installDir: "/usr/local",
|
|
59
|
+
extractCmd: (archive, dest) => `sudo tar -C '${dest}' -xzf '${archive}'`,
|
|
60
|
+
envInstructions: ` export LIBTENSORFLOW_PATH=/usr/local`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Linux (default)
|
|
64
|
+
return {
|
|
65
|
+
libFile: "libtensorflow.so",
|
|
66
|
+
defaultPaths: [
|
|
67
|
+
"/usr/local/lib",
|
|
68
|
+
"/usr/lib",
|
|
69
|
+
"/usr/lib/x86_64-linux-gnu",
|
|
70
|
+
"/usr/lib/aarch64-linux-gnu",
|
|
71
|
+
],
|
|
72
|
+
downloadUrl: `${TF_BASE}/libtensorflow-cpu-linux-x86_64.tar.gz`,
|
|
73
|
+
installDir: "/usr/local",
|
|
74
|
+
extractCmd: (archive, dest) => `sudo tar -C '${dest}' -xzf '${archive}' && sudo ldconfig`,
|
|
75
|
+
envInstructions: ` export LIBTENSORFLOW_PATH=/usr/local`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// ─── Detection ──────────────────────────────────────────────────────────────
|
|
79
|
+
/**
|
|
80
|
+
* Check if libtensorflow is present at the given directory.
|
|
81
|
+
* Looks for the platform library file in <dir>/lib and <dir>.
|
|
82
|
+
*/
|
|
83
|
+
function checkDir(dir, libFile) {
|
|
84
|
+
for (const candidate of [join(dir, "lib", libFile), join(dir, libFile)]) {
|
|
85
|
+
if (existsSync(candidate))
|
|
86
|
+
return candidate;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the libtensorflow path.
|
|
92
|
+
* Returns { tfPath, source } where source explains how it was found.
|
|
93
|
+
* Returns null if not found.
|
|
94
|
+
*/
|
|
95
|
+
export function resolveTfPath() {
|
|
96
|
+
const config = getPlatformConfig();
|
|
97
|
+
// 1. Environment variable.
|
|
98
|
+
const envPath = process.env["LIBTENSORFLOW_PATH"];
|
|
99
|
+
if (envPath) {
|
|
100
|
+
const found = checkDir(envPath, config.libFile);
|
|
101
|
+
if (found)
|
|
102
|
+
return { tfPath: envPath, source: "LIBTENSORFLOW_PATH env var" };
|
|
103
|
+
// Env var set but library not there — warn but don't fall through silently.
|
|
104
|
+
process.stderr.write(`[isidorus] LIBTENSORFLOW_PATH is set to '${envPath}' but ` +
|
|
105
|
+
`${config.libFile} was not found there.\n`);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
// 2. Hardcoded default paths.
|
|
109
|
+
for (const dir of config.defaultPaths) {
|
|
110
|
+
const found = checkDir(dir, config.libFile);
|
|
111
|
+
if (found) {
|
|
112
|
+
process.stderr.write(`[isidorus] Found ${config.libFile} at ${dir} ` +
|
|
113
|
+
`(set LIBTENSORFLOW_PATH=${dir} to silence this message)\n`);
|
|
114
|
+
return { tfPath: dir, source: `default path ${dir}` };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
// ─── Download helper ─────────────────────────────────────────────────────────
|
|
120
|
+
async function downloadFile(url, dest) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
const file = createWriteStream(dest);
|
|
123
|
+
const request = get(url, response => {
|
|
124
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
125
|
+
// Follow redirect.
|
|
126
|
+
downloadFile(response.headers.location, dest)
|
|
127
|
+
.then(resolve).catch(reject);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (response.statusCode !== 200) {
|
|
131
|
+
reject(new Error(`HTTP ${response.statusCode} from ${url}`));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const total = parseInt(response.headers["content-length"] ?? "0", 10);
|
|
135
|
+
let downloaded = 0;
|
|
136
|
+
let lastPct = -1;
|
|
137
|
+
response.on("data", (chunk) => {
|
|
138
|
+
downloaded += chunk.length;
|
|
139
|
+
if (total > 0) {
|
|
140
|
+
const pct = Math.floor((downloaded / total) * 100);
|
|
141
|
+
if (pct !== lastPct && pct % 10 === 0) {
|
|
142
|
+
process.stdout.write(`\r downloading... ${pct}%`);
|
|
143
|
+
lastPct = pct;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
response.pipe(file);
|
|
148
|
+
file.on("finish", () => { process.stdout.write("\n"); file.close(); resolve(); });
|
|
149
|
+
});
|
|
150
|
+
request.on("error", reject);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// ─── Prompt ──────────────────────────────────────────────────────────────────
|
|
154
|
+
async function prompt(question) {
|
|
155
|
+
const rl = readline.createInterface({
|
|
156
|
+
input: process.stdin,
|
|
157
|
+
output: process.stdout,
|
|
158
|
+
});
|
|
159
|
+
return new Promise(resolve => {
|
|
160
|
+
rl.question(question, answer => { rl.close(); resolve(answer.trim()); });
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// ─── Auto-install ─────────────────────────────────────────────────────────────
|
|
164
|
+
async function autoInstall(config) {
|
|
165
|
+
const tmpDir = process.env["TEMP"] ?? process.env["TMPDIR"] ?? "/tmp";
|
|
166
|
+
const archiveExt = config.downloadUrl.endsWith(".zip") ? ".zip" : ".tar.gz";
|
|
167
|
+
const archivePath = join(tmpDir, `libtensorflow${archiveExt}`);
|
|
168
|
+
console.log(`\n Downloading libtensorflow ${TF_VERSION}...`);
|
|
169
|
+
console.log(` URL: ${config.downloadUrl}`);
|
|
170
|
+
console.log(` Destination: ${config.installDir}\n`);
|
|
171
|
+
try {
|
|
172
|
+
await downloadFile(config.downloadUrl, archivePath);
|
|
173
|
+
console.log(` Extracting to ${config.installDir}...`);
|
|
174
|
+
mkdirSync(config.installDir, { recursive: true });
|
|
175
|
+
const cmd = config.extractCmd(archivePath, config.installDir);
|
|
176
|
+
await execAsync(cmd);
|
|
177
|
+
console.log(` Done.\n`);
|
|
178
|
+
return config.installDir;
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
console.error(` Auto-install failed: ${err.message}`);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// ─── Main entry ──────────────────────────────────────────────────────────────
|
|
186
|
+
/**
|
|
187
|
+
* Ensure libtensorflow is available. Called once at package load time.
|
|
188
|
+
*
|
|
189
|
+
* If the library is found, returns the resolved path and sets
|
|
190
|
+
* LIBTENSORFLOW_PATH in the environment so the native addon can find it.
|
|
191
|
+
*
|
|
192
|
+
* If not found, prompts the user to install automatically or prints
|
|
193
|
+
* manual installation instructions, then exits.
|
|
194
|
+
*/
|
|
195
|
+
export async function ensureTf() {
|
|
196
|
+
const config = getPlatformConfig();
|
|
197
|
+
// Fast path — already resolved.
|
|
198
|
+
const resolved = resolveTfPath();
|
|
199
|
+
if (resolved) {
|
|
200
|
+
process.env["LIBTENSORFLOW_PATH"] = resolved.tfPath;
|
|
201
|
+
return resolved.tfPath;
|
|
202
|
+
}
|
|
203
|
+
// Not found — prompt.
|
|
204
|
+
console.error(`
|
|
205
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
206
|
+
│ libtensorflow not found │
|
|
207
|
+
│ │
|
|
208
|
+
│ @isidorus/cpu requires the TensorFlow C library (${TF_VERSION}). │
|
|
209
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
210
|
+
`);
|
|
211
|
+
const isInteractive = process.stdin.isTTY;
|
|
212
|
+
if (isInteractive) {
|
|
213
|
+
const answer = await prompt(" Install libtensorflow automatically? [Y/n] ");
|
|
214
|
+
const accepted = answer === "" || answer.toLowerCase() === "y";
|
|
215
|
+
if (accepted) {
|
|
216
|
+
const installPath = await autoInstall(config);
|
|
217
|
+
if (installPath) {
|
|
218
|
+
const found = checkDir(installPath, config.libFile);
|
|
219
|
+
if (found) {
|
|
220
|
+
process.env["LIBTENSORFLOW_PATH"] = installPath;
|
|
221
|
+
console.log(` libtensorflow installed at ${installPath}.\n` +
|
|
222
|
+
` To skip this step in future, set:\n` +
|
|
223
|
+
` LIBTENSORFLOW_PATH=${installPath}\n`);
|
|
224
|
+
return installPath;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Auto-install failed — fall through to manual instructions.
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Non-interactive or user declined — print manual instructions.
|
|
231
|
+
const os = platform();
|
|
232
|
+
console.error(` Manual installation:\n`);
|
|
233
|
+
if (os === "win32") {
|
|
234
|
+
console.error(` 1. Download:\n` +
|
|
235
|
+
` ${config.downloadUrl}\n\n` +
|
|
236
|
+
` 2. Extract to C:\\libtensorflow\n\n` +
|
|
237
|
+
` 3. Add to PATH (PowerShell):\n` +
|
|
238
|
+
`${config.envInstructions}\n\n` +
|
|
239
|
+
` 4. Add C:\\libtensorflow\\lib to your PATH so tensorflow.dll\n` +
|
|
240
|
+
` is found at runtime.\n`);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
console.error(` 1. Run:\n` +
|
|
244
|
+
` wget ${config.downloadUrl}\n` +
|
|
245
|
+
` sudo tar -C /usr/local -xzf $(basename ${config.downloadUrl})\n` +
|
|
246
|
+
(os === "linux" ? ` sudo ldconfig\n` : ``) +
|
|
247
|
+
`\n` +
|
|
248
|
+
` 2. Or set LIBTENSORFLOW_PATH to your install directory:\n` +
|
|
249
|
+
`${config.envInstructions}\n`);
|
|
250
|
+
}
|
|
251
|
+
console.error(` Then re-run your application.\n`);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=install-libtensorflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-libtensorflow.js","sourceRoot":"","sources":["../../src/ts/install-libtensorflow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAO,IAAI,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAa,MAAM,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAc,OAAO,CAAC;AACpC,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C;oBAChD,OAAO,CAAC,GAAG,CACT,gCAAgC,WAAW,KAAK;wBAChD,uCAAuC;wBACvC,0BAA0B,WAAW,IAAI,CAC1C,CAAC;oBACF,OAAO,WAAW,CAAC;gBACrB,CAAC;YACH,CAAC;YACD,6DAA6D;QAC/D,CAAC;IACH,CAAC;IAED,gEAAgE;IAChE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAE1C,IAAI,EAAE,KAAK,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,KAAK,CACX,kBAAkB;YAClB,QAAQ,MAAM,CAAC,WAAW,MAAM;YAChC,uCAAuC;YACvC,kCAAkC;YAClC,GAAG,MAAM,CAAC,eAAe,MAAM;YAC/B,kEAAkE;YAClE,6BAA6B,CAC9B,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CACX,aAAa;YACb,aAAa,MAAM,CAAC,WAAW,IAAI;YACnC,+CAA+C,MAAM,CAAC,WAAW,KAAK;YACtE,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,IAAI;YACJ,6DAA6D;YAC7D,GAAG,MAAM,CAAC,eAAe,IAAI,CAC9B,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,CACX,mCAAmC,CACpC,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Tensor, Shape } from "@isidorus/core";
|
|
2
|
+
import { DType } from "@isidorus/core";
|
|
3
|
+
import type { Graph } from "../graph.js";
|
|
4
|
+
/**
|
|
5
|
+
* placeholder — feed input into the graph at session run time.
|
|
6
|
+
* Shape may contain null for dynamic (unknown-at-build-time) dimensions.
|
|
7
|
+
*/
|
|
8
|
+
export declare function placeholder(g: Graph, name: string, shape: Shape, dtype?: DType): Tensor;
|
|
9
|
+
/**
|
|
10
|
+
* constant — embed a fixed value as a Const op in the graph.
|
|
11
|
+
* `data` should be a Buffer containing the raw little-endian bytes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function constant(g: Graph, data: Buffer, shape: number[], dtype: DType, name?: string): Tensor;
|
|
14
|
+
/** Convenience: scalar float32 constant. */
|
|
15
|
+
export declare function scalar(g: Graph, value: number, name?: string): Tensor;
|
|
16
|
+
/**
|
|
17
|
+
* reshape — reshape a tensor to a new shape.
|
|
18
|
+
* `newShape` must be a 1-D int32 constant already in the graph,
|
|
19
|
+
* or use reshapeTo() for the convenience form.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reshape(g: Graph, x: Tensor, shape: Tensor, name?: string): Tensor;
|
|
22
|
+
/**
|
|
23
|
+
* reshapeTo — convenience wrapper that creates the shape constant inline.
|
|
24
|
+
* @param newShape Array of dimension sizes (-1 = infer)
|
|
25
|
+
*/
|
|
26
|
+
export declare function reshapeTo(g: Graph, x: Tensor, newShape: number[], name?: string): Tensor;
|
|
27
|
+
/** identity — pass-through (useful for naming intermediate tensors). */
|
|
28
|
+
export declare function identity(g: Graph, x: Tensor, name?: string): Tensor;
|
|
29
|
+
//# sourceMappingURL=array_ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_ops.d.ts","sourceRoot":"","sources":["../../../src/ts/ops/array_ops.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAa,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,KAAK,EACR,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,EACZ,KAAK,GAAE,KAAqB,GAC3B,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,KAAK,EACR,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EAAE,EACf,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAWR;AAED,4CAA4C;AAC5C,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAKR;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAGnE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DType, shapeToTF } from "@isidorus/core";
|
|
2
|
+
/**
|
|
3
|
+
* placeholder — feed input into the graph at session run time.
|
|
4
|
+
* Shape may contain null for dynamic (unknown-at-build-time) dimensions.
|
|
5
|
+
*/
|
|
6
|
+
export function placeholder(g, name, shape, dtype = DType.FLOAT32) {
|
|
7
|
+
const [t] = g.addOp("Placeholder", [], {
|
|
8
|
+
dtype: { kind: "type", value: dtype },
|
|
9
|
+
shape: { kind: "shape", value: shapeToTF(shape) },
|
|
10
|
+
}, name);
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* constant — embed a fixed value as a Const op in the graph.
|
|
15
|
+
* `data` should be a Buffer containing the raw little-endian bytes.
|
|
16
|
+
*/
|
|
17
|
+
export function constant(g, data, shape, dtype, name) {
|
|
18
|
+
const [t] = g.addOp("Const", [], {
|
|
19
|
+
dtype: { kind: "type", value: dtype },
|
|
20
|
+
value: { kind: "tensor", value: { dtype, shape, data } },
|
|
21
|
+
}, name);
|
|
22
|
+
return t;
|
|
23
|
+
}
|
|
24
|
+
/** Convenience: scalar float32 constant. */
|
|
25
|
+
export function scalar(g, value, name) {
|
|
26
|
+
const buf = Buffer.allocUnsafe(4);
|
|
27
|
+
buf.writeFloatLE(value, 0);
|
|
28
|
+
return constant(g, buf, [], DType.FLOAT32, name);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* reshape — reshape a tensor to a new shape.
|
|
32
|
+
* `newShape` must be a 1-D int32 constant already in the graph,
|
|
33
|
+
* or use reshapeTo() for the convenience form.
|
|
34
|
+
*/
|
|
35
|
+
export function reshape(g, x, shape, name) {
|
|
36
|
+
const [t] = g.addOp("Reshape", [x, shape], {}, name);
|
|
37
|
+
return t;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* reshapeTo — convenience wrapper that creates the shape constant inline.
|
|
41
|
+
* @param newShape Array of dimension sizes (-1 = infer)
|
|
42
|
+
*/
|
|
43
|
+
export function reshapeTo(g, x, newShape, name) {
|
|
44
|
+
const shapeBuf = Buffer.allocUnsafe(newShape.length * 4);
|
|
45
|
+
newShape.forEach((d, i) => shapeBuf.writeInt32LE(d, i * 4));
|
|
46
|
+
const shapeConst = constant(g, shapeBuf, [newShape.length], DType.INT32);
|
|
47
|
+
return reshape(g, x, shapeConst, name);
|
|
48
|
+
}
|
|
49
|
+
/** identity — pass-through (useful for naming intermediate tensors). */
|
|
50
|
+
export function identity(g, x, name) {
|
|
51
|
+
const [t] = g.addOp("Identity", [x], {}, name);
|
|
52
|
+
return t;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=array_ops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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Ac,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ts/ops/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Tensor } from "@isidorus/core";
|
|
2
|
+
import { DType } from "@isidorus/core";
|
|
3
|
+
import type { Graph } from "../graph.js";
|
|
4
|
+
/**
|
|
5
|
+
* matmul — matrix multiplication.
|
|
6
|
+
* Supports optional transpose of either operand.
|
|
7
|
+
*/
|
|
8
|
+
export declare function matmul(g: Graph, a: Tensor, b: Tensor, options?: {
|
|
9
|
+
transposeA?: boolean;
|
|
10
|
+
transposeB?: boolean;
|
|
11
|
+
}, name?: string): Tensor;
|
|
12
|
+
/**
|
|
13
|
+
* batchMatmul — batched matrix multiplication (BatchMatMulV2).
|
|
14
|
+
* Inputs must have rank >= 2. Leading dims are treated as batch dims.
|
|
15
|
+
*/
|
|
16
|
+
export declare function batchMatmul(g: Graph, a: Tensor, b: Tensor, options?: {
|
|
17
|
+
adjX?: boolean;
|
|
18
|
+
adjY?: boolean;
|
|
19
|
+
}, name?: string): Tensor;
|
|
20
|
+
/** Element-wise addition. Supports broadcasting. */
|
|
21
|
+
export declare function add(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
22
|
+
/** Element-wise subtraction. Supports broadcasting. */
|
|
23
|
+
export declare function sub(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
24
|
+
/** Element-wise multiplication. Supports broadcasting. */
|
|
25
|
+
export declare function mul(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
26
|
+
/** Element-wise (real) division. Supports broadcasting. */
|
|
27
|
+
export declare function div(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
28
|
+
/**
|
|
29
|
+
* biasAdd — adds a 1-D bias tensor to a value tensor.
|
|
30
|
+
* The bias is added to the last dimension of value.
|
|
31
|
+
* Equivalent to add() but semantically clearer for neural network layers.
|
|
32
|
+
*/
|
|
33
|
+
export declare function biasAdd(g: Graph, value: Tensor, bias: Tensor, name?: string): Tensor;
|
|
34
|
+
/** Element-wise maximum. Supports broadcasting. */
|
|
35
|
+
export declare function maximum(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
36
|
+
/** Element-wise minimum. Supports broadcasting. */
|
|
37
|
+
export declare function minimum(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
38
|
+
/** Element-wise x^y. Supports broadcasting. */
|
|
39
|
+
export declare function pow(g: Graph, base: Tensor, exp: Tensor, name?: string): Tensor;
|
|
40
|
+
/** Element-wise negation. */
|
|
41
|
+
export declare function neg(g: Graph, x: Tensor, name?: string): Tensor;
|
|
42
|
+
/** Element-wise absolute value. */
|
|
43
|
+
export declare function abs(g: Graph, x: Tensor, name?: string): Tensor;
|
|
44
|
+
/** Element-wise e^x. */
|
|
45
|
+
export declare function exp(g: Graph, x: Tensor, name?: string): Tensor;
|
|
46
|
+
/** Element-wise natural log. */
|
|
47
|
+
export declare function log(g: Graph, x: Tensor, name?: string): Tensor;
|
|
48
|
+
/** Element-wise square root. */
|
|
49
|
+
export declare function sqrt(g: Graph, x: Tensor, name?: string): Tensor;
|
|
50
|
+
/** Element-wise square. */
|
|
51
|
+
export declare function square(g: Graph, x: Tensor, name?: string): Tensor;
|
|
52
|
+
/** Element-wise reciprocal (1/x). */
|
|
53
|
+
export declare function reciprocal(g: Graph, x: Tensor, name?: string): Tensor;
|
|
54
|
+
/** Element-wise floor. */
|
|
55
|
+
export declare function floor(g: Graph, x: Tensor, name?: string): Tensor;
|
|
56
|
+
/** Element-wise ceiling. */
|
|
57
|
+
export declare function ceil(g: Graph, x: Tensor, name?: string): Tensor;
|
|
58
|
+
/** Element-wise round (ties to even). */
|
|
59
|
+
export declare function round(g: Graph, x: Tensor, name?: string): Tensor;
|
|
60
|
+
/** Element-wise sign (-1, 0, or 1). */
|
|
61
|
+
export declare function sign(g: Graph, x: Tensor, name?: string): Tensor;
|
|
62
|
+
/** Cast tensor to a different dtype. */
|
|
63
|
+
export declare function cast(g: Graph, x: Tensor, dtype: DType, name?: string): Tensor;
|
|
64
|
+
/** Sum over the given axes. keepDims preserves reduced dimensions as size 1. */
|
|
65
|
+
export declare function sum(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
66
|
+
/** Mean over the given axes. */
|
|
67
|
+
export declare function mean(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
68
|
+
/** Max over the given axes. */
|
|
69
|
+
export declare function reduceMax(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
70
|
+
/** Min over the given axes. */
|
|
71
|
+
export declare function reduceMin(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
72
|
+
/** Product over the given axes. */
|
|
73
|
+
export declare function prod(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
74
|
+
/** Variance over the given axes (naive: E[x^2] - E[x]^2). */
|
|
75
|
+
export declare function variance(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
76
|
+
/** Standard deviation over the given axes. */
|
|
77
|
+
export declare function std(g: Graph, x: Tensor, axes: number[], keepDims?: boolean, name?: string): Tensor;
|
|
78
|
+
/** Element-wise a == b → bool tensor. */
|
|
79
|
+
export declare function equal(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
80
|
+
/** Element-wise a != b → bool tensor. */
|
|
81
|
+
export declare function notEqual(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
82
|
+
/** Element-wise a > b → bool tensor. */
|
|
83
|
+
export declare function greater(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
84
|
+
/** Element-wise a >= b → bool tensor. */
|
|
85
|
+
export declare function greaterEqual(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
86
|
+
/** Element-wise a < b → bool tensor. */
|
|
87
|
+
export declare function less(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
88
|
+
/** Element-wise a <= b → bool tensor. */
|
|
89
|
+
export declare function lessEqual(g: Graph, a: Tensor, b: Tensor, name?: string): Tensor;
|
|
90
|
+
/** Clip values to [minVal, maxVal]. */
|
|
91
|
+
export declare function clipByValue(g: Graph, x: Tensor, minVal: number, maxVal: number, name?: string): Tensor;
|
|
92
|
+
/** Index of the maximum value along an axis. */
|
|
93
|
+
export declare function argMax(g: Graph, x: Tensor, axis: number, name?: string): Tensor;
|
|
94
|
+
/** Index of the minimum value along an axis. */
|
|
95
|
+
export declare function argMin(g: Graph, x: Tensor, axis: number, name?: string): Tensor;
|
|
96
|
+
//# sourceMappingURL=math_ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math_ops.d.ts","sourceRoot":"","sources":["../../../src/ts/ops/math_ops.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAezC;;;GAGG;AACH,wBAAgB,MAAM,CACpB,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,EAC5D,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,KAAK,EACR,CA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