Skip to content
Discussion options

You must be logged in to vote

Hi @saeedhd96,

I think that should be possible. Here is a little reproducer. It only supports two distributions at the moment but if you can stack your distribution it should work as well.

if __name__ == "__main__":
    cdf1 = mi.Float(0.1, 0.3, 0.4, 0.6, 0.8, 1.0)
    cdf2 = mi.Float(0.1, 0.2, 0.6, 0.7, 0.9, 1.0)

    sample = mi.Float(0.6, 0.6)

    cdf = dr.zeros(mi.Float, len(cdf1) + len(cdf2))

    dr.scatter(cdf, cdf1, dr.arange(mi.UInt, len(cdf1)))
    dr.scatter(cdf, cdf2, dr.arange(mi.UInt, len(cdf2)) + len(cdf1))

    start = mi.UInt(0, len(cdf1))

    idx = dr.binary_search(
        0, len(cdf1), lambda idx: dr.gather(mi.Float, cdf, idx + start) < sample
    )

    print(f"{idx=}"

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@njroussel
Comment options

Answer selected by saeedhd96
Comment options

You must be logged in to vote
3 replies
@njroussel
Comment options

@saeedhd96
Comment options

@DoeringChristian
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
3 participants