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
[SobolEngine] Update direction numbers to 21201 dims #49710
Changes from all commits
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -126,19 +126,28 @@ Tensor& _sobol_engine_initialize_state_(Tensor& sobolstate, int64_t dimension) { | |||||||||
TORCH_CHECK(sobolstate.dtype() == at::kLong, | ||||||||||
"sobolstate needs to be of type ", at::kLong); | ||||||||||
|
||||||||||
/// First row of `sobolstate` is 1 | ||||||||||
sobolstate.select(0, 0).fill_(1); | ||||||||||
|
||||||||||
/// Use a tensor accessor for `sobolstate` | ||||||||||
auto ss_a = sobolstate.accessor<int64_t, 2>(); | ||||||||||
for (int64_t d = 0; d < dimension; ++d) { | ||||||||||
|
||||||||||
/// First row of `sobolstate` is all 1s | ||||||||||
for (int64_t m = 0; m < MAXBIT; ++m) { | ||||||||||
ss_a[0][m] = 1; | ||||||||||
} | ||||||||||
|
||||||||||
/// Remaining rows of sobolstate (row 2 through dim, indexed by [1:dim]) | ||||||||||
for (int64_t d = 1; d < dimension; ++d) { | ||||||||||
int64_t p = poly[d]; | ||||||||||
int64_t m = bit_length(p) - 1; | ||||||||||
|
||||||||||
// First m elements of row d comes from initsobolstate | ||||||||||
for (int64_t i = 0; i < m; ++i) { | ||||||||||
ss_a[d][i] = initsobolstate[d][i]; | ||||||||||
} | ||||||||||
Comment on lines
143
to
145
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. Nit
Suggested change
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. I have very little understanding of the C++ internals of torch, but this fails (your suggestion above as well). Note that initsobolstate is a C array not a tensor, not sure if that's what's the issue here. I'll leave this and the stderr: caffe2/aten/src/ATen/native/SobolEngineOps.cpp:141:32: error: invalid operands to binary expression ('TensorAccessor<long, 2UL - 1, DefaultPtrTraits, long>' and 'int64_t' (aka 'long')) |
||||||||||
|
||||||||||
// Fill in remaining elements of v as in Section 2 (top of pg. 90) of: | ||||||||||
// P. Bratley and B. L. Fox. Algorithm 659: Implementing sobol's | ||||||||||
// quasirandom sequence generator. ACM Trans. | ||||||||||
// Math. Softw., 14(1):88-100, Mar. 1988. | ||||||||||
for (int64_t j = m; j < MAXBIT; ++j) { | ||||||||||
int64_t newv = ss_a[d][j - m]; | ||||||||||
int64_t pow2 = 1; | ||||||||||
|
@@ -152,6 +161,8 @@ Tensor& _sobol_engine_initialize_state_(Tensor& sobolstate, int64_t dimension) { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/// Multiply each column of sobolstate by power of 2: | ||||||||||
/// sobolstate * [2^(maxbit-1), 2^(maxbit-2),..., 2, 1] | ||||||||||
Tensor pow2s = at::pow(2, at::native::arange((MAXBIT - 1), -1, -1, sobolstate.options())); | ||||||||||
sobolstate.mul_(pow2s); | ||||||||||
return sobolstate; | ||||||||||
|
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.
Nit