Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TensorFlow.js dependency to 3.x #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disable TensorFlow debug logging at startup.
# Set to 0 if you want to print these debug logs.
TF_CPP_MIN_LOG_LEVEL=3
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js: "8"
node_js: lts/*
script:
- yarn lint
- yarn test
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ about the file format.

API:

import { parse, serialize } from "tfjs-npy"
```ts
import { parse, serialize } from "tfjs-npy"

parse(ab: ArrayBuffer): tf.Tensor
function parse(ab: ArrayBuffer): tf.Tensor

serialize(tensor: tf.Tensor): Promise<ArrayBuffer>
function serialize(tensor: tf.Tensor): Promise<ArrayBuffer>
```

https://github.com/propelml/tfjs-npy

Expand Down
9 changes: 5 additions & 4 deletions npy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import * as tf from "@tensorflow/tfjs-core";

/** Serializes a tensor into a npy file contents. */
export async function serialize(tensor: tf.Tensor): Promise<ArrayBuffer> {
const descr = new Map([["float32", "<f4"], ["int32", "<i4"]]).get(
tensor.dtype,
);
const descr = new Map([
["float32", "<f4"],
["int32", "<i4"],
]).get(tensor.dtype);

// First figure out how long the file is going to be so we can create the
// output ArrayBuffer.
Expand All @@ -32,7 +33,7 @@ export async function serialize(tensor: tf.Tensor): Promise<ArrayBuffer> {
const unpaddedLength =
1 + magicStr.length + versionStr.length + 2 + header.length;
// Spaces to 16-bit align.
const padding = " ".repeat((16 - unpaddedLength % 16) % 16);
const padding = " ".repeat((16 - (unpaddedLength % 16)) % 16);
header += padding;
assertEqual((unpaddedLength + padding.length) % 16, 0);
// Either int32 or float32 for now Both 4 bytes per element.
Expand Down
2 changes: 1 addition & 1 deletion npy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ limitations under the License.
*/

import { test, assertEqual } from "liltest";
import * as tf from "@tensorflow/tfjs-core";
import * as tf from "@tensorflow/tfjs-node";
import * as npy from "./npy";
import { readFileSync } from "fs";
const { expectArraysClose } = tf.test_util;
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
"build": "tsc",
"fmt": "prettier --trailing-comma all --write *.ts",
"lint": "tslint --project tsconfig.json",
"test": "ts-node npy_test.ts"
"test": "ts-node -r dotenv/config npy_test.ts"
},
"dependencies": {
"@tensorflow/tfjs-core": "^0.9.0"
"@tensorflow/tfjs-core": "^3.0.0"
},
"devDependencies": {
"@types/node": "^8.10.11",
"@tensorflow/tfjs-node": "^3.0.0",
"@types/node": "^15.0.2",
"dotenv": "^9.0.0",
"liltest": "^0.0.5",
"prettier": "^1.12.1",
"ts-node": "^6.0.2",
"prettier": "^2.2.1",
"seedrandom": "~2.4.3",
"ts-node": "^9.1.1",
"tslint": "^5.9.1",
"typescript": "^2.8.3"
"typescript": "^4.2.4"
}
}
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"strict": true,
"sourceMap": true,
"removeComments": true,
"preserveConstEnums": true,
Expand All @@ -11,13 +11,14 @@
"outDir": "./dist",
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedParameters": false,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"allowUnreachableCode": false,
"experimentalDecorators": true
"experimentalDecorators": true,
// Necessary for TensorFlow.js
// See https://www.tensorflow.org/js/tutorials/setup#typescript
"skipLibCheck": true
},
"include": ["*.ts"]
}
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"no-require-imports": true,
"no-string-throw": true,
"no-unused-expression": true,
"no-unused-variable": true,
"no-var-keyword": true,
"object-literal-shorthand": true,
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
Expand Down
Loading