You cannot use lambda like that. The object will not pickle. I'd rather just use inheritance instead. 

Also, I'd rather not create a separate function for the dense and sparse cases. It prevents you from sharing computations and in many cases a few if statements here and there suffice.