diff --git a/package-lock.json b/package-lock.json index dc2b6ab..0b01796 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,26 +9,26 @@ "version": "0.3.0", "license": "GPL-3.0-or-later", "devDependencies": { - "@types/node": "^22.1.0", - "prettier": "^3.3.3", - "prettier-plugin-organize-imports": "^4.0.0", - "typescript": "^5.5.4" + "@types/node": "^22.10.1", + "prettier": "^3.4.2", + "prettier-plugin-organize-imports": "^4.1.0", + "typescript": "^5.7.2" } }, "node_modules/@types/node": { - "version": "22.1.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", - "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~6.13.0" + "undici-types": "~6.20.0" } }, "node_modules/prettier": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", - "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "dev": true, "license": "MIT", "bin": { @@ -42,30 +42,26 @@ } }, "node_modules/prettier-plugin-organize-imports": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-4.0.0.tgz", - "integrity": "sha512-vnKSdgv9aOlqKeEFGhf9SCBsTyzDSyScy1k7E0R1Uo4L0cTcOV7c1XQaT7jfXIOc/p08WLBfN2QUQA9zDSZMxA==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-4.1.0.tgz", + "integrity": "sha512-5aWRdCgv645xaa58X8lOxzZoiHAldAPChljr/MT0crXVOWTZ+Svl4hIWlz+niYSlO6ikE5UXkN1JrRvIP2ut0A==", "dev": true, "license": "MIT", "peerDependencies": { - "@vue/language-plugin-pug": "^2.0.24", "prettier": ">=2.0", "typescript": ">=2.9", - "vue-tsc": "^2.0.24" + "vue-tsc": "^2.1.0" }, "peerDependenciesMeta": { - "@vue/language-plugin-pug": { - "optional": true - }, "vue-tsc": { "optional": true } } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, "license": "Apache-2.0", "bin": { @@ -77,9 +73,9 @@ } }, "node_modules/undici-types": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", - "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", "dev": true, "license": "MIT" } diff --git a/package.json b/package.json index d3c7a06..3b7b821 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,10 @@ "format": "prettier src --write" }, "devDependencies": { - "@types/node": "^22.1.0", - "prettier": "^3.3.3", - "prettier-plugin-organize-imports": "^4.0.0", - "typescript": "^5.5.4" + "@types/node": "^22.10.1", + "prettier": "^3.4.2", + "prettier-plugin-organize-imports": "^4.1.0", + "typescript": "^5.7.2" }, "license": "GPL-3.0-or-later" } diff --git a/src/mos/model/test/line.test.ts b/src/mos/model/test/line.test.ts index 808c6b5..b5b32d7 100644 --- a/src/mos/model/test/line.test.ts +++ b/src/mos/model/test/line.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { line } from "../line.js" +import { line } from "../line.ts" test("mos -- line", () => { assert.deepEqual(line(1)([2, 3]), 5) diff --git a/src/mos/tensor/operator.ts b/src/mos/tensor/operator.ts index 9c9d665..25adb12 100644 --- a/src/mos/tensor/operator.ts +++ b/src/mos/tensor/operator.ts @@ -1,4 +1,4 @@ -import { assertTensor1, isScalar, isTensor1, type Tensor } from "./tensor.js" +import { assertTensor1, isScalar, isTensor1, type Tensor } from "./tensor.ts" export function sum1(t: Tensor): number { assertTensor1(t) diff --git a/src/mos/tensor/test/operator.test.ts b/src/mos/tensor/test/operator.test.ts index 7ca9654..5fabf04 100644 --- a/src/mos/tensor/test/operator.test.ts +++ b/src/mos/tensor/test/operator.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import test from "node:test" -import { sum, sum1 } from "../operator.js" +import { sum, sum1 } from "../operator.ts" test("mos -- sum1", () => { assert.equal(sum1([1, 2, 3, 4, 5, 6]), 21) diff --git a/src/mos/tensor/test/tensor.test.ts b/src/mos/tensor/test/tensor.test.ts index db7c499..ceac501 100644 --- a/src/mos/tensor/test/tensor.test.ts +++ b/src/mos/tensor/test/tensor.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import test from "node:test" -import { rank, shape } from "../tensor.js" +import { rank, shape } from "../tensor.ts" test("mos -- shape", () => { assert.deepEqual(shape(1), []) diff --git a/src/system-a/block/Block.ts b/src/system-a/block/Block.ts index 7b15d56..a16a12b 100644 --- a/src/system-a/block/Block.ts +++ b/src/system-a/block/Block.ts @@ -1,4 +1,4 @@ -import type { Shape, Tensor } from "../tensor/index.js" +import type { Shape, Tensor } from "../tensor/index.ts" export type BlockFn = (t: Tensor) => (...ps: Array) => Tensor diff --git a/src/system-a/block/blockStack.ts b/src/system-a/block/blockStack.ts index ebe82e2..7cd937e 100644 --- a/src/system-a/block/blockStack.ts +++ b/src/system-a/block/blockStack.ts @@ -1,6 +1,6 @@ -import { arrayAppend } from "../../utils/arrayAppend.js" -import { Block, type BlockFn } from "./Block.js" -import { emptyBlock } from "./emptyBlock.js" +import { arrayAppend } from "../../utils/arrayAppend.ts" +import { Block, type BlockFn } from "./Block.ts" +import { emptyBlock } from "./emptyBlock.ts" // NOTE Be careful about the order of applications, // `f` first, then `g`. diff --git a/src/system-a/block/emptyBlock.ts b/src/system-a/block/emptyBlock.ts index cb2ffa0..566a4af 100644 --- a/src/system-a/block/emptyBlock.ts +++ b/src/system-a/block/emptyBlock.ts @@ -1,4 +1,4 @@ -import { Block } from "./Block.js" +import { Block } from "./Block.ts" export const emptyBlock = Block( (t) => diff --git a/src/system-a/block/index.ts b/src/system-a/block/index.ts index 7bc5023..6767c98 100644 --- a/src/system-a/block/index.ts +++ b/src/system-a/block/index.ts @@ -1,3 +1,3 @@ -export * from "./Block.js" -export * from "./blockStack.js" -export * from "./emptyBlock.js" +export * from "./Block.ts" +export * from "./blockStack.ts" +export * from "./emptyBlock.ts" diff --git a/src/system-a/gradient-descent/Representation.ts b/src/system-a/gradient-descent/Representation.ts index 55b9fb8..4cb5cc2 100644 --- a/src/system-a/gradient-descent/Representation.ts +++ b/src/system-a/gradient-descent/Representation.ts @@ -1,4 +1,4 @@ -import type { Tensor } from "../tensor/index.js" +import type { Tensor } from "../tensor/index.ts" export interface Representation { inflate: (p: Tensor) => R diff --git a/src/system-a/gradient-descent/gradientDescent.ts b/src/system-a/gradient-descent/gradientDescent.ts index f93e94b..2ac8f6f 100644 --- a/src/system-a/gradient-descent/gradientDescent.ts +++ b/src/system-a/gradient-descent/gradientDescent.ts @@ -1,7 +1,7 @@ -import { zip } from "../../utils/zip.js" -import { gradient } from "../gradient/index.js" -import { assertTensorArray, type Tensor } from "../tensor/index.js" -import type { Representation } from "./Representation.js" +import { zip } from "../../utils/zip.ts" +import { gradient } from "../gradient/index.ts" +import { assertTensorArray, type Tensor } from "../tensor/index.ts" +import type { Representation } from "./Representation.ts" export type GradientDescentFn = ( objective: (...ps: Array) => Tensor, diff --git a/src/system-a/gradient-descent/gradientDescentAdam.ts b/src/system-a/gradient-descent/gradientDescentAdam.ts index 0997d31..9f5bb4e 100644 --- a/src/system-a/gradient-descent/gradientDescentAdam.ts +++ b/src/system-a/gradient-descent/gradientDescentAdam.ts @@ -1,8 +1,8 @@ -import { tensorZeros, type Tensor } from "../tensor/index.js" -import { add, div, mul, square, squareRoot, sub } from "../toys/index.js" -import type { Representation } from "./Representation.js" -import { gradientDescent } from "./gradientDescent.js" -import { smooth } from "./smooth.js" +import { tensorZeros, type Tensor } from "../tensor/index.ts" +import { add, div, mul, square, squareRoot, sub } from "../toys/index.ts" +import type { Representation } from "./Representation.ts" +import { gradientDescent } from "./gradientDescent.ts" +import { smooth } from "./smooth.ts" const stabilizer = 1e-8 diff --git a/src/system-a/gradient-descent/gradientDescentLonely.ts b/src/system-a/gradient-descent/gradientDescentLonely.ts index c24f8a8..acbe055 100644 --- a/src/system-a/gradient-descent/gradientDescentLonely.ts +++ b/src/system-a/gradient-descent/gradientDescentLonely.ts @@ -1,7 +1,7 @@ -import type { Tensor } from "../tensor/index.js" -import { mul, sub } from "../toys/index.js" -import type { Representation } from "./Representation.js" -import { gradientDescent } from "./gradientDescent.js" +import type { Tensor } from "../tensor/index.ts" +import { mul, sub } from "../toys/index.ts" +import type { Representation } from "./Representation.ts" +import { gradientDescent } from "./gradientDescent.ts" export function lonelyRepresentation(options: { learningRate: number diff --git a/src/system-a/gradient-descent/gradientDescentNaked.ts b/src/system-a/gradient-descent/gradientDescentNaked.ts index 4cf218d..1f5588c 100644 --- a/src/system-a/gradient-descent/gradientDescentNaked.ts +++ b/src/system-a/gradient-descent/gradientDescentNaked.ts @@ -1,7 +1,7 @@ -import type { Tensor } from "../tensor/index.js" -import { mul, sub } from "../toys/index.js" -import type { Representation } from "./Representation.js" -import { gradientDescent } from "./gradientDescent.js" +import type { Tensor } from "../tensor/index.ts" +import { mul, sub } from "../toys/index.ts" +import type { Representation } from "./Representation.ts" +import { gradientDescent } from "./gradientDescent.ts" export function nakedRepresentation(options: { learningRate: number diff --git a/src/system-a/gradient-descent/gradientDescentRms.ts b/src/system-a/gradient-descent/gradientDescentRms.ts index c36251d..2876bff 100644 --- a/src/system-a/gradient-descent/gradientDescentRms.ts +++ b/src/system-a/gradient-descent/gradientDescentRms.ts @@ -1,8 +1,8 @@ -import { tensorZeros, type Tensor } from "../tensor/index.js" -import { add, div, mul, square, squareRoot, sub } from "../toys/index.js" -import type { Representation } from "./Representation.js" -import { gradientDescent } from "./gradientDescent.js" -import { smooth } from "./smooth.js" +import { tensorZeros, type Tensor } from "../tensor/index.ts" +import { add, div, mul, square, squareRoot, sub } from "../toys/index.ts" +import type { Representation } from "./Representation.ts" +import { gradientDescent } from "./gradientDescent.ts" +import { smooth } from "./smooth.ts" const stabilizer = 1e-8 diff --git a/src/system-a/gradient-descent/gradientDescentVelocity.ts b/src/system-a/gradient-descent/gradientDescentVelocity.ts index 73ef47e..106af66 100644 --- a/src/system-a/gradient-descent/gradientDescentVelocity.ts +++ b/src/system-a/gradient-descent/gradientDescentVelocity.ts @@ -1,7 +1,7 @@ -import { tensorZeros, type Tensor } from "../tensor/index.js" -import { add, mul, sub } from "../toys/index.js" -import type { Representation } from "./Representation.js" -import { gradientDescent } from "./gradientDescent.js" +import { tensorZeros, type Tensor } from "../tensor/index.ts" +import { add, mul, sub } from "../toys/index.ts" +import type { Representation } from "./Representation.ts" +import { gradientDescent } from "./gradientDescent.ts" export function velocityRepresentation(options: { learningRate: number diff --git a/src/system-a/gradient-descent/index.ts b/src/system-a/gradient-descent/index.ts index fae4abd..c6352f3 100644 --- a/src/system-a/gradient-descent/index.ts +++ b/src/system-a/gradient-descent/index.ts @@ -1 +1 @@ -export * from "./gradientDescent.js" +export * from "./gradientDescent.ts" diff --git a/src/system-a/gradient-descent/smooth.ts b/src/system-a/gradient-descent/smooth.ts index 892a5d5..c199988 100644 --- a/src/system-a/gradient-descent/smooth.ts +++ b/src/system-a/gradient-descent/smooth.ts @@ -1,5 +1,5 @@ -import type { Tensor } from "../tensor/index.js" -import { add, mul } from "../toys/index.js" +import type { Tensor } from "../tensor/index.ts" +import { add, mul } from "../toys/index.ts" export function smooth(decayRate: number, average: Tensor, g: Tensor): Tensor { return add(mul(decayRate, average), mul(1 - decayRate, g)) diff --git a/src/system-a/gradient/GradientState.ts b/src/system-a/gradient/GradientState.ts index e14d487..364ac56 100644 --- a/src/system-a/gradient/GradientState.ts +++ b/src/system-a/gradient/GradientState.ts @@ -1,4 +1,4 @@ -import { type Scalar } from "../tensor/index.js" +import { type Scalar } from "../tensor/index.ts" export type GradientState = Map diff --git a/src/system-a/gradient/gradient.test.ts b/src/system-a/gradient/gradient.test.ts index aa53fef..4926b04 100644 --- a/src/system-a/gradient/gradient.test.ts +++ b/src/system-a/gradient/gradient.test.ts @@ -1,7 +1,7 @@ import assert from "node:assert" import { test } from "node:test" -import { add, mul, sum } from "../toys/index.js" -import { gradient } from "./gradient.js" +import { add, mul, sum } from "../toys/index.ts" +import { gradient } from "./gradient.ts" test("gradient -- add", () => { assert.deepStrictEqual(gradient(add, [1, 1]), [1, 1]) diff --git a/src/system-a/gradient/gradient.ts b/src/system-a/gradient/gradient.ts index 56310b8..fdc3d49 100644 --- a/src/system-a/gradient/gradient.ts +++ b/src/system-a/gradient/gradient.ts @@ -4,12 +4,12 @@ import { scalarTruncate, tensorMap, type Tensor, -} from "../tensor/index.js" +} from "../tensor/index.ts" import { emptyGradientState, gradientStateGetWithDefault, type GradientState, -} from "./GradientState.js" +} from "./GradientState.ts" // The effect of `gradient` on a `DifferentiableFn` // is `sum` of all elements of it's result tensor. diff --git a/src/system-a/gradient/index.ts b/src/system-a/gradient/index.ts index 56111e3..cd6273c 100644 --- a/src/system-a/gradient/index.ts +++ b/src/system-a/gradient/index.ts @@ -1,2 +1,2 @@ -export * from "./gradient.js" -export * from "./GradientState.js" +export * from "./gradient.ts" +export * from "./GradientState.ts" diff --git a/src/system-a/loss/index.ts b/src/system-a/loss/index.ts index b269dde..f6fa6d2 100644 --- a/src/system-a/loss/index.ts +++ b/src/system-a/loss/index.ts @@ -1 +1 @@ -export * from "./l2Loss.js" +export * from "./l2Loss.ts" diff --git a/src/system-a/loss/l2Loss.ts b/src/system-a/loss/l2Loss.ts index 24a2449..7f9d3bc 100644 --- a/src/system-a/loss/l2Loss.ts +++ b/src/system-a/loss/l2Loss.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { square, sub, sum } from "../toys/index.js" +import { type Tensor } from "../tensor/index.ts" +import { square, sub, sum } from "../toys/index.ts" export type Target = (xs: Tensor) => (...ps: Array) => Tensor export type Expectant = (xs: Tensor, ys: Tensor) => Objective diff --git a/src/system-a/models/argmax.test.ts b/src/system-a/models/argmax.test.ts index 78d30e7..683a4c2 100644 --- a/src/system-a/models/argmax.test.ts +++ b/src/system-a/models/argmax.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { argmax } from "./argmax.js" +import { argmax } from "./argmax.ts" test("argmax", () => { assert.deepStrictEqual(argmax([1, 2, 3]), 2) diff --git a/src/system-a/models/argmax.ts b/src/system-a/models/argmax.ts index 3e0578c..9c38628 100644 --- a/src/system-a/models/argmax.ts +++ b/src/system-a/models/argmax.ts @@ -1,4 +1,4 @@ -import { scalarReal, type Scalar } from "../tensor/Scalar.js" +import { scalarReal, type Scalar } from "../tensor/Scalar.ts" // NOTE `argmax` is only meaningful for `Tensor1`, // for general nested `Tensor` a list of indexed diff --git a/src/system-a/models/compareClassification.test.ts b/src/system-a/models/compareClassification.test.ts index 12717a2..ead2ddd 100644 --- a/src/system-a/models/compareClassification.test.ts +++ b/src/system-a/models/compareClassification.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { compareClassification } from "./compareClassification.js" +import { compareClassification } from "./compareClassification.ts" test("compareClassification", () => { assert.deepStrictEqual(compareClassification([1, 2, 3], [10, 20, 30]), 1) diff --git a/src/system-a/models/compareClassification.ts b/src/system-a/models/compareClassification.ts index 30a3773..16cf813 100644 --- a/src/system-a/models/compareClassification.ts +++ b/src/system-a/models/compareClassification.ts @@ -1,6 +1,6 @@ -import type { Scalar } from "../tensor/Scalar.js" -import { extend2 } from "../toys/extend.js" -import { argmax } from "./argmax.js" +import type { Scalar } from "../tensor/Scalar.ts" +import { extend2 } from "../toys/extend.ts" +import { argmax } from "./argmax.ts" export type Classification = Array diff --git a/src/system-a/models/iris/irisModel.test.ts b/src/system-a/models/iris/irisModel.test.ts index 3af73b3..88a4d48 100644 --- a/src/system-a/models/iris/irisModel.test.ts +++ b/src/system-a/models/iris/irisModel.test.ts @@ -1,7 +1,7 @@ import { test } from "node:test" -import { modelAccuracy } from "../modelAccuracy.js" -import { irisTestXs, irisTestYs } from "./irisDataset.js" -import { irisModel } from "./irisModel.js" +import { modelAccuracy } from "../modelAccuracy.ts" +import { irisTestXs, irisTestYs } from "./irisDataset.ts" +import { irisModel } from "./irisModel.ts" test("irisModel", () => { // console.log(irisModel(irisTestXs)) diff --git a/src/system-a/models/iris/irisModel.ts b/src/system-a/models/iris/irisModel.ts index 7a18881..106164c 100644 --- a/src/system-a/models/iris/irisModel.ts +++ b/src/system-a/models/iris/irisModel.ts @@ -1,16 +1,16 @@ -import { blockStack } from "../../block/index.js" -import { gradientDescentAdam } from "../../gradient-descent/gradientDescentAdam.js" -import { gradientDescentNaked } from "../../gradient-descent/gradientDescentNaked.js" -import { gradientDescentRms } from "../../gradient-descent/gradientDescentRms.js" -import { l2Loss } from "../../loss/index.js" +import { blockStack } from "../../block/index.ts" +import { gradientDescentAdam } from "../../gradient-descent/gradientDescentAdam.ts" +import { gradientDescentNaked } from "../../gradient-descent/gradientDescentNaked.ts" +import { gradientDescentRms } from "../../gradient-descent/gradientDescentRms.ts" +import { l2Loss } from "../../loss/index.ts" import { denseBlock, denseBlockInitParameters, -} from "../../perceptrons/relu/index.js" -import type { Tensor } from "../../tensor/Tensor.js" -import { samplingObjective } from "../../tensor/samplingObjective.js" -import { model } from "../model.js" -import { irisTrainXs, irisTrainYs } from "./irisDataset.js" +} from "../../perceptrons/relu/index.ts" +import type { Tensor } from "../../tensor/Tensor.ts" +import { samplingObjective } from "../../tensor/samplingObjective.ts" +import { model } from "../model.ts" +import { irisTrainXs, irisTrainYs } from "./irisDataset.ts" // export const irisNetwork = blockStack([ // denseBlock(4, 6), diff --git a/src/system-a/models/model.ts b/src/system-a/models/model.ts index 8992ea5..a876f0b 100644 --- a/src/system-a/models/model.ts +++ b/src/system-a/models/model.ts @@ -1,5 +1,5 @@ -import type { Target } from "../loss/index.js" -import type { Tensor } from "../tensor/Tensor.js" +import type { Target } from "../loss/index.ts" +import type { Tensor } from "../tensor/Tensor.ts" export type Model = (t: Tensor) => Tensor diff --git a/src/system-a/models/modelAccuracy.ts b/src/system-a/models/modelAccuracy.ts index 022a600..46e5d7d 100644 --- a/src/system-a/models/modelAccuracy.ts +++ b/src/system-a/models/modelAccuracy.ts @@ -1,9 +1,9 @@ -import type { Tensor } from "../tensor/Tensor.js" -import { assertTensorArray } from "../tensor/assertions.js" -import { sum } from "../toys/sum.js" -import { div } from "../toys/toys.js" -import { compareClassification } from "./compareClassification.js" -import type { Model } from "./model.js" +import type { Tensor } from "../tensor/Tensor.ts" +import { assertTensorArray } from "../tensor/assertions.ts" +import { sum } from "../toys/sum.ts" +import { div } from "../toys/toys.ts" +import { compareClassification } from "./compareClassification.ts" +import type { Model } from "./model.ts" export function modelAccuracy(model: Model, xs: Tensor, ys: Tensor): Tensor { return accuracy(model(xs), ys) diff --git a/src/system-a/perceptrons/relu/denseBlock.ts b/src/system-a/perceptrons/relu/denseBlock.ts index a610551..1f7a66d 100644 --- a/src/system-a/perceptrons/relu/denseBlock.ts +++ b/src/system-a/perceptrons/relu/denseBlock.ts @@ -1,9 +1,9 @@ -import { Block } from "../../block/index.js" -import type { Tensor } from "../../tensor/Tensor.js" -import { randomTensor } from "../../tensor/randomTensor.js" -import type { Shape } from "../../tensor/shape.js" -import { zeroTensor } from "../../tensor/zeroTensor.js" -import { leakyRelu } from "./leakyRelu.js" +import { Block } from "../../block/index.ts" +import type { Tensor } from "../../tensor/Tensor.ts" +import { randomTensor } from "../../tensor/randomTensor.ts" +import type { Shape } from "../../tensor/shape.ts" +import { zeroTensor } from "../../tensor/zeroTensor.ts" +import { leakyRelu } from "./leakyRelu.ts" export function denseBlock(inputSize: number, layerWidth: number): Block { return Block(leakyRelu, [[layerWidth, inputSize], [layerWidth]]) diff --git a/src/system-a/perceptrons/relu/index.ts b/src/system-a/perceptrons/relu/index.ts index ea15e5d..783cfb5 100644 --- a/src/system-a/perceptrons/relu/index.ts +++ b/src/system-a/perceptrons/relu/index.ts @@ -1,3 +1,3 @@ -export * from "./denseBlock.js" -export * from "./leakyRelu.js" -export * from "./relu.js" +export * from "./denseBlock.ts" +export * from "./leakyRelu.ts" +export * from "./relu.ts" diff --git a/src/system-a/perceptrons/relu/leakyRelu.ts b/src/system-a/perceptrons/relu/leakyRelu.ts index 23b863f..be3dcdf 100644 --- a/src/system-a/perceptrons/relu/leakyRelu.ts +++ b/src/system-a/perceptrons/relu/leakyRelu.ts @@ -1,6 +1,6 @@ -import type { Scalar, Tensor } from "../../tensor/index.js" -import { extend1, lt, mul } from "../../toys/index.js" -import { linear } from "./linear.js" +import type { Scalar, Tensor } from "../../tensor/index.ts" +import { extend1, lt, mul } from "../../toys/index.ts" +import { linear } from "./linear.ts" export function leakyRectifyScalar(s: Scalar): Scalar { return lt(s, 0) ? (mul(-0.01, s) as Scalar) : s diff --git a/src/system-a/perceptrons/relu/linear.test.ts b/src/system-a/perceptrons/relu/linear.test.ts index 62fae23..e163a1b 100644 --- a/src/system-a/perceptrons/relu/linear.test.ts +++ b/src/system-a/perceptrons/relu/linear.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { linear, linearWrong } from "./linear.js" +import { linear, linearWrong } from "./linear.ts" test("linear -- matrixVactorMul is necessary", () => { assert.deepStrictEqual( diff --git a/src/system-a/perceptrons/relu/linear.ts b/src/system-a/perceptrons/relu/linear.ts index 120ad36..852c2c8 100644 --- a/src/system-a/perceptrons/relu/linear.ts +++ b/src/system-a/perceptrons/relu/linear.ts @@ -1,5 +1,5 @@ -import type { Tensor } from "../../tensor/index.js" -import { add, dot, extend2, mul, sum } from "../../toys/index.js" +import type { Tensor } from "../../tensor/index.ts" +import { add, dot, extend2, mul, sum } from "../../toys/index.ts" const mul21 = extend2(mul, 2, 1) diff --git a/src/system-a/perceptrons/relu/multiLayerRelu.ts b/src/system-a/perceptrons/relu/multiLayerRelu.ts index 91beb42..840dc1f 100644 --- a/src/system-a/perceptrons/relu/multiLayerRelu.ts +++ b/src/system-a/perceptrons/relu/multiLayerRelu.ts @@ -1,5 +1,5 @@ -import type { Tensor } from "../../tensor/Tensor.js" -import { relu } from "./relu.js" +import type { Tensor } from "../../tensor/Tensor.ts" +import { relu } from "./relu.ts" type Target = (t: Tensor) => (...ps: Array) => Tensor diff --git a/src/system-a/perceptrons/relu/relu.test.ts b/src/system-a/perceptrons/relu/relu.test.ts index 3151cc3..c9d5bec 100644 --- a/src/system-a/perceptrons/relu/relu.test.ts +++ b/src/system-a/perceptrons/relu/relu.test.ts @@ -1,7 +1,7 @@ import assert from "node:assert" import { test } from "node:test" -import { assertTensorAlmostEqual } from "../../tensor/assertions.js" -import { rectify, relu } from "./relu.js" +import { assertTensorAlmostEqual } from "../../tensor/assertions.ts" +import { rectify, relu } from "./relu.ts" test("rectify", () => { assert.deepStrictEqual( diff --git a/src/system-a/perceptrons/relu/relu.ts b/src/system-a/perceptrons/relu/relu.ts index 57da84b..3bf138f 100644 --- a/src/system-a/perceptrons/relu/relu.ts +++ b/src/system-a/perceptrons/relu/relu.ts @@ -1,6 +1,6 @@ -import type { Scalar, Tensor } from "../../tensor/index.js" -import { extend1, lt } from "../../toys/index.js" -import { linear } from "./linear.js" +import type { Scalar, Tensor } from "../../tensor/index.ts" +import { extend1, lt } from "../../toys/index.ts" +import { linear } from "./linear.ts" export function rectifyScalar(s: Scalar): Scalar { return lt(s, 0) ? 0 : s diff --git a/src/system-a/targets/line.test.ts b/src/system-a/targets/line.test.ts index 48ae395..d06fcfa 100644 --- a/src/system-a/targets/line.test.ts +++ b/src/system-a/targets/line.test.ts @@ -1,13 +1,13 @@ import assert from "assert" import { test } from "node:test" -import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.js" -import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.js" -import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.js" -import type { GradientDescentFn } from "../gradient-descent/index.js" -import { l2Loss } from "../loss/index.js" -import { assertTensorAlmostEqual } from "../tensor/index.js" -import { samplingObjective } from "../tensor/samplingObjective.js" -import { line } from "./line.js" +import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.ts" +import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.ts" +import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.ts" +import type { GradientDescentFn } from "../gradient-descent/index.ts" +import { l2Loss } from "../loss/index.ts" +import { assertTensorAlmostEqual } from "../tensor/index.ts" +import { samplingObjective } from "../tensor/samplingObjective.ts" +import { line } from "./line.ts" test("line", () => { assert.deepStrictEqual(line(1)(2, 3), 5) diff --git a/src/system-a/targets/line.ts b/src/system-a/targets/line.ts index 3c6e97e..8218cfa 100644 --- a/src/system-a/targets/line.ts +++ b/src/system-a/targets/line.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { add, mul } from "../toys/index.js" +import { type Tensor } from "../tensor/index.ts" +import { add, mul } from "../toys/index.ts" export function line(x: Tensor): (...ps: [Tensor, Tensor]) => Tensor { return (ps0, ps1) => add(mul(ps0, x), ps1) diff --git a/src/system-a/targets/plane.test.ts b/src/system-a/targets/plane.test.ts index 34fa6c5..92d9581 100644 --- a/src/system-a/targets/plane.test.ts +++ b/src/system-a/targets/plane.test.ts @@ -1,15 +1,15 @@ import assert from "node:assert" import { test } from "node:test" -import { gradientDescentAdam } from "../gradient-descent/gradientDescentAdam.js" -import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.js" -import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.js" -import { gradientDescentRms } from "../gradient-descent/gradientDescentRms.js" -import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.js" -import type { GradientDescentFn } from "../gradient-descent/index.js" -import { l2Loss } from "../loss/index.js" -import { assertTensorAlmostEqual } from "../tensor/index.js" -import { samplingObjective } from "../tensor/samplingObjective.js" -import { plane } from "./plane.js" +import { gradientDescentAdam } from "../gradient-descent/gradientDescentAdam.ts" +import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.ts" +import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.ts" +import { gradientDescentRms } from "../gradient-descent/gradientDescentRms.ts" +import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.ts" +import type { GradientDescentFn } from "../gradient-descent/index.ts" +import { l2Loss } from "../loss/index.ts" +import { assertTensorAlmostEqual } from "../tensor/index.ts" +import { samplingObjective } from "../tensor/samplingObjective.ts" +import { plane } from "./plane.ts" test("plane", () => { assert.deepStrictEqual(plane([1, 3])([1, 2], 3), 10) diff --git a/src/system-a/targets/plane.ts b/src/system-a/targets/plane.ts index 10d76a7..ec375f0 100644 --- a/src/system-a/targets/plane.ts +++ b/src/system-a/targets/plane.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { add, dot } from "../toys/index.js" +import { type Tensor } from "../tensor/index.ts" +import { add, dot } from "../toys/index.ts" export function plane(t: Tensor): (...ps: [Tensor, Tensor]) => Tensor { return (ps0, ps1) => add(dot(ps0, t), ps1) diff --git a/src/system-a/targets/quad.test.ts b/src/system-a/targets/quad.test.ts index d0845c5..dcc2340 100644 --- a/src/system-a/targets/quad.test.ts +++ b/src/system-a/targets/quad.test.ts @@ -1,13 +1,13 @@ import assert from "node:assert" import { test } from "node:test" -import type { GradientDescentFn } from "../gradient-descent/gradientDescent.js" -import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.js" -import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.js" -import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.js" -import { l2Loss } from "../loss/index.js" -import { assertTensorAlmostEqual } from "../tensor/index.js" -import { samplingObjective } from "../tensor/samplingObjective.js" -import { quad } from "./quad.js" +import type { GradientDescentFn } from "../gradient-descent/gradientDescent.ts" +import { gradientDescentLonely } from "../gradient-descent/gradientDescentLonely.ts" +import { gradientDescentNaked } from "../gradient-descent/gradientDescentNaked.ts" +import { gradientDescentVelocity } from "../gradient-descent/gradientDescentVelocity.ts" +import { l2Loss } from "../loss/index.ts" +import { assertTensorAlmostEqual } from "../tensor/index.ts" +import { samplingObjective } from "../tensor/samplingObjective.ts" +import { quad } from "./quad.ts" test("quad", () => { assert.deepStrictEqual(quad(3)(4.5, 2.1, 7.8), 54.6) diff --git a/src/system-a/targets/quad.ts b/src/system-a/targets/quad.ts index 88d0a7b..ead78bb 100644 --- a/src/system-a/targets/quad.ts +++ b/src/system-a/targets/quad.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { add, mul, square } from "../toys/index.js" +import { type Tensor } from "../tensor/index.ts" +import { add, mul, square } from "../toys/index.ts" export function quad(x: Tensor): (...ps: [Tensor, Tensor, Tensor]) => Tensor { return (ps0, ps1, ps2) => add(mul(ps0, square(x)), add(mul(ps1, x), ps2)) diff --git a/src/system-a/tensor/Link.ts b/src/system-a/tensor/Link.ts index 7648190..f5366f9 100644 --- a/src/system-a/tensor/Link.ts +++ b/src/system-a/tensor/Link.ts @@ -2,8 +2,8 @@ import { gradientStateGetWithDefault, gradientStateSet, type GradientState, -} from "../gradient/index.js" -import { type Scalar } from "./Scalar.js" +} from "../gradient/index.ts" +import { type Scalar } from "./Scalar.ts" export type Link = ( y: Scalar, diff --git a/src/system-a/tensor/Scalar.ts b/src/system-a/tensor/Scalar.ts index 0a8902f..f918de1 100644 --- a/src/system-a/tensor/Scalar.ts +++ b/src/system-a/tensor/Scalar.ts @@ -1,4 +1,4 @@ -import { endOfChain, type Link } from "./Link.js" +import { endOfChain, type Link } from "./Link.ts" export type Dual = { "@type": "Dual"; real: number; link: Link } diff --git a/src/system-a/tensor/Tensor.ts b/src/system-a/tensor/Tensor.ts index 4aef6e2..acf6d81 100644 --- a/src/system-a/tensor/Tensor.ts +++ b/src/system-a/tensor/Tensor.ts @@ -1,4 +1,4 @@ -import { isScalar, type Scalar } from "./Scalar.js" +import { isScalar, type Scalar } from "./Scalar.ts" export type Tensor = Scalar | Array diff --git a/src/system-a/tensor/assertions.ts b/src/system-a/tensor/assertions.ts index d3861af..65be6d6 100644 --- a/src/system-a/tensor/assertions.ts +++ b/src/system-a/tensor/assertions.ts @@ -1,6 +1,6 @@ -import { isScalar, type Scalar } from "./Scalar.js" -import { isTensor, type Tensor } from "./Tensor.js" -import { tensorAlmostEqual } from "./tensorAlmostEqual.js" +import { isScalar, type Scalar } from "./Scalar.ts" +import { isTensor, type Tensor } from "./Tensor.ts" +import { tensorAlmostEqual } from "./tensorAlmostEqual.ts" export function assertScalar(t: any): asserts t is Scalar { if (!isScalar(t)) { diff --git a/src/system-a/tensor/index.ts b/src/system-a/tensor/index.ts index 7077179..b60557b 100644 --- a/src/system-a/tensor/index.ts +++ b/src/system-a/tensor/index.ts @@ -1,13 +1,13 @@ -export * from "./assertions.js" -export * from "./Link.js" -export * from "./randomTensor.js" -export * from "./rank.js" -export * from "./Scalar.js" -export * from "./shape.js" -export * from "./Tensor.js" -export * from "./tensorAlmostEqual.js" -export * from "./tensorEvery.js" -export * from "./tensorMap.js" -export * from "./tensorReal.js" -export * from "./tensorZeros.js" -export * from "./zeroTensor.js" +export * from "./assertions.ts" +export * from "./Link.ts" +export * from "./randomTensor.ts" +export * from "./rank.ts" +export * from "./Scalar.ts" +export * from "./shape.ts" +export * from "./Tensor.ts" +export * from "./tensorAlmostEqual.ts" +export * from "./tensorEvery.ts" +export * from "./tensorMap.ts" +export * from "./tensorReal.ts" +export * from "./tensorZeros.ts" +export * from "./zeroTensor.ts" diff --git a/src/system-a/tensor/randomTensor.ts b/src/system-a/tensor/randomTensor.ts index 56584a0..1c8ad96 100644 --- a/src/system-a/tensor/randomTensor.ts +++ b/src/system-a/tensor/randomTensor.ts @@ -1,7 +1,7 @@ -import { randomGaussian } from "../../utils/randomGaussian.js" -import { repeatApply } from "../../utils/repeatApply.js" -import type { Tensor } from "./Tensor.js" -import type { Shape } from "./shape.js" +import { randomGaussian } from "../../utils/randomGaussian.ts" +import { repeatApply } from "../../utils/repeatApply.ts" +import type { Tensor } from "./Tensor.ts" +import type { Shape } from "./shape.ts" export function randomTensor( mean: number, diff --git a/src/system-a/tensor/rank.ts b/src/system-a/tensor/rank.ts index ee5b923..e7ce017 100644 --- a/src/system-a/tensor/rank.ts +++ b/src/system-a/tensor/rank.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "./Tensor.js" -import { shape } from "./shape.js" +import { type Tensor } from "./Tensor.ts" +import { shape } from "./shape.ts" export function rank(t: Tensor): number { return shape(t).length diff --git a/src/system-a/tensor/samplingObjective.ts b/src/system-a/tensor/samplingObjective.ts index 77d7f23..5677bbc 100644 --- a/src/system-a/tensor/samplingObjective.ts +++ b/src/system-a/tensor/samplingObjective.ts @@ -1,7 +1,7 @@ -import { refs } from "../../utils/refs.js" -import { samples } from "../../utils/samples.js" -import type { Expectant, Objective } from "../loss/index.js" -import { type Tensor } from "../tensor/index.js" +import { refs } from "../../utils/refs.ts" +import { samples } from "../../utils/samples.ts" +import type { Expectant, Objective } from "../loss/index.ts" +import { type Tensor } from "../tensor/index.ts" export function samplingObjective( expectant: Expectant, diff --git a/src/system-a/tensor/shape.test.ts b/src/system-a/tensor/shape.test.ts index eb830c9..c61e85a 100644 --- a/src/system-a/tensor/shape.test.ts +++ b/src/system-a/tensor/shape.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { shape } from "./shape.js" +import { shape } from "./shape.ts" test("shape", () => { assert.deepStrictEqual(shape(1), []) diff --git a/src/system-a/tensor/shape.ts b/src/system-a/tensor/shape.ts index 3641876..cba339a 100644 --- a/src/system-a/tensor/shape.ts +++ b/src/system-a/tensor/shape.ts @@ -1,8 +1,8 @@ -import { arrayEqual } from "../../utils/arrayEqual.js" -import { assertArrayTheSame } from "../../utils/assertArrayTheSame.js" -import { isScalar } from "./Scalar.js" -import { type Tensor } from "./Tensor.js" -import { assertTensorArray } from "./assertions.js" +import { arrayEqual } from "../../utils/arrayEqual.ts" +import { assertArrayTheSame } from "../../utils/assertArrayTheSame.ts" +import { isScalar } from "./Scalar.ts" +import { type Tensor } from "./Tensor.ts" +import { assertTensorArray } from "./assertions.ts" export type Shape = Array diff --git a/src/system-a/tensor/tensorAlmostEqual.ts b/src/system-a/tensor/tensorAlmostEqual.ts index e6f054f..01fb51e 100644 --- a/src/system-a/tensor/tensorAlmostEqual.ts +++ b/src/system-a/tensor/tensorAlmostEqual.ts @@ -1,7 +1,7 @@ -import { sub } from "../toys/index.js" -import { scalarReal } from "./Scalar.js" -import { type Tensor } from "./Tensor.js" -import { tensorEvery } from "./tensorEvery.js" +import { sub } from "../toys/index.ts" +import { scalarReal } from "./Scalar.ts" +import { type Tensor } from "./Tensor.ts" +import { tensorEvery } from "./tensorEvery.ts" export function tensorAlmostEqual( x: Tensor, diff --git a/src/system-a/tensor/tensorEvery.ts b/src/system-a/tensor/tensorEvery.ts index cec33da..bbc55fd 100644 --- a/src/system-a/tensor/tensorEvery.ts +++ b/src/system-a/tensor/tensorEvery.ts @@ -1,5 +1,5 @@ -import { isScalar, type Scalar } from "./Scalar.js" -import { type Tensor } from "./Tensor.js" +import { isScalar, type Scalar } from "./Scalar.ts" +import { type Tensor } from "./Tensor.ts" export function tensorEvery( tensor: Tensor, diff --git a/src/system-a/tensor/tensorMap.ts b/src/system-a/tensor/tensorMap.ts index 3825aa9..facb0e1 100644 --- a/src/system-a/tensor/tensorMap.ts +++ b/src/system-a/tensor/tensorMap.ts @@ -1,5 +1,5 @@ -import { isScalar, type Scalar } from "./Scalar.js" -import { type Tensor } from "./Tensor.js" +import { isScalar, type Scalar } from "./Scalar.ts" +import { type Tensor } from "./Tensor.ts" export function tensorMap(tensor: Tensor, fn: (x: Scalar) => Scalar): Tensor { if (isScalar(tensor)) { diff --git a/src/system-a/tensor/tensorReal.ts b/src/system-a/tensor/tensorReal.ts index 0221177..4b06e98 100644 --- a/src/system-a/tensor/tensorReal.ts +++ b/src/system-a/tensor/tensorReal.ts @@ -1,6 +1,6 @@ -import { scalarReal } from "./Scalar.js" -import { type Tensor } from "./Tensor.js" -import { tensorMap } from "./tensorMap.js" +import { scalarReal } from "./Scalar.ts" +import { type Tensor } from "./Tensor.ts" +import { tensorMap } from "./tensorMap.ts" export function tensorReal(tensor: Tensor): Tensor { return tensorMap(tensor, scalarReal) diff --git a/src/system-a/tensor/tensorZeros.test.ts b/src/system-a/tensor/tensorZeros.test.ts index f745a7a..84f4913 100644 --- a/src/system-a/tensor/tensorZeros.test.ts +++ b/src/system-a/tensor/tensorZeros.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { tensorZeros } from "./tensorZeros.js" +import { tensorZeros } from "./tensorZeros.ts" test("tensorZeros", () => { assert.deepStrictEqual( diff --git a/src/system-a/tensor/tensorZeros.ts b/src/system-a/tensor/tensorZeros.ts index e5b865b..e415881 100644 --- a/src/system-a/tensor/tensorZeros.ts +++ b/src/system-a/tensor/tensorZeros.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "./Tensor.js" -import { tensorMap } from "./tensorMap.js" +import { type Tensor } from "./Tensor.ts" +import { tensorMap } from "./tensorMap.ts" export function tensorZeros(tensor: Tensor): Tensor { return tensorMap(tensor, (_) => 0) diff --git a/src/system-a/tensor/zeroTensor.test.ts b/src/system-a/tensor/zeroTensor.test.ts index c2e0749..c8f98ab 100644 --- a/src/system-a/tensor/zeroTensor.test.ts +++ b/src/system-a/tensor/zeroTensor.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { zeroTensor } from "./zeroTensor.js" +import { zeroTensor } from "./zeroTensor.ts" test("zeroTensor", () => { assert.deepStrictEqual(zeroTensor([2, 3]), [ diff --git a/src/system-a/tensor/zeroTensor.ts b/src/system-a/tensor/zeroTensor.ts index 0cb6c43..5ef7e17 100644 --- a/src/system-a/tensor/zeroTensor.ts +++ b/src/system-a/tensor/zeroTensor.ts @@ -1,6 +1,6 @@ -import { repeatApply } from "../../utils/repeatApply.js" -import type { Tensor } from "./Tensor.js" -import type { Shape } from "./shape.js" +import { repeatApply } from "../../utils/repeatApply.ts" +import type { Tensor } from "./Tensor.ts" +import type { Shape } from "./shape.ts" export function zeroTensor(shape: Shape): Tensor { if (shape.length === 0) return 0 diff --git a/src/system-a/toys/comparator.ts b/src/system-a/toys/comparator.ts index b0375e2..6d25778 100644 --- a/src/system-a/toys/comparator.ts +++ b/src/system-a/toys/comparator.ts @@ -1,4 +1,4 @@ -import { scalarReal, type Scalar } from "../tensor/index.js" +import { scalarReal, type Scalar } from "../tensor/index.ts" export function comparator( p: (x: number, y: number) => boolean, diff --git a/src/system-a/toys/dot.test.ts b/src/system-a/toys/dot.test.ts index ca0a1f1..54d4946 100644 --- a/src/system-a/toys/dot.test.ts +++ b/src/system-a/toys/dot.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { dot } from "./dot.js" +import { dot } from "./dot.ts" test("dot", () => { assert.deepStrictEqual(dot([1, 2, 3], [1, 2, 3]), 14) diff --git a/src/system-a/toys/dot.ts b/src/system-a/toys/dot.ts index 60ffd75..039196e 100644 --- a/src/system-a/toys/dot.ts +++ b/src/system-a/toys/dot.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { mul, sum } from "./index.js" +import { type Tensor } from "../tensor/index.ts" +import { mul, sum } from "./index.ts" export function dot(w: Tensor, x: Tensor): Tensor { return sum(mul(w, x)) diff --git a/src/system-a/toys/extend.test.ts b/src/system-a/toys/extend.test.ts index 8f9992d..7d151ec 100644 --- a/src/system-a/toys/extend.test.ts +++ b/src/system-a/toys/extend.test.ts @@ -1,8 +1,8 @@ import assert from "node:assert" import { test } from "node:test" -import { shape } from "../tensor/index.js" -import { extend2 } from "./extend.js" -import { mul } from "./toys.js" +import { shape } from "../tensor/index.ts" +import { extend2 } from "./extend.ts" +import { mul } from "./toys.ts" test("extend2 -- mul 0 0", () => { assert.deepStrictEqual( diff --git a/src/system-a/toys/extend.ts b/src/system-a/toys/extend.ts index ef0e26c..c68a324 100644 --- a/src/system-a/toys/extend.ts +++ b/src/system-a/toys/extend.ts @@ -1,5 +1,5 @@ -import { zip } from "../../utils/zip.js" -import { assertTensorArray, rank, type Tensor } from "../tensor/index.js" +import { zip } from "../../utils/zip.ts" +import { assertTensorArray, rank, type Tensor } from "../tensor/index.ts" export function extend1( fn: (x: A) => B, diff --git a/src/system-a/toys/flatten.test.ts b/src/system-a/toys/flatten.test.ts index 1982e17..3c92a21 100644 --- a/src/system-a/toys/flatten.test.ts +++ b/src/system-a/toys/flatten.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { flatten } from "./flatten.js" +import { flatten } from "./flatten.ts" test("flatten", () => { assert.deepStrictEqual( diff --git a/src/system-a/toys/flatten.ts b/src/system-a/toys/flatten.ts index 537e1f6..22e4b98 100644 --- a/src/system-a/toys/flatten.ts +++ b/src/system-a/toys/flatten.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "../tensor/index.js" -import { extend1 } from "./extend.js" +import { type Tensor } from "../tensor/index.ts" +import { extend1 } from "./extend.ts" export function flatten2(t: Array>): Array { return t.flatMap((x) => x) diff --git a/src/system-a/toys/index.ts b/src/system-a/toys/index.ts index 6775355..aa40022 100644 --- a/src/system-a/toys/index.ts +++ b/src/system-a/toys/index.ts @@ -1,4 +1,4 @@ -export * from "./dot.js" -export * from "./extend.js" -export * from "./sum.js" -export * from "./toys.js" +export * from "./dot.ts" +export * from "./extend.ts" +export * from "./sum.ts" +export * from "./toys.ts" diff --git a/src/system-a/toys/mul.test.ts b/src/system-a/toys/mul.test.ts index 1a3c171..19e70bf 100644 --- a/src/system-a/toys/mul.test.ts +++ b/src/system-a/toys/mul.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { mul } from "./index.js" +import { mul } from "./index.ts" // NOTE Related issues about `ext2`: // https://github.com/themetaschemer/malt/issues/56 diff --git a/src/system-a/toys/primitive.ts b/src/system-a/toys/primitive.ts index 67e4f45..73f1622 100644 --- a/src/system-a/toys/primitive.ts +++ b/src/system-a/toys/primitive.ts @@ -4,7 +4,7 @@ import { scalarLink, scalarReal, type Scalar, -} from "../tensor/index.js" +} from "../tensor/index.ts" export function primitive1( realFn: (ra: number) => number, diff --git a/src/system-a/toys/sum.test.ts b/src/system-a/toys/sum.test.ts index 102739a..7b51abf 100644 --- a/src/system-a/toys/sum.test.ts +++ b/src/system-a/toys/sum.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { sum } from "./sum.js" +import { sum } from "./sum.ts" test("sum", () => { assert.deepStrictEqual(sum([1, 2, 3]), 6) diff --git a/src/system-a/toys/sum.ts b/src/system-a/toys/sum.ts index 759d1da..5bd6195 100644 --- a/src/system-a/toys/sum.ts +++ b/src/system-a/toys/sum.ts @@ -1,6 +1,6 @@ -import type { Scalar } from "../tensor/index.js" -import { extend1 } from "./extend.js" -import { addScalar } from "./index.js" +import type { Scalar } from "../tensor/index.ts" +import { extend1 } from "./extend.ts" +import { addScalar } from "./index.ts" export function sum1(xs: Array): Scalar { return xs.reduce((x, result) => addScalar(x, result), 0) diff --git a/src/system-a/toys/toys-by-hand.ts b/src/system-a/toys/toys-by-hand.ts index 1a1ff39..fdf10fa 100644 --- a/src/system-a/toys/toys-by-hand.ts +++ b/src/system-a/toys/toys-by-hand.ts @@ -1,4 +1,4 @@ -import { Dual, scalarLink, scalarReal, type Scalar } from "../tensor/index.js" +import { Dual, scalarLink, scalarReal, type Scalar } from "../tensor/index.ts" function addScalar(da: Scalar, db: Scalar): Scalar { return Dual(scalarReal(da) + scalarReal(db), (_d, z, state) => { diff --git a/src/system-a/toys/toys.ts b/src/system-a/toys/toys.ts index ba5799b..c0d00e6 100644 --- a/src/system-a/toys/toys.ts +++ b/src/system-a/toys/toys.ts @@ -1,6 +1,6 @@ -import { comparator } from "./comparator.js" -import { extend1, extend2 } from "./extend.js" -import { primitive1, primitive2 } from "./primitive.js" +import { comparator } from "./comparator.ts" +import { extend1, extend2 } from "./extend.ts" +import { primitive1, primitive2 } from "./primitive.ts" export const expScalar = primitive1(Math.exp, (ra, z) => Math.exp(ra) * z) diff --git a/src/the-book/appendix-a.test.ts b/src/the-book/appendix-a.test.ts index 9fbdee8..b029fa0 100644 --- a/src/the-book/appendix-a.test.ts +++ b/src/the-book/appendix-a.test.ts @@ -8,7 +8,7 @@ import { mulScalar, scalarTruncate, tensorMap, -} from "./appendix-a.js" +} from "./appendix-a.ts" test("appendix-a -- tensorMap", () => { assert.deepStrictEqual( diff --git a/src/the-book/chapter-1.test.ts b/src/the-book/chapter-1.test.ts index f58125a..1faed8c 100644 --- a/src/the-book/chapter-1.test.ts +++ b/src/the-book/chapter-1.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { line } from "./chapter-1.js" +import { line } from "./chapter-1.ts" test("chapter-1 -- line", () => { assert.deepStrictEqual(line(1)([2, 3]), 5) diff --git a/src/the-book/chapter-2.test.ts b/src/the-book/chapter-2.test.ts index 3620913..834c84c 100644 --- a/src/the-book/chapter-2.test.ts +++ b/src/the-book/chapter-2.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { shape } from "./chapter-2.js" +import { shape } from "./chapter-2.ts" test("chapter-2 -- shape", () => { assert.deepStrictEqual(shape(1), []) diff --git a/src/the-book/chapter-3.test.ts b/src/the-book/chapter-3.test.ts index 51f96f1..a7d5824 100644 --- a/src/the-book/chapter-3.test.ts +++ b/src/the-book/chapter-3.test.ts @@ -1,7 +1,7 @@ import assert from "node:assert" import { test } from "node:test" -import { l2Loss } from "./chapter-3.js" -import { line } from "./interlude-i.js" +import { l2Loss } from "./chapter-3.ts" +import { line } from "./interlude-i.ts" test("chapter-3 -- l2Loss", () => { const lineXs = [2, 1, 4, 3] diff --git a/src/the-book/chapter-3.ts b/src/the-book/chapter-3.ts index 96114ee..b8a3ad0 100644 --- a/src/the-book/chapter-3.ts +++ b/src/the-book/chapter-3.ts @@ -1,5 +1,5 @@ -import { type Tensor } from "./chapter-2.js" -import { square, sub, sum } from "./interlude-i.js" +import { type Tensor } from "./chapter-2.ts" +import { square, sub, sum } from "./interlude-i.ts" export function l2Loss( target: (xs: Tensor) => (ps: Parameters) => Tensor, diff --git a/src/the-book/interlude-i.test.ts b/src/the-book/interlude-i.test.ts index c478a4d..753d847 100644 --- a/src/the-book/interlude-i.test.ts +++ b/src/the-book/interlude-i.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { add, line, mul, square, squareRoot, sub, sum } from "./interlude-i.js" +import { add, line, mul, square, squareRoot, sub, sum } from "./interlude-i.ts" test("interlude-i -- add", () => { assert.deepStrictEqual(add(1, 1), 2) diff --git a/src/the-book/interlude-i.ts b/src/the-book/interlude-i.ts index eab712b..e6bfbb2 100644 --- a/src/the-book/interlude-i.ts +++ b/src/the-book/interlude-i.ts @@ -1,11 +1,11 @@ -import { zip } from "../utils/zip.js" +import { zip } from "../utils/zip.ts" import { assertNotScalar, assertTensor1, isScalar, rank, type Tensor, -} from "./chapter-2.js" +} from "./chapter-2.ts" export function extend2( fn: (x: number, y: number) => number, diff --git a/src/utils/arrayAppend.test.ts b/src/utils/arrayAppend.test.ts index 35c1745..1f6795f 100644 --- a/src/utils/arrayAppend.test.ts +++ b/src/utils/arrayAppend.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { arrayAppend } from "./arrayAppend.js" +import { arrayAppend } from "./arrayAppend.ts" test("arrayAppend", () => { assert.deepStrictEqual(arrayAppend([10], [3]), [10, 3]) diff --git a/src/utils/refs.test.ts b/src/utils/refs.test.ts index 30167d3..eb935b0 100644 --- a/src/utils/refs.test.ts +++ b/src/utils/refs.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { refs } from "./refs.js" +import { refs } from "./refs.ts" test("refs", () => { assert.deepStrictEqual(refs([0, 1, 2, 3, 4, 5], [1, 3, 5]), [1, 3, 5]) diff --git a/src/utils/samples.test.ts b/src/utils/samples.test.ts index 685e0a7..1c29251 100644 --- a/src/utils/samples.test.ts +++ b/src/utils/samples.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert" import { test } from "node:test" -import { samples } from "./samples.js" +import { samples } from "./samples.ts" test("samples", () => { assert.deepStrictEqual(samples(10, 3).length, 3) diff --git a/src/utils/samples.ts b/src/utils/samples.ts index d062c40..3613695 100644 --- a/src/utils/samples.ts +++ b/src/utils/samples.ts @@ -1,4 +1,4 @@ -import { randomNat } from "./randomNat.js" +import { randomNat } from "./randomNat.ts" export function samples(n: number, s: number): Array { const results: Array = [] diff --git a/tsconfig.json b/tsconfig.json index 4b7619c..80308fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "target": "es6", "strict": true, "verbatimModuleSyntax": true, + "rewriteRelativeImportExtensions": true, "declaration": true, "sourceMap": true, "declarationMap": true,