9
9
#include " TMVA/RModel.hxx"
10
10
#include " TMVA/SOFIE_common.hxx"
11
11
12
+ namespace {
13
+ const std::string SP = " " ;
14
+ }
15
+
12
16
namespace TMVA {
13
17
namespace Experimental {
14
18
namespace SOFIE {
@@ -717,25 +721,18 @@ namespace {
717
721
718
722
std::string createOutputTensor (RModel const &rmodel, std::string const &name, bool isIntermediateTensor)
719
723
{
720
- if (name.empty ()) return " {}" ;
724
+ if (name.empty ())
725
+ return " {}" ;
721
726
ETensorType eOutputType = rmodel.GetTensorType (name);
727
+ // The std::vector<bool> is a special type that is not wrapping continuous memory.
728
+ // We don't want to use it as a return type.
722
729
std::string outputType = ConvertTypeToString (eOutputType);
723
- if (isIntermediateTensor) {
724
-
725
- if (eOutputType == ETensorType::BOOL) {
726
- return " fTensor_" + name;
727
- } else {
728
- // need to check is size is the same(don't want to return a vector with larger size)
729
- // in that case better to copy
730
- return " std::vector<" + ConvertTypeToString (eOutputType) + " >(tensor_" + name + " , tensor_" + name + " + " +
731
- std::to_string (ConvertShapeToLength (rmodel.GetTensorShape (name))) + " )" ;
732
- }
733
- }
734
- // include also dynamic tensors since the vectors can be allocated with a size larger than their output
735
- // we need a special handling for bool type allocated as vector<bool>
736
- auto outputLength = ConvertDynamicShapeToLength (rmodel.GetDynamicTensorShape (name));
737
- if (rmodel.IsDynamicTensor (name) && eOutputType == ETensorType::BOOL) {
738
- return " std::vector<bool>(fTensor_" + name + " .begin(), fTensor_" + name + " .begin() + " + outputLength + " )" ;
730
+ auto outputLength = isIntermediateTensor ? std::to_string (ConvertShapeToLength (rmodel.GetTensorShape (name)))
731
+ : ConvertDynamicShapeToLength (rmodel.GetDynamicTensorShape (name));
732
+ // need to check is size is the same(don't want to return a vector with
733
+ // larger size) in that case better to copy
734
+ if (eOutputType == ETensorType::BOOL) {
735
+ return " std::vector<unsigned char>(fTensor_" + name + " .begin(), fTensor_" + name + " .begin() + " + outputLength + " )" ;
739
736
}
740
737
return " std::vector<" + outputType + " >(tensor_" + name + " , tensor_" + name + " + " + outputLength + " )" ;
741
738
}
@@ -755,7 +752,9 @@ void RModel::GenerateOutput() {
755
752
bool sameOutputTypes = true ;
756
753
std::string inferReturnType; // type return by infer function
757
754
ETensorType eOutputType = GetTensorType (*fOutputTensorNames .begin ());
758
- std::string outputType = ConvertTypeToString (eOutputType);
755
+ // The std::vector<bool> is a special type that is not wrapping continuous memory.
756
+ // We don't want to use it as a return type.
757
+ std::string outputType = eOutputType != ETensorType::BOOL ? ConvertTypeToString (eOutputType) : " unsigned char" ;
759
758
fGC += " \n\n " ;
760
759
if (outputSize == 1 ) {
761
760
fGC += " std::vector<" + outputType + " >" ;
0 commit comments