Is there any way to compute the finite series
$S_M = \sum_{n=1}^{M} r^{n^2}, $
for some real $r$, integer $M$?