File tree 5 files changed +35
-34
lines changed
5 files changed +35
-34
lines changed Original file line number Diff line number Diff line change 1
1
# system-a
2
2
3
- [ system-a] ` tensor/ ` -- extract ` assert `
4
-
5
3
[ system-a] ` tensor/ ` -- ` tensorZeros ` -- zeros of the same shape
6
4
[ system-a] ` velocityRepresentation ` -- takes ` options: { velocityAccumulationFactor } `
7
5
[ system-a] ` gradientDescentVelocity `
Original file line number Diff line number Diff line change @@ -20,12 +20,6 @@ export function isScalar(x: any): x is Scalar {
20
20
return typeof x === "number" || isDual ( x )
21
21
}
22
22
23
- export function assertScalar ( t : any ) : asserts t is Scalar {
24
- if ( ! isScalar ( t ) ) {
25
- throw new Error ( `[assertScalar] ${ t } ` )
26
- }
27
- }
28
-
29
23
export function scalarReal ( x : Scalar ) : number {
30
24
if ( isDual ( x ) ) {
31
25
return x . real
Original file line number Diff line number Diff line change 1
1
import { isScalar , type Scalar } from "./Scalar.js"
2
- import { rank } from "./rank.js"
3
- import { tensorAlmostEqual } from "./tensorAlmostEqual.js"
4
2
5
3
export type Tensor = Scalar | Array < Tensor >
6
4
7
5
export function isTensor ( x : any ) : x is Tensor {
8
6
return isScalar ( x ) || ( x instanceof Array && x . every ( isTensor ) )
9
7
}
10
-
11
- export function assertTensor1 ( t : Tensor ) : asserts t is Array < Scalar > {
12
- if ( rank ( t ) !== 1 ) {
13
- throw new Error ( `[assertTensor1] ${ t } ` )
14
- }
15
- }
16
-
17
- export function assertTensorArray ( x : any ) : asserts x is Array < Tensor > {
18
- if ( x instanceof Array && x . every ( isTensor ) ) {
19
- return
20
- }
21
-
22
- throw new Error ( `[assertTensorArray] ${ x } ` )
23
- }
24
-
25
- export function assertTensorAlmostEqual (
26
- x : Tensor ,
27
- y : Tensor ,
28
- epsilon : number ,
29
- ) : void {
30
- if ( ! tensorAlmostEqual ( x , y , epsilon ) ) {
31
- throw new Error ( `[assertTensorAlmostEqual] [${ x } ], [${ y } ], ${ epsilon } ` )
32
- }
33
- }
Original file line number Diff line number Diff line change
1
+ import { isScalar , type Scalar } from "./Scalar.js"
2
+ import { isTensor , type Tensor } from "./Tensor.js"
3
+ import { rank } from "./rank.js"
4
+ import { tensorAlmostEqual } from "./tensorAlmostEqual.js"
5
+
6
+ export function assertScalar ( t : any ) : asserts t is Scalar {
7
+ if ( ! isScalar ( t ) ) {
8
+ throw new Error ( `[assertScalar] ${ t } ` )
9
+ }
10
+ }
11
+
12
+ export function assertTensor1 ( t : Tensor ) : asserts t is Array < Scalar > {
13
+ if ( rank ( t ) !== 1 ) {
14
+ throw new Error ( `[assertTensor1] ${ t } ` )
15
+ }
16
+ }
17
+
18
+ export function assertTensorArray ( x : any ) : asserts x is Array < Tensor > {
19
+ if ( x instanceof Array && x . every ( isTensor ) ) {
20
+ return
21
+ }
22
+
23
+ throw new Error ( `[assertTensorArray] ${ x } ` )
24
+ }
25
+
26
+ export function assertTensorAlmostEqual (
27
+ x : Tensor ,
28
+ y : Tensor ,
29
+ epsilon : number ,
30
+ ) : void {
31
+ if ( ! tensorAlmostEqual ( x , y , epsilon ) ) {
32
+ throw new Error ( `[assertTensorAlmostEqual] [${ x } ], [${ y } ], ${ epsilon } ` )
33
+ }
34
+ }
Original file line number Diff line number Diff line change 1
1
export * from "./Scalar.js"
2
2
export * from "./Tensor.js"
3
+ export * from "./assertions.js"
3
4
export * from "./rank.js"
4
5
export * from "./shape.js"
5
6
export * from "./tensorAlmostEqual.js"
You can’t perform that action at this time.
0 commit comments