Fix stack-use-after-scope.
Otherwise the arrays referred to by TConstArrayRef do not survive for the call to modelCalcer.CalcFlat.
@@ -67,7 +67,7 @@ Y_UNIT_TEST_SUITE(TObliviousTreeModel) {
Y_UNIT_TEST(TestFlatCalcFloat) {
auto modelCalcer = SimpleFloatModel();
TVector<double> result(8);
- TVector<TConstArrayRef<float>> features = {
+ TVector<TVector<float>> data = {
{0.f, 0.f, 0.f},
{3.f, 0.f, 0.f},
{0.f, 1.f, 0.f},
@@ -77,6 +77,10 @@ Y_UNIT_TEST_SUITE(TObliviousTreeModel) {
{0.f, 1.f, 1.f},
{3.f, 1.f, 1.f},
};
+ TVector<TConstArrayRef<float>> features(data.size());
+ for (size_t i = 0; i < data.size(); i++) {
+ features[i] = data[i];
+ };
modelCalcer.CalcFlat(
features,
result);
@@ -88,11 +92,15 @@ Y_UNIT_TEST_SUITE(TObliviousTreeModel) {
Y_UNIT_TEST(TestFlatCalcMultiVal) {
auto modelCalcer = MultiValueFloatModel();
- TVector<TConstArrayRef<float>> features = {
+ TVector<TVector<float>> data = {
{0.f, 0.f},
{1.f, 0.f},
{0.f, 1.f},
{1.f, 1.f}};
+ TVector<TConstArrayRef<float>> features(data.size());
+ for (size_t i = 0; i < data.size(); i++) {
+ features[i] = data[i];
+ };
TVector<double> result(features.size() * 3);
modelCalcer.CalcFlat(
features,
