catniff 0.7.3 → 0.8.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 CHANGED
@@ -9,6 +9,8 @@ Install through npm:
9
9
  npm install catniff
10
10
  ```
11
11
 
12
+ Ensure you have Node v24 as well for things like float16 to work.
13
+
12
14
  ## Tensors
13
15
 
14
16
  Tensors in Catniff can be created by passing in a number or an nD array, and there are built-in methods that can be used to perform tensor arithmetic:
@@ -148,6 +150,18 @@ All available APIs are in [`./src/`](./src/) if you want to dig deeper.
148
150
  * Code refactoring.
149
151
  * Proper tests.
150
152
 
153
+ ## Cite Catniff
154
+
155
+ ```bibtex
156
+ @misc{catniff,
157
+ author = {Phu Minh Nguyen},
158
+ title = {Catniff: Torch-like deep learning framework for Javascript},
159
+ year = {2025},
160
+ publisher = {GitHub},
161
+ url = {https://github.com/nguyenphuminh/catniff}
162
+ }
163
+ ```
164
+
151
165
  ## Copyrights and License
152
166
 
153
167
  Copyrights © 2025 Nguyen Phu Minh.
package/dist/core.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Backend } from "./backend";
2
- export type TensorValue = number | TensorValue[];
2
+ import { dtype, MemoryBuffer } from "./dtype";
3
+ export type TensorValue = number | ArrayLike<TensorValue>;
3
4
  export interface TensorOptions {
4
5
  shape?: number[];
5
6
  strides?: number[];
@@ -10,9 +11,10 @@ export interface TensorOptions {
10
11
  gradFn?: Function;
11
12
  children?: Tensor[];
12
13
  device?: string;
14
+ dtype?: dtype;
13
15
  }
14
16
  export declare class Tensor {
15
- value: number[] | number;
17
+ value: MemoryBuffer;
16
18
  shape: number[];
17
19
  strides: number[];
18
20
  offset: number;
@@ -22,12 +24,13 @@ export declare class Tensor {
22
24
  gradFn: Function;
23
25
  children: Tensor[];
24
26
  device: string;
27
+ dtype: dtype;
25
28
  static training: boolean;
26
29
  static noGrad: boolean;
27
30
  static createGraph: boolean;
28
31
  constructor(value: TensorValue, options?: TensorOptions);
29
- static flattenValue(tensor: TensorValue): number[] | number;
30
- static getShape(tensor: TensorValue): number[];
32
+ static flattenValue(tensorValue: TensorValue): ArrayLike<number>;
33
+ static getShape(tensorValue: TensorValue): number[];
31
34
  static getStrides(shape: number[]): number[];
32
35
  static padShape(stridesA: number[], stridesB: number[], shapeA: number[], shapeB: number[]): [
33
36
  number[],
@@ -40,11 +43,12 @@ export declare class Tensor {
40
43
  static coordsToUnbroadcastedIndex(coords: number[], shape: number[], strides: number[]): number;
41
44
  static coordsToIndex(coords: number[], strides: number[]): number;
42
45
  static shapeToSize(shape: number[]): number;
46
+ static getResultDtype(type1: dtype, type2: dtype): dtype;
47
+ handleOther(other: Tensor | TensorValue): Tensor;
43
48
  static elementWiseAB(tA: Tensor, tB: Tensor, op: (tA: number, tB: number) => number): Tensor;
44
49
  static elementWiseSelf(tA: Tensor, op: (tA: number) => number): Tensor;
45
50
  elementWiseABDAG(other: TensorValue | Tensor, op: (a: number, b: number) => number, thisGrad?: (self: Tensor, other: Tensor, outGrad: Tensor) => Tensor, otherGrad?: (self: Tensor, other: Tensor, outGrad: Tensor) => Tensor): Tensor;
46
51
  elementWiseSelfDAG(op: (a: number) => number, thisGrad?: (self: Tensor, outGrad: Tensor) => Tensor): Tensor;
47
- handleOther(other: Tensor | TensorValue): Tensor;
48
52
  static addGrad(tensor: Tensor, accumGrad: Tensor): void;
49
53
  static normalizeDims(dims: number[], numDims: number): number[];
50
54
  isContiguous(): boolean;
@@ -70,15 +74,15 @@ export declare class Tensor {
70
74
  operation: (accumulator: number, value: number) => number;
71
75
  needsCounters?: boolean;
72
76
  postProcess?: (options: {
73
- values: number[];
74
- counters?: number[];
77
+ values: MemoryBuffer;
78
+ counters?: MemoryBuffer;
75
79
  }) => void;
76
80
  needsShareCounts?: boolean;
77
81
  gradientFn: (options: {
78
- outputValue: number[];
79
- originalValue: number[];
80
- counters: number[];
81
- shareCounts: number[];
82
+ outputValue: MemoryBuffer;
83
+ originalValue: MemoryBuffer;
84
+ counters: MemoryBuffer;
85
+ shareCounts: MemoryBuffer;
82
86
  realIndex: number;
83
87
  outIndex: number;
84
88
  }) => number;
@@ -220,7 +224,8 @@ export declare class Tensor {
220
224
  val(): TensorValue;
221
225
  detach(): Tensor;
222
226
  clone(): Tensor;
223
- replace(other: Tensor | TensorValue, allowShapeMismatch?: boolean): Tensor;
227
+ replace(other: Tensor | TensorValue): Tensor;
228
+ cast(dtype: dtype): Tensor;
224
229
  static backends: Map<string, Backend>;
225
230
  to(device: string): Tensor;
226
231
  to_(device: string): Tensor;