catniff 0.6.2 → 0.6.3

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/dist/core.d.ts CHANGED
@@ -196,6 +196,9 @@ export declare class Tensor {
196
196
  static randintLike(tensor: Tensor, low: number, high: number, options?: TensorOptions): Tensor;
197
197
  static normal(shape: number[], mean: number, stdDev: number, options?: TensorOptions): Tensor;
198
198
  static uniform(shape: number[], low: number, high: number, options?: TensorOptions): Tensor;
199
+ static arange(start: number, stop?: number, step?: number, options?: TensorOptions): Tensor;
200
+ static linspace(start: number, stop: number, steps: number, options?: TensorOptions): Tensor;
201
+ static eye(n: number, m?: number, options?: TensorOptions): Tensor;
199
202
  backward(options?: {
200
203
  zeroGrad?: boolean;
201
204
  }): void;
package/dist/core.js CHANGED
@@ -1574,6 +1574,47 @@ class Tensor {
1574
1574
  }
1575
1575
  return new Tensor(outputValue, { shape, numel: outputSize, ...options });
1576
1576
  }
1577
+ // Utility to create an 1D tensor from a range incrementing with "step"
1578
+ static arange(start, stop, step = 1, options = {}) {
1579
+ if (typeof stop === "undefined") {
1580
+ stop = start;
1581
+ start = 0;
1582
+ }
1583
+ const outputSize = Math.ceil((stop - start) / step);
1584
+ const outputShape = [outputSize];
1585
+ const outputValue = new Array(outputSize);
1586
+ for (let index = 0; index < outputValue.length; index++) {
1587
+ outputValue[index] = start + step * index;
1588
+ }
1589
+ return new Tensor(outputValue, { shape: outputShape, numel: outputSize, ...options });
1590
+ }
1591
+ // Utility to create an 1D tensor from a range evenly spaced out with a given amount of steps
1592
+ static linspace(start, stop, steps, options = {}) {
1593
+ if (steps <= 0)
1594
+ throw new Error("Steps must be positive");
1595
+ if (steps === 1) {
1596
+ return new Tensor([start], { shape: [1], numel: 1, ...options });
1597
+ }
1598
+ const step = (stop - start) / (steps - 1);
1599
+ const outputValue = new Array(steps);
1600
+ for (let index = 0; index < steps; index++) {
1601
+ outputValue[index] = start + step * index;
1602
+ }
1603
+ // Ensure we hit the endpoint exactly (avoids floating point errors)
1604
+ outputValue[steps - 1] = stop;
1605
+ return new Tensor(outputValue, { shape: [steps], numel: steps, ...options });
1606
+ }
1607
+ // Utility to create a 2D tensor with its main diagonal filled with 1s and others with 0s
1608
+ static eye(n, m = n, options = {}) {
1609
+ const outputSize = n * m;
1610
+ const outputShape = [n, m];
1611
+ const outputStrides = Tensor.getStrides(outputShape);
1612
+ const outputValue = new Array(outputSize).fill(0);
1613
+ for (let i = 0; i < Math.min(n, m); i++) {
1614
+ outputValue[i * outputStrides[0] + i * outputStrides[1]] = 1;
1615
+ }
1616
+ return new Tensor(outputValue, { shape: outputShape, strides: outputStrides, numel: outputSize, ...options });
1617
+ }
1577
1618
  // Reverse-mode autodiff call
1578
1619
  backward(options = {}) {
1579
1620
  // Init
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catniff",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "A small Torch-like deep learning framework for Javascript",
5
5
  "main": "index.js",
6
6
  "scripts": {