-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from chaoming0625/master
update quickstart docs & enable jit error checking
- Loading branch information
Showing
17 changed files
with
2,055 additions
and
1,655 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
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
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
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,80 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from brainpy.math.numpy_ops import any, all | ||
from jax.core import Primitive | ||
from jax.interpreters import batching, mlir, xla | ||
from jax.abstract_arrays import ShapedArray | ||
import jax.numpy as jnp | ||
|
||
|
||
__all__ = [ | ||
'remove_vmap' | ||
] | ||
|
||
|
||
def remove_vmap(x, op='any'): | ||
if op == 'any': | ||
return _any_without_vmap(x) | ||
elif op == 'all': | ||
return _all_without_vmap(x) | ||
else: | ||
raise ValueError(f'Do not support type: {op}') | ||
|
||
|
||
_any_no_vmap_prim = Primitive('any_no_vmap') | ||
|
||
|
||
def _any_without_vmap(x): | ||
return _any_no_vmap_prim.bind(x) | ||
|
||
|
||
def _any_without_vmap_imp(x): | ||
return any(x) | ||
|
||
|
||
def _any_without_vmap_abs(x): | ||
return ShapedArray(shape=(), dtype=jnp.bool_) | ||
|
||
|
||
def _any_without_vmap_batch(x, batch_axes): | ||
(x, ) = x | ||
return _any_without_vmap(x), batching.not_mapped | ||
|
||
|
||
_any_no_vmap_prim.def_impl(_any_without_vmap_imp) | ||
_any_no_vmap_prim.def_abstract_eval(_any_without_vmap_abs) | ||
batching.primitive_batchers[_any_no_vmap_prim] = _any_without_vmap_batch | ||
if hasattr(xla, "lower_fun"): | ||
xla.register_translation(_any_no_vmap_prim, | ||
xla.lower_fun(_any_without_vmap_imp, multiple_results=False, new_style=True)) | ||
mlir.register_lowering(_any_no_vmap_prim, mlir.lower_fun(_any_without_vmap_imp, multiple_results=False)) | ||
|
||
|
||
_all_no_vmap_prim = Primitive('all_no_vmap') | ||
|
||
|
||
def _all_without_vmap(x): | ||
return _all_no_vmap_prim.bind(x) | ||
|
||
|
||
def _all_without_vmap_imp(x): | ||
return all(x) | ||
|
||
|
||
def _all_without_vmap_abs(x): | ||
return ShapedArray(shape=(), dtype=jnp.bool_) | ||
|
||
|
||
def _all_without_vmap_batch(x, batch_axes): | ||
(x, ) = x | ||
return _all_without_vmap(x), batching.not_mapped | ||
|
||
|
||
_all_no_vmap_prim.def_impl(_all_without_vmap_imp) | ||
_all_no_vmap_prim.def_abstract_eval(_all_without_vmap_abs) | ||
batching.primitive_batchers[_all_no_vmap_prim] = _all_without_vmap_batch | ||
if hasattr(xla, "lower_fun"): | ||
xla.register_translation(_all_no_vmap_prim, | ||
xla.lower_fun(_all_without_vmap_imp, multiple_results=False, new_style=True)) | ||
mlir.register_lowering(_all_no_vmap_prim, mlir.lower_fun(_all_without_vmap_imp, multiple_results=False)) | ||
|
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
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
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
Oops, something went wrong.