-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import jax.numpy as jnp | ||
|
||
|
||
def scatter_reduce_sum(indices, values, shape): | ||
zeros = jnp.zeros(shape, values.dtype) | ||
return zeros.at[indices].add(values) | ||
|
||
|
||
def scatter_reduce_min(indices, values, shape): | ||
zeros = jnp.zeros(shape, values.dtype.max, values.dtype) | ||
return zeros.at[indices].min(values) | ||
|
||
|
||
def scatter_reduce_max(indices, values, shape): | ||
zeros = jnp.full(shape, values.dtype.min, values.dtype) | ||
return zeros.at[indices].max(values) | ||
|
||
|
||
def scatter_reduce_mean(indices, values, shape): | ||
zeros = jnp.zeros(shape, values.dtype) | ||
counts = jnp.zeros(shape, values.dtype) | ||
counts.at[indices].add(jnp.ones_like(values)) | ||
return zeros.at[indices].add(values)/counts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters