Bayesian inference via sparse Hamiltonian flows