Optimizing sparse computations jointly