Skip to content

Commit

Permalink
fix: fixed typo PeculiarVentures#62, fixed types for Ract.isInRect, T…
Browse files Browse the repository at this point in the history
…ypedPool, Tensor
  • Loading branch information
apilguk committed Aug 27, 2020
1 parent 374af8c commit aea32a2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"marked": "^1.1.1",
"micro-fps": "^0.1.2",
"platform": "^1.3.4",
"prismjs": "^1.20.0",
"prismjs": "1.20.0",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
Expand Down
23 changes: 11 additions & 12 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CaptureVideo {
start(deviceID?: string, exactFacingMode?: string): void;
stop(): void;
getImageBuffer(type: 'uint8' | 'float32' | Tensor): Float32Array | Uint8Array | Tensor | ImageData
getImageBufferTo(dtype: 'uint8' | 'float32' | Tensor, ctx?: CanvasRenderingContext2D, width?: number, height?: number, x?: number, y?: number, w?: number, h?: number, to: Tensor): void
getImageBufferTo(dtype: 'uint8' | 'float32' | Tensor, ctx?: CanvasRenderingContext2D, width?: number, height?: number, x?: number, y?: number, w?: number, h?: number, to?: Tensor): void
getSourceImageBuffer(dtype: 'uint8' | 'float32' | Tensor, x?: number, y?: number, w?: number, h?: number): Float32Array | Uint8Array | Tensor | ImageData
}

Expand Down Expand Up @@ -81,12 +81,12 @@ export class Rect {
public scale(w: number, h: number): Rect
public clone(): Rect
public clear(): Rect
public fromDeep(array: number[]): Rect
public fromDeep(array: number[][]): Rect
public fromArray(array: number[]): Rect
public toArray(): number[]
public toJSON(): number[]
public fromLines(a: Line, b: Line, c: Line, d: Line): Rect
public isInRect(rect: Rect): boolean
public isInRect(x: number, y: number): boolean
public isNotEmpty(): boolean
public set(ax: number, ay: number, bx: number, by: number, cx: number, cy: number, dx: number, dy: number): Rect
public assign(rect: Rect): Rect
Expand All @@ -96,8 +96,8 @@ export class Rect {
public perspective(matrix: Tensor): Rect
}

export class TypedPool<T = any> {
constructor(instance: T, count: number)
export class TypedPool<T> {
constructor(instance: new () => T, count: number)
public length: number
at(index: number): T
push(item: T): void
Expand Down Expand Up @@ -158,7 +158,6 @@ export function threshold(input: Tensor, value?: number, axis?: number): Operati
export function transformationMatrix(input: Tensor, output: Tensor): Operation
export function upsample(input: Tensor, coef: number, interpolatoion: 'nearest' | 'linear'): Operation


/* program */

type TensorDataView = Float32Array | Float64Array | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Uint8ClampedArray | number[];
Expand Down Expand Up @@ -187,7 +186,7 @@ type MapDTypeToDataView = {
'array': number[];
}

export class Tensor<T extends TensorDataView = Uint8Array> {
export class Tensor<T = TensorDataView> {
shape: Shape;
size: number;
stride: number[];
Expand All @@ -205,15 +204,14 @@ export class Tensor<T extends TensorDataView = Uint8Array> {
public index(...args: number[]): number
public assign(input: T): void
public relese(): this
public clone(): Tensor<T>
public clone(): Tensor

static IndexToCoord(shape: Shape, index: number): number[]
static CoordToIndex(shape: Shape, coords: number[]): number
static Malloc(dtype: DType, size: number): TensorDataView
static DefineType(data: TensorDataView): DType
static GetTypedArray(dtype: DType, data: TensorDataView): TensorDataView
static GetSize(shape: Shape): number

}

type Chunk = 'pickCurrentValue' | 'pickValue' | 'float' | string;
Expand Down Expand Up @@ -274,18 +272,19 @@ export function isValidGLSLVariableName(name: string): boolean
export function isValidOperationShape(shape: Shape): boolean
export function deprecationWarning(name: string, msg: string): void
export function deprecationError(name: string, msg: string): void
export class DeprecationError extends Error { }
export class DeprecationError extends Error {}

/* math utils */

export function sortPoints(points: number[], canvas?: HTMLCanvasElement): number[]
export function angleBetweenLines(A: Line, B: Line): number
export function transfromPoint(px: number, py: number, transformation: Tensor): [number, number]
export function transformPoint(px: number, py: number, transformation: Tensor): [number, number]
export function generateTransformMatrix(rect: Rect, dstBounds: [number, number], transformMatrix: Tensor, pad?: number): Tensor
export function calcIntegralSum(img: Tensor, x: number, y: number, w: number, h: number): number
export function calcHAARFeature(img: Tensor, feature: number[][], size: number, dx: number, dy: number, dStep: number): number

/* Common */
/* common */

type InputType = Tensor | Operation;

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/math/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* All rights reserved.
*/

import { sortPoints, angleBetweenLines, transfromPoint } from './utils';
import { sortPoints, angleBetweenLines, transformPoint } from './utils';
import Line from './line';

/**
Expand Down Expand Up @@ -351,10 +351,10 @@ export default class Rect {
}

perspective(matrix) {
const p1 = transfromPoint(this.data[0], this.data[1], matrix);
const p2 = transfromPoint(this.data[2], this.data[3], matrix);
const p3 = transfromPoint(this.data[4], this.data[5], matrix);
const p4 = transfromPoint(this.data[6], this.data[7], matrix);
const p1 = transformPoint(this.data[0], this.data[1], matrix);
const p2 = transformPoint(this.data[2], this.data[3], matrix);
const p3 = transformPoint(this.data[4], this.data[5], matrix);
const p4 = transformPoint(this.data[6], this.data[7], matrix);

this.data[0] = p1[0];
this.data[1] = p1[1];
Expand Down
2 changes: 1 addition & 1 deletion lib/math/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function angleBetweenLines(line1, line2) {
return Math.acos(d / Math.sqrt(l2));
}

export function transfromPoint(px, py, transformation) {
export function transformPoint(px, py, transformation) {
const m = transformation;
let xs = 0.0;
let ys = 0.0;
Expand Down
9 changes: 8 additions & 1 deletion lib/program/tensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default class Tensor extends GraphNode {
* @description Write zeros into tensor's data
* @return {Tensor} self
*/
relese() {
release() {
if (this.empty) {
this.data.set(this.empty);
} else {
Expand All @@ -152,6 +152,13 @@ export default class Tensor extends GraphNode {
return this;
}

relese() {
utils.deprecationWarning('Tensor: relese');
this.release();

return this;
}

/**
* @return {Tensor} a shallow copy, new instance
*/
Expand Down
1 change: 0 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const assert = (expression, msg) => {
}
};


export const assertShapesAreEqual = (a, b) => {
if (a.shape.length !== b.shape.length) {
return false;
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@
"LICENSE.md",
"README.md",
"dist/"
]
],
"dependencies": {
"babel-plugin-dynamic-import-node": "^2.3.3"
}
}
2 changes: 1 addition & 1 deletion test/program/tensor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Tensor', () => {
it('release', () => {
const input = new gm.Tensor('float32', [2, 2], new Float32Array([1, 2, 3, 4]));

input.relese();
input.release();

assert.deepEqual(input.data, new Float32Array([0, 0, 0, 0]));
});
Expand Down

0 comments on commit aea32a2

Please sign in to comment.