Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnkitAggarwalPEC/7b13e51952f89ac826ea240d0e44b610 to your computer and use it in GitHub Desktop.
Save AnkitAggarwalPEC/7b13e51952f89ac826ea240d0e44b610 to your computer and use it in GitHub Desktop.
class PrimitiveArrayCast{
public:
static Status SafeCast(const PrimitiveArray& input , const std::shared_ptr<DataType> & target_type, MemoryPool * pool , std::shared_ptr <PrimitiveArray> * out){
//! Check if types are equal
if(input.type()->Equals(target_type)){
//! We can simply reinterpret
//!! Cannot Call Set Data as it is decalred as protected
out->get()->SetData(input.data()) ;
}
else{
//! New memory has to be allocated
std::unique_ptr <ArrayBuilder> * builder;
MakeBuilder(pool, target_type , builder);
//! Append Cannot be called as it is not decalared
builder->Append(input.raw_values(),input.length(),nullptr);
builder->Finish(out->get());
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment