(a: Tensor)
| 915 | } |
| 916 | } |
| 917 | disposeTensor(a: Tensor): void { |
| 918 | if (!this.state.tensorInfo.has(a.dataId)) { |
| 919 | return; |
| 920 | } |
| 921 | const info = this.state.tensorInfo.get(a.dataId); |
| 922 | |
| 923 | this.state.numTensors--; |
| 924 | if (a.dtype === 'string') { |
| 925 | this.state.numStringTensors--; |
| 926 | this.state.numBytes -= info.bytes; |
| 927 | } |
| 928 | // Don't count bytes for complex numbers as they are counted by their |
| 929 | // components. |
| 930 | if (a.dtype !== 'complex64' && a.dtype !== 'string') { |
| 931 | const bytes = a.size * util.bytesPerElement(a.dtype); |
| 932 | this.state.numBytes -= bytes; |
| 933 | } |
| 934 | |
| 935 | // Remove the reference to dataId if backend dispose the data successfully |
| 936 | if (info.backend.disposeData(a.dataId)) { |
| 937 | this.removeDataId(a.dataId, info.backend); |
| 938 | } |
| 939 | |
| 940 | // TODO(nsthorat): Construct an error and save the stack trace for |
| 941 | // debugging when in debug mode. Creating a stack trace is too expensive |
| 942 | // to do unconditionally. |
| 943 | } |
| 944 | |
| 945 | disposeVariables(): void { |
| 946 | for (const varName in this.state.registeredVariables) { |
no test coverage detected