Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
webgl: operator Tanh (#62)
Browse files Browse the repository at this point in the history
* Add tanh ops for webgl backend

* A faster tanh ops for webgl backend
  • Loading branch information
NTT123 authored and fs-eire committed Jan 9, 2019
1 parent 35ed071 commit 653fc9e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/backends/webgl/ops/unary-op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ export function glslSqrt(): GlslValueFunction {
export function glslTan(): GlslValueFunction {
return glslBuiltinUnary('tan');
}
export function glslTanh(): GlslValueFunction {
const name = `tanh_`;
const body = `
float ${name}(float a) {
a = clamp(a, -10., 10.);
a = exp(2.*a);
return (a - 1.) / (a + 1.);
}
vec4 ${name}(vec4 v) {
v = clamp(v, -10., 10.);
v = exp(2.*v);
return (v - 1.) / (v + 1.);
}
`;
return {body, name, type: FunctionType.ValueBased};
}
function glslBuiltinUnary(fname: string): GlslValueFunction {
const name = `${fname}_`;
const body = `
Expand Down
2 changes: 2 additions & 0 deletions lib/backends/webgl/session-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class WebGLSessionHandler implements SessionHandler {
return new WebGLSlice();
case 'Tan':
return new unaryOps.WebGLUnaryOp(FLOAT_TYPES, unaryOps.glslTan());
case 'Tanh':
return new unaryOps.WebGLUnaryOp(FLOAT_TYPES, unaryOps.glslTanh());
case 'Transpose':
return new WebGLTranspose();
case 'Tile':
Expand Down
4 changes: 2 additions & 2 deletions test/unittest-whitelist.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@
// "test_slice_start_out_of_bounds", // tensor shape of 0
"test_tan_example",
"test_tan",
// "test_tanh_example",
// "test_tanh",
"test_tanh_example",
"test_tanh",
"test_tile",
"test_tile_precomputed",
"test_transpose_all_permutations_0",
Expand Down

0 comments on commit 653fc9e

Please sign in to comment.