yarn install # Install dependencies
yarn build # Build for browser and node (runs clean first)
yarn test # Run tests against src/ (uses mocha + tsx)
yarn test:build # Run tests against built library in build/
yarn test:coverage # Run tests with coverage report
yarn test:watch # Watch mode for tests (alias: yarn watch)
yarn lint # Lint src/ with ESLint
yarn serve # Serve on localhost:8080
yarn docs # Build TypeDoc documentation
yarn update-tests # Regenerate test/testcases.gen.js from scripts/generate_tests.pyTo run a single test file:
yarn mocha --node-option conditions=torch-src test/tensor.test.jssrcindex.tsis the entry point of the library.tensor.tsis the main tensor class.functionscontains all functions that tensors can perform.nncontains all neural network modules (for everything undertorch.nn).optimcontains all optimizers (for everything undertorch.optim).creationcontains all tensor creation functions (all functions that create a tensor not from scratch, includingzeros,randn).
examplescontains example usages of the library, including on node, on the browser, and using pyodide on the browser.testcontains the test cases of the library, including on node and on the browser. See Testing.
Use yarn watch (or yarn test:watch) to automatically re-run tests on each edit.
To add a new function, add it to src/functions/ops.ts.
- To allow for
torch.<opname>(<tensor>, <args>), add it as well tosrc/functions/functional.ts. - To allow for
<tensor>.<opname>(<args>), add it as well tosrc/tensor.tsas atensormethod.
Tests are run using mocha.
- Node: To test on node, run
yarn test. - Browser: To test on browser, run
yarn serve(afteryarn buildif necessary) and navigate to http://localhost:8080/test/.
To create a new test:
- Create a new
.test.js/.test.tsfile intestor write your new test in one of the existing files. - If you created a new file and would like to test it on the browser, add it to
test/index.html.
To see docs, run yarn docs to build, and run yarn serve docs to serve docs on http://localhost:8080/.
To ensure familiarity with PyTorch, docs should be derived from the PyTorch docs, as mentioned in NOTICE.