| 19 | using namespace NCB; |
| 20 | |
| 21 | static TDataProviderPtr MakeDataProvider( |
| 22 | TConstArrayRef<float> features, |
| 23 | ui32 fCount, |
| 24 | TConstArrayRef<float> labels, |
| 25 | TConstArrayRef<float> weights, |
| 26 | TConstArrayRef<float> baseline |
| 27 | ) { |
| 28 | |
| 29 | TDataProviderBuilderOptions builderOptions; |
| 30 | |
| 31 | THolder<IDataProviderBuilder> dataProviderBuilder; |
| 32 | IRawFeaturesOrderDataVisitor* builderVisitor; |
| 33 | |
| 34 | CreateDataProviderBuilderAndVisitor(builderOptions, |
| 35 | &NPar::LocalExecutor(), |
| 36 | &dataProviderBuilder, |
| 37 | &builderVisitor); |
| 38 | |
| 39 | TDataMetaInfo metaInfo; |
| 40 | metaInfo.TargetType = ERawTargetType::Float; |
| 41 | metaInfo.TargetCount = 1; |
| 42 | metaInfo.HasWeights = weights.data() != nullptr; |
| 43 | if (baseline.data() != nullptr) { |
| 44 | metaInfo.BaselineCount = baseline.size() / labels.size(); |
| 45 | } |
| 46 | metaInfo.FeaturesLayout = new TFeaturesLayout((ui32) fCount); |
| 47 | |
| 48 | const size_t samplesCount = features.size() / fCount; |
| 49 | |
| 50 | builderVisitor->Start(metaInfo, |
| 51 | samplesCount, |
| 52 | EObjectsOrder::Ordered, {}); |
| 53 | |
| 54 | for (ui32 f = 0; f < fCount; ++f) { |
| 55 | auto valHolder = |
| 56 | MakeIntrusive<TTypeCastArrayHolder<float, float>>( |
| 57 | TMaybeOwningConstArrayHolder<float>::CreateNonOwning( |
| 58 | features.Slice(f * samplesCount, samplesCount))); |
| 59 | builderVisitor->AddFloatFeature(f, valHolder); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | builderVisitor->AddTarget( |
| 64 | MakeIntrusive<TTypeCastArrayHolder<float, float>>( |
| 65 | TMaybeOwningConstArrayHolder<float>::CreateNonOwning(labels))); |
| 66 | if (weights.data() != nullptr) { |
| 67 | builderVisitor->AddWeights(weights); |
| 68 | } |
| 69 | |
| 70 | if (baseline.data() != nullptr) { |
| 71 | const ui32 baselineCount = baseline.size() / labels.size(); |
| 72 | for (ui32 baselineIdx = 0; baselineIdx < baselineCount; ++baselineIdx) { |
| 73 | builderVisitor->AddBaseline(baselineIdx, baseline.Slice(baselineIdx * labels.size(), labels.size())); |
| 74 | } |
| 75 | } |
| 76 | builderVisitor->Finish(); |
| 77 | |
| 78 | return dataProviderBuilder->GetResult(); |
no test coverage detected