|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/**
|
|
|
|
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
|
|
|
|
* Copyright 2020-2021 Huawei Technologies Co., Ltd
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -90,67 +90,74 @@ TEST_F(MindDataTestPipeline, TestCalculateNumSamples) {
|
|
|
|
|
int64_t num_rows = 30; // dummy variable for number of rows in the dataset
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl = DistributedSampler(2, 1, false, 6);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt;
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 6);
|
|
|
|
|
|
|
|
|
|
sampl = PKSampler(3, false);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 30);
|
|
|
|
|
|
|
|
|
|
sampl = RandomSampler(false, 12);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 12);
|
|
|
|
|
|
|
|
|
|
sampl = SequentialSampler(0, 10);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 10);
|
|
|
|
|
|
|
|
|
|
std::vector<double> weights = {0.9, 0.8, 0.68, 0.7, 0.71, 0.6, 0.5, 0.4, 0.3, 0.5, 0.2, 0.1};
|
|
|
|
|
sampl = WeightedRandomSampler(weights, 12);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 12);
|
|
|
|
|
|
|
|
|
|
std::vector<int64_t> indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21};
|
|
|
|
|
sampl = SubsetRandomSampler(indices, 11);
|
|
|
|
|
EXPECT_NE(sampl, nullptr);
|
|
|
|
|
sampler_rt = sampl->SamplerBuild();
|
|
|
|
|
sampl->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_EQ(sampler_rt->CalculateNumSamples(num_rows), 11);
|
|
|
|
|
|
|
|
|
|
// Testing chains
|
|
|
|
|
// Parent and child have num_samples
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl1 = WeightedRandomSampler(weights, 12);
|
|
|
|
|
EXPECT_NE(sampl1, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt1 = sampl1->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt1;
|
|
|
|
|
sampl1->SamplerBuild(&sampler_rt1);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl2 = SequentialSampler(0, 10);
|
|
|
|
|
EXPECT_NE(sampl2, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt2 = sampl2->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt2;
|
|
|
|
|
sampl2->SamplerBuild(&sampler_rt2);
|
|
|
|
|
sampler_rt2->AddChild(sampler_rt1);
|
|
|
|
|
EXPECT_EQ(sampler_rt2->CalculateNumSamples(num_rows), 10);
|
|
|
|
|
|
|
|
|
|
// Parent doesn't have num_samples
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl3 = WeightedRandomSampler(weights, 12);
|
|
|
|
|
EXPECT_NE(sampl3, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt3 = sampl3->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt3;
|
|
|
|
|
sampl3->SamplerBuild(&sampler_rt3);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl4 = SubsetRandomSampler(indices);
|
|
|
|
|
EXPECT_NE(sampl4, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt4 = sampl4->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt4;
|
|
|
|
|
sampl4->SamplerBuild(&sampler_rt4);
|
|
|
|
|
sampler_rt4->AddChild(sampler_rt3);
|
|
|
|
|
EXPECT_EQ(sampler_rt4->CalculateNumSamples(num_rows), 11);
|
|
|
|
|
|
|
|
|
|
// Child doesn't have num_samples
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl5 = RandomSampler(false);
|
|
|
|
|
EXPECT_NE(sampl5, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt5 = sampl5->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt5;
|
|
|
|
|
sampl5->SamplerBuild(&sampler_rt5);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl6 = PKSampler(3, false, 7);
|
|
|
|
|
EXPECT_NE(sampl6, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt6 = sampl6->SamplerBuild();
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt6;
|
|
|
|
|
sampl6->SamplerBuild(&sampler_rt6);
|
|
|
|
|
sampler_rt6->AddChild(sampler_rt5);
|
|
|
|
|
EXPECT_EQ(sampler_rt6->CalculateNumSamples(num_rows), 7);
|
|
|
|
|
}
|
|
|
|
@ -159,10 +166,14 @@ TEST_F(MindDataTestPipeline, TestSamplersMoveParameters) {
|
|
|
|
|
std::vector<int64_t> indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23};
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl1 = SubsetRandomSampler(indices);
|
|
|
|
|
EXPECT_FALSE(indices.empty());
|
|
|
|
|
EXPECT_NE(sampl1->SamplerBuild(), nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt = nullptr;
|
|
|
|
|
sampl1->SamplerBuild(&sampler_rt);
|
|
|
|
|
EXPECT_NE(sampler_rt, nullptr);
|
|
|
|
|
std::shared_ptr<SamplerObj> sampl2 = SubsetRandomSampler(std::move(indices));
|
|
|
|
|
EXPECT_TRUE(indices.empty());
|
|
|
|
|
EXPECT_NE(sampl2->SamplerBuild(), nullptr);
|
|
|
|
|
std::shared_ptr<SamplerRT> sampler_rt2 = nullptr;
|
|
|
|
|
sampl2->SamplerBuild(&sampler_rt2);
|
|
|
|
|
EXPECT_NE(sampler_rt, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MindDataTestPipeline, TestWeightedRandomSamplerFail) {
|
|
|
|
|