UNPKG

@hoff97/tensor-js

Version:

PyTorch like deep learning inferrence library

85 lines 2.16 kB
export class CosBack { constructor(input) { this.input = input; } backward(grad) { const sin = this.input.value.sin(); const gradAbs = grad.multiply(sin, -1); sin.delete(); const needed = this.input.backward(gradAbs); if (!needed) { gradAbs.delete(); } } delete() { if (!this.input.isLeaf()) { this.input.delete(); } } } export class ACosBack { constructor(input) { this.input = input; } backward(grad) { const squared = this.input.value.multiply(this.input.value); const oneMinus = squared.addMultiplyScalar(-1, 1); squared.delete(); const sqrt = oneMinus.sqrt(); oneMinus.delete(); const gradACos = grad.divide(sqrt, -1); sqrt.delete(); const needed = this.input.backward(gradACos); if (!needed) { gradACos.delete(); } } delete() { if (!this.input.isLeaf()) { this.input.delete(); } } } export class CosHBack { constructor(input) { this.input = input; } backward(grad) { const sinh = this.input.value.sinh(); const gradCosH = grad.multiply(sinh); sinh.delete(); const needed = this.input.backward(gradCosH); if (!needed) { gradCosH.delete(); } } delete() { if (!this.input.isLeaf()) { this.input.delete(); } } } export class ACosHBack { constructor(input) { this.input = input; } backward(grad) { const squared = this.input.value.multiply(this.input.value); const onePlus = squared.addMultiplyScalar(1, -1); squared.delete(); const sqrt = onePlus.sqrt(); onePlus.delete(); const gradACosH = grad.divide(sqrt); sqrt.delete(); const needed = this.input.backward(gradACosH); if (!needed) { gradACosH.delete(); } } delete() { if (!this.input.isLeaf()) { this.input.delete(); } } } //# sourceMappingURL=cosBack.js.map