Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Add complex64 support for tf.abs(). #1331

Merged
merged 5 commits into from
Oct 18, 2018
Merged

Add complex64 support for tf.abs(). #1331

merged 5 commits into from
Oct 18, 2018

Conversation

nsthorat
Copy link
Contributor

@nsthorat nsthorat commented Oct 18, 2018

We hide this behind tf.abs.

y = sqrt(real ^ 2 + imag ^ 2)


This change is Reviewable

@nsthorat nsthorat requested a review from dsmilkov October 18, 2018 17:16
Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r1.
Reviewable status: 0 of 1 approvals obtained (waiting on @nsthorat and @dsmilkov)


src/kernels/webgl/complex_abs_gpu.ts, line 32 at r1 (raw file):

        float imag = getImagAtOutCoords();

        setOutput(sqrt(real * real + imag * imag));

vec2 v = vec2(real, imag)
setOutput(dot(v, v))


src/ops/unary_ops_test.ts, line 142 at r1 (raw file):

      Math.sqrt(0 * 0 + 3 * 3), Math.sqrt(1 * 1 + 0 * 0),
      Math.sqrt(2 * 2 + -1 * -1)
    ]);

add couple more unit tests for different ranks

Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @nsthorat and @dsmilkov)


src/kernels/webgl/complex_abs_gpu.ts, line 32 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

vec2 v = vec2(real, imag)
setOutput(dot(v, v))

forgot sqrt()

Copy link
Contributor Author

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @nsthorat)


src/kernels/webgl/complex_abs_gpu.ts, line 32 at r1 (raw file):

vec2 v = vec2(real, imag)

Nice. Done.


src/ops/unary_ops_test.ts, line 142 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

add couple more unit tests for different ranks

Done

@nsthorat nsthorat merged commit ec0f171 into master Oct 18, 2018
@nsthorat nsthorat deleted the complexabs branch October 18, 2018 17:57
@DirkToewe
Copy link
Contributor

There's also a length() function in GLSL ES 1.00. It might be slightly faster and also avoid some fringe cases of float32 underflow ( float32( (1e-23)² ) = 0 ).

@dsmilkov
Copy link
Contributor

That's a great point @DirkToewe. Want to send a PR?

@DirkToewe
Copy link
Contributor

Here You go

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants