Partition function of a finite Ising model on a torus