quick fix for excessive memory allocation issue when input data is sparse