-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,766 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
target | ||
*.node | ||
*.so | ||
*.dll | ||
*.dylib | ||
**/node_modules | ||
**/.DS_Store | ||
npm-debug.log | ||
cargo.log | ||
cross.log | ||
lib/*.js | ||
lib/*.js | ||
bin/**/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Module 1`] = ` | ||
Float32Array [ | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
] | ||
`; | ||
|
||
exports[`Module 2`] = ` | ||
Float32Array [ | ||
1, | ||
4, | ||
9, | ||
16, | ||
25, | ||
36, | ||
] | ||
`; | ||
|
||
exports[`Tensor 1`] = ` | ||
Float32Array [ | ||
2, | ||
4, | ||
6, | ||
] | ||
`; | ||
|
||
exports[`Tensor 2`] = ` | ||
Float32Array [ | ||
0, | ||
4, | ||
6, | ||
] | ||
`; | ||
|
||
exports[`Tensor 3`] = ` | ||
Float32Array [ | ||
1, | ||
2, | ||
1, | ||
2, | ||
3, | ||
4, | ||
3, | ||
4, | ||
5, | ||
6, | ||
5, | ||
6, | ||
] | ||
`; | ||
|
||
exports[`Tensor 4`] = ` | ||
Float32Array [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
import path from "path"; | ||
import { Module, Tensor, Sampler } from "./index"; | ||
import { Module, Tensor, Sampler, EValueTag, DType } from "./index"; | ||
|
||
const model = path.resolve(__dirname, "__fixtures__/mul.pte"); | ||
|
||
// it("Module", async () => { | ||
// const mod = await Module.load(model); | ||
// expect(mod.method_names).toEqual(["forward"]); | ||
// expect(mod.getMethodMeta("forward")).toEqual({ | ||
// name: "forward", | ||
// inputs: [ | ||
// { tag: "tensor", tensor_info: { dtype: "float32", shape: [3, 2] } }, | ||
// { tag: "tensor", tensor_info: { dtype: "float32", shape: [3, 2] } }, | ||
// ], | ||
// outputs: [{ tag: "tensor", tensor_info: { dtype: "float32", shape: [3, 2] } }], | ||
// }); | ||
// { // execute without inputs | ||
// const outputs = await mod.execute("forward"); | ||
// expect(outputs[0]).toBeInstanceOf(Tensor); | ||
// if (outputs[0] instanceof Tensor) { | ||
// expect(outputs[0].dtype).toBe("float32"); | ||
// expect(outputs[0].shape).toEqual([3, 2]); | ||
// expect(outputs[0].data).toMatchSnapshot(); | ||
// } | ||
// } | ||
// { // forward | ||
// const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6])); | ||
// const outputs = await mod.forward([input, input]); | ||
// expect(outputs[0]).toBeInstanceOf(Tensor); | ||
// if (outputs[0] instanceof Tensor) { | ||
// expect(outputs[0].dtype).toBe("float32"); | ||
// expect(outputs[0].shape).toEqual([3, 2]); | ||
// expect(outputs[0].data).toMatchSnapshot(); | ||
// } | ||
// } | ||
// }); | ||
it("Module", async () => { | ||
const mod = await Module.load(model); | ||
expect(mod.method_names).toEqual(["forward"]); | ||
expect(mod.getMethodMeta("forward")).toEqual({ | ||
name: "forward", | ||
inputs: [ | ||
{ tag: EValueTag.Tensor, tensor_info: { dtype: DType.float32, shape: [3, 2] } }, | ||
{ tag: EValueTag.Tensor, tensor_info: { dtype: DType.float32, shape: [3, 2] } }, | ||
], | ||
outputs: [{ tag: EValueTag.Tensor, tensor_info: { dtype: DType.float32, shape: [3, 2] } }], | ||
}); | ||
{ // execute without inputs | ||
const outputs = await mod.execute("forward"); | ||
expect(outputs[0]).toBeInstanceOf(Tensor); | ||
if (outputs[0] instanceof Tensor) { | ||
expect(outputs[0].dtype).toBe("float32"); | ||
expect(outputs[0].shape).toEqual([3, 2]); | ||
expect(outputs[0].data).toMatchSnapshot(); | ||
} | ||
} | ||
{ // forward | ||
const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6])); | ||
const outputs = await mod.forward([input, input]); | ||
expect(outputs[0]).toBeInstanceOf(Tensor); | ||
if (outputs[0] instanceof Tensor) { | ||
expect(outputs[0].dtype).toBe("float32"); | ||
expect(outputs[0].shape).toEqual([3, 2]); | ||
expect(outputs[0].data).toMatchSnapshot(); | ||
} | ||
} | ||
}); | ||
|
||
// it("Tensor", async () => { | ||
// const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6])); | ||
it("Tensor", async () => { | ||
const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6])); | ||
|
||
// // slice | ||
// const slice = input.slice(null, [1, null]); | ||
// expect(slice.dtype).toBe("float32"); | ||
// expect(slice.shape).toEqual([3, 1]); | ||
// expect(slice.data).toMatchSnapshot(); | ||
// slice | ||
const slice = input.slice(null, [1, null]); | ||
expect(slice.dtype).toBe("float32"); | ||
expect(slice.shape).toEqual([3, 1]); | ||
expect(slice.data).toMatchSnapshot(); | ||
|
||
// // setValue | ||
// slice.setValue([0, 0], 0); | ||
// expect(slice.data).toMatchSnapshot(); | ||
// setValue | ||
slice.setValue([0, 0], 0); | ||
expect(slice.data).toMatchSnapshot(); | ||
|
||
// // concat | ||
// const concat = Tensor.concat([input, input], 1); | ||
// expect(concat.dtype).toBe("float32"); | ||
// expect(concat.shape).toEqual([3, 4]); | ||
// expect(concat.data).toMatchSnapshot(); | ||
// concat | ||
const concat = Tensor.concat([input, input], 1); | ||
expect(concat.dtype).toBe("float32"); | ||
expect(concat.shape).toEqual([3, 4]); | ||
expect(concat.data).toMatchSnapshot(); | ||
|
||
// // reshape | ||
// input.reshape([2, 3]); | ||
// expect(input.dtype).toBe("float32"); | ||
// expect(input.shape).toEqual([2, 3]); | ||
// expect(input.data).toMatchSnapshot(); | ||
// }); | ||
// reshape | ||
const reshaped = input.reshape([2, 3]); | ||
expect(reshaped.dtype).toBe("float32"); | ||
expect(reshaped.shape).toEqual([2, 3]); | ||
expect(reshaped.data).toMatchSnapshot(); | ||
}); | ||
|
||
it("Sampler", async () => { | ||
// const mockTensor = new Tensor("float32", [1, 2, 10], Float32Array.from({ length: 20 }, (_, i) => i)); | ||
const mockTensor = new Tensor("float32", [1, 2, 10], Float32Array.from({ length: 20 }, (_, i) => i)); | ||
const sampler = new Sampler(10); | ||
|
||
// sample | ||
const sample = sampler.sample([1,2,3,4,5,6,7,8,9,10]); | ||
const sample = sampler.sample(mockTensor); | ||
expect(sample).toBeGreaterThanOrEqual(0); | ||
expect(sample).toBeLessThanOrEqual(10); | ||
}); |
Oops, something went wrong.