From e6fbb4b526a8dfd6eb1134201ee28a50058291be Mon Sep 17 00:00:00 2001 From: Giff Song Date: Mon, 24 Oct 2016 02:41:14 +0900 Subject: [PATCH] Add definitions for ndarray --- ndarray/ndarray-test.ts | 27 +++++++++++++++++++++++++++ ndarray/ndarray.d.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 ndarray/ndarray-test.ts create mode 100644 ndarray/ndarray.d.ts diff --git a/ndarray/ndarray-test.ts b/ndarray/ndarray-test.ts new file mode 100644 index 0000000000..1c4e829d90 --- /dev/null +++ b/ndarray/ndarray-test.ts @@ -0,0 +1,27 @@ +/// + +import ndarray = require('ndarray'); + +const data = new Int32Array(2 * 2 * 2 + 10); +const a = ndarray(data, [2, 2, 2], [1, 2, 4], 5); + +console.log(a.data === data); +console.log(a.shape[0] === 2); +console.log(a.shape[1] === 2); +console.log(a.shape[2] === 2); +console.log(a.stride[0] === 1); +console.log(a.stride[1] === 2); +console.log(a.stride[2] === 4); +console.log(a.offset === 5); +console.log(a.dtype === 'int32'); +console.log(a.size === 8); +console.log(a.order[0] === 0); +console.log(a.order[1] === 1); +console.log(a.order[2] === 2); +console.log(a.dimension === 3); +console.log(a.set(0, 0, 0, 1) === 1); +console.log(a.get(0, 0, 0) === 1); +console.log(a.index(1, 1, 1) === 12); + +const b = a.lo(0, 0, 0).hi(1, 1, 1); +const c = b.step(0).transpose(0, 0, 0).pick(null, null, 0); diff --git a/ndarray/ndarray.d.ts b/ndarray/ndarray.d.ts new file mode 100644 index 0000000000..64be7833ba --- /dev/null +++ b/ndarray/ndarray.d.ts @@ -0,0 +1,35 @@ +// Type definitions for ndarray v1.0.18 +// Project: https://github.com/scijs/ndarray +// Definitions by: Giff Song +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'ndarray' { + type Data = + Array | Int8Array | Int16Array | Int32Array | + Uint8Array | Uint16Array | Uint32Array | + Float32Array | Float64Array | Uint8ClampedArray; + + interface ndarray { + data: Data; + shape: number[]; + stride: number[]; + offset: number; + dtype: 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' |'uint32' | + 'float32' | 'float64' | 'array'| 'uint8_clamped' | 'buffer' | 'generic'; + size: number; + order: number[]; + dimension: number; + get(...args: number[]): number; + set(...args: number[]): number; + index(...args: number[]): number; + lo(...args: number[]): ndarray; + hi(...args: number[]): ndarray; + step(...args: number[]): ndarray; + transpose(...args: number[]): ndarray; + pick(...args: number[]): ndarray; + } + + function ndarray(data: Data, shape?: number[], stride?: number[], offset?: number): ndarray; + + export = ndarray; +}