Skip to content

Boolean indexing alternative #408

Answered by awni
Kheims asked this question in Q&A
Jan 9, 2024 · 1 comments · 9 replies
Discussion options

You must be logged in to vote

@Kheims It shouldn't be too bad to precompute the non-zero degree indices from a perf standpoint. I know it is not that elegant.

A slightly hacky solution could be to do something like:

>>> import mlx.core as mx
>>> deg = mx.array([1,2,3,0])
>>> deg += 1e-10
>>> deg_inv_sq = deg**(-0.5)
>>> deg_inv_sq = mx.where(deg_inv_sq <= 1, deg_inv_sq, 0)
>>> deg_inv_sq
array([1, 0.707107, 0.57735, 0], dtype=float32)

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@Kheims
Comment options

@awni
Comment options

@Kheims
Comment options

@awni
Comment options

Answer selected by Kheims
@Kheims
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants