-
Couldn't load subscription status.
- Fork 4.4k
[MLA-1762] reduce memory allocations from DiscreteActionOutputApplier #4922
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
Changes from all commits
757b05d
99e8883
42d2f23
255bfa7
f2bd60c
f23c0b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,10 +32,11 @@ public Multinomial(int seed) | |
| /// to be monotonic (always increasing). If the CMF is scaled, then the last entry in | ||
| /// the array will be 1.0. | ||
| /// </param> | ||
| /// <returns>A sampled index from the CMF ranging from 0 to cmf.Length-1.</returns> | ||
| public int Sample(float[] cmf) | ||
| /// <param name="branchSize">The number of possible branches, i.e. the effective size of the cmf array.</param> | ||
| /// <returns>A sampled index from the CMF ranging from 0 to branchSize-1.</returns> | ||
| public int Sample(float[] cmf, int branchSize) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the float[] might be larger than we need now, we also pass the effective size of the array. We could instead (or in additionally) repeat the final |
||
| { | ||
| var p = (float)m_Random.NextDouble() * cmf[cmf.Length - 1]; | ||
| var p = (float)m_Random.NextDouble() * cmf[branchSize - 1]; | ||
| var cls = 0; | ||
| while (cmf[cls] < p) | ||
| { | ||
|
|
@@ -44,5 +45,15 @@ public int Sample(float[] cmf) | |
|
|
||
| return cls; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Samples from the Multinomial distribution defined by the provided cumulative | ||
| /// mass function. | ||
| /// </summary> | ||
| /// <returns>A sampled index from the CMF ranging from 0 to cmf.Length-1.</returns> | ||
| public int Sample(float[] cmf) | ||
| { | ||
| return Sample(cmf, cmf.Length); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these exceptions no longer needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure they were ever necessary in the first place. The temporary tensors they were referencing are no longer needed.