https://github.com/jackvial/operator-overload.ts
Using TS Compiler API to add operator overloading to TS
https://github.com/jackvial/operator-overload.ts
compilers operator-overloading typescript
Last synced: 6 months ago
JSON representation
Using TS Compiler API to add operator overloading to TS
- Host: GitHub
- URL: https://github.com/jackvial/operator-overload.ts
- Owner: jackvial
- Created: 2024-09-14T14:10:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-15T01:39:03.000Z (over 1 year ago)
- Last Synced: 2024-09-15T08:07:02.739Z (over 1 year ago)
- Topics: compilers, operator-overloading, typescript
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Operator Overloading In TypeScript
Using TS Compiler API to add operator overloading to TS
# Examples
```
const a = new Tensor([
[1, 2],
[3, 4]
]);
const b = new Tensor([
[5, 6],
[7, 8]
]);
console.log('Tensor Tensor Multiplication Example');
// @ts-ignore
const c = a * b;
console.log("c: ", c);
console.log('-----------------------------------');
console.log('Tensor Scalar Multiplication Example (Scalar Right)');
// @ts-ignore
const d = a * 2;
console.log("d: ", d)
console.log('-----------------------------------');
console.log('Tensor Scalar Multiplication Example (Scalar Left)');
// @ts-ignore
const e = 2 * a;
console.log("e: ", e);
```
```
✔ ~/Code/ts/operator-overload.ts [main|✔]
20:58 $ npm run example
> operator-overload-ts@1.0.0 example
> node dist/index.js
a: Tensor { value: [ [ 1, 2 ], [ 3, 4 ] ] }
b: Tensor { value: [ [ 5, 6 ], [ 7, 8 ] ] }
Tensor Tensor Multiplication Example
c: Tensor { value: [ [ 19, 22 ], [ 43, 50 ] ] }
-----------------------------------
Tensor Scalar Multiplication Example (Scalar Right)
d: Tensor { value: [ [ 2, 4 ], [ 6, 8 ] ] }
-----------------------------------
Tensor Scalar Multiplication Example (Scalar Left)
e: Tensor { value: [ [ 2, 4 ], [ 6, 8 ] ] }
```
# Compile
`npm run build` or `npx ts-node src/compile.ts`
# Run Example
`npm run example` or `node dist/index.js`