Skip to content

Commit 42600ba

Browse files
cyyeverfacebook-github-bot
authored andcommitted
Fix IndicesEstimator constructor (#4906)
Summary: X-link: facebookresearch/FBGEMM#1945 The old behaviour of constructor delegation is invalid, it creates a temporary object. Pull Request resolved: #4906 Reviewed By: cthi Differential Revision: D82979114 Pulled By: q10 fbshipit-source-id: 1becc704617b858e453ed1a542f349a9b26fc54e
1 parent ddada9e commit 42600ba

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

fbgemm_gpu/src/tbe/eeg/indices_estimator.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "indices_estimator.h"
10+
#include <algorithm>
1011
#include <cassert>
1112
#include <chrono>
1213
#include <fstream>
@@ -45,7 +46,7 @@ void IndicesEstimator::populateLogTable_() {
4546
}
4647
}
4748

48-
IndicesEstimator::IndicesEstimator(const torch::Tensor& indices) {
49+
void IndicesEstimator::init(const torch::Tensor& indices) {
4950
TORCH_CHECK(
5051
indices.numel() > 0, "indices numel is ", indices.numel(), "(< 1)");
5152

@@ -62,6 +63,10 @@ IndicesEstimator::IndicesEstimator(const torch::Tensor& indices) {
6263
populateLogTable_();
6364
}
6465

66+
IndicesEstimator::IndicesEstimator(const torch::Tensor& indices) {
67+
init(indices);
68+
}
69+
6570
IndicesEstimator::IndicesEstimator(const std::filesystem::path& tensors_path) {
6671
// NOTE: PyTorch API requires us to use a torch::pickle_load on a
6772
// vector<char> (torch::load doesn't work here)
@@ -79,7 +84,7 @@ IndicesEstimator::IndicesEstimator(const std::filesystem::path& tensors_path) {
7984
assert((ival.isTensor()) && "Loaded file is not a tensor!");
8085

8186
// Pass it to the tensor-based constructor
82-
IndicesEstimator(ival.toTensor());
87+
init(ival.toTensor());
8388
}
8489

8590
std::vector<double> IndicesEstimator::heavyHitters() const {

fbgemm_gpu/src/tbe/eeg/indices_estimator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class IndicesEstimator {
3737
double estimateQuality(const IndicesDistributionParameters& params) const;
3838

3939
private:
40+
void init(const torch::Tensor& indices);
41+
4042
// Hardcoded parameters
4143
// Heavy hitter threshold: we make sure they account for >=90% of the mass or
4244
// the top 20 frequencies, whichever comes first. We also ensure that we cover

0 commit comments

Comments
 (0)