Skip to content

Commit

Permalink
"rewriteRelativeImportExtensions": true,
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Dec 4, 2024
1 parent 927a342 commit 28cd74e
Show file tree
Hide file tree
Showing 91 changed files with 253 additions and 256 deletions.
46 changes: 21 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion src/mos/model/test/line.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/mos/tensor/operator.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/mos/tensor/test/operator.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/mos/tensor/test/tensor.test.ts
Original file line number Diff line number Diff line change
@@ -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), [])
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/block/Block.ts
Original file line number Diff line number Diff line change
@@ -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>) => Tensor

Expand Down
6 changes: 3 additions & 3 deletions src/system-a/block/blockStack.ts
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/block/emptyBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Block } from "./Block.js"
import { Block } from "./Block.ts"

export const emptyBlock = Block(
(t) =>
Expand Down
6 changes: 3 additions & 3 deletions src/system-a/block/index.ts
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion src/system-a/gradient-descent/Representation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tensor } from "../tensor/index.js"
import type { Tensor } from "../tensor/index.ts"

export interface Representation<R> {
inflate: (p: Tensor) => R
Expand Down
8 changes: 4 additions & 4 deletions src/system-a/gradient-descent/gradientDescent.ts
Original file line number Diff line number Diff line change
@@ -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>) => Tensor,
Expand Down
10 changes: 5 additions & 5 deletions src/system-a/gradient-descent/gradientDescentAdam.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/system-a/gradient-descent/gradientDescentLonely.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/system-a/gradient-descent/gradientDescentNaked.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/system-a/gradient-descent/gradientDescentRms.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/system-a/gradient-descent/gradientDescentVelocity.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/gradient-descent/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./gradientDescent.js"
export * from "./gradientDescent.ts"
4 changes: 2 additions & 2 deletions src/system-a/gradient-descent/smooth.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/gradient/GradientState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Scalar } from "../tensor/index.js"
import { type Scalar } from "../tensor/index.ts"

export type GradientState = Map<Scalar, number>

Expand Down
4 changes: 2 additions & 2 deletions src/system-a/gradient/gradient.test.ts
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
4 changes: 2 additions & 2 deletions src/system-a/gradient/gradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/system-a/gradient/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./gradient.js"
export * from "./GradientState.js"
export * from "./gradient.ts"
export * from "./GradientState.ts"
2 changes: 1 addition & 1 deletion src/system-a/loss/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./l2Loss.js"
export * from "./l2Loss.ts"
4 changes: 2 additions & 2 deletions src/system-a/loss/l2Loss.ts
Original file line number Diff line number Diff line change
@@ -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>) => Tensor
export type Expectant = (xs: Tensor, ys: Tensor) => Objective
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/models/argmax.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/models/argmax.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/system-a/models/compareClassification.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/system-a/models/compareClassification.ts
Original file line number Diff line number Diff line change
@@ -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<Scalar>

Expand Down
6 changes: 3 additions & 3 deletions src/system-a/models/iris/irisModel.test.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
20 changes: 10 additions & 10 deletions src/system-a/models/iris/irisModel.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/system-a/models/model.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/system-a/models/modelAccuracy.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading

0 comments on commit 28cd74e

Please sign in to comment.