Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add colab link for documentation notebooks #614

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[math] Fix can not import jax.in1d
  • Loading branch information
Routhleck committed Feb 7, 2024
commit 3e6758ad01065308211ac8f5e895260b2ce37fe9
18 changes: 17 additions & 1 deletion brainpy/_src/math/compat_numpy.py
Original file line number Diff line number Diff line change
@@ -205,6 +205,23 @@ def asfarray(a, dtype=np.float_):
dtype = np.float_
return asarray(a, dtype=dtype)

def in1d(ar1, ar2, assume_unique: bool = False, invert: bool = False) -> Array:
del assume_unique
ar1_flat = ravel(ar1)
ar2_flat = ravel(ar2)
# Note: an algorithm based on searchsorted has better scaling, but in practice
# is very slow on accelerators because it relies on lax control flow. If XLA
# ever supports binary search natively, we should switch to this:
# ar2_flat = jnp.sort(ar2_flat)
# ind = jnp.searchsorted(ar2_flat, ar1_flat)
# if invert:
# return ar1_flat != ar2_flat[ind]
# else:
# return ar1_flat == ar2_flat[ind]
if invert:
return asarray((ar1_flat[:, None] != ar2_flat[None, :]).all(-1))
else:
return asarray((ar1_flat[:, None] == ar2_flat[None, :]).any(-1))

# Others
# ------
@@ -237,7 +254,6 @@ def asfarray(a, dtype=np.float_):
histogram_bin_edges = _compatible_with_brainpy_array(jnp.histogram_bin_edges)
histogramdd = _compatible_with_brainpy_array(jnp.histogramdd)
i0 = _compatible_with_brainpy_array(jnp.i0)
in1d = _compatible_with_brainpy_array(jnp.in1d)
indices = _compatible_with_brainpy_array(jnp.indices)
insert = _compatible_with_brainpy_array(jnp.insert)
intersect1d = _compatible_with_brainpy_array(jnp.intersect1d)
Loading