Can allocation be optional for XGDMatrixCreateFromMat

My use case is latency sensitive and allocating in my prediction path is not an option. Looking at the C code for XGDMatrixCreateFromMat it appears it allocates with is surprising to me. Can we make allocation optional? Is there already a way to satisfy my use-case?

After digging a little deeper it appears we allocate at least 3 times. Interesting… Once for the shared_ptr? Once for the object the shared_ptr points to and an unknown number of times from constructing & populating a vector.

You can use in-place prediction via XGBoosterPredictFromDense(). Take a look at the example at https://github.com/dmlc/xgboost/blob/118192f11678aeaab510eaa725e815e4e706279e/demo/c-api/inference/inference.c#L172-L202

Hi,

I have tried to follow the example but haven’t been able to get it working. Here is my code along with the error message.

You need to first build the array interface, which is a JSON string. Take a look at Matrix_ArrayInterface() from the linked example.