def reshape(self, shape):
        """
        Reshapes self to have the given shape. The number of elements cannot
        change as this only changes how the contents are interpreted.
        """
        m, n = shape
        mlen = self.shape[0] * self.shape[1]
        if m == -1:
          assert n > 0 and mlen % n == 0
          m = mlen / n
        elif n == -1:
          assert m > 0 and mlen % m == 0
          n = mlen / m

        err_code = _cudamat.reshape(self.p_mat, ct.c_uint(m), ct.c_uint(n))
        if err_code:
            raise generate_exception(err_code)

        return self

        Reshapes self to have the given shape. The number of elements cannot
        change as this only changes how the contents are interpreted.
        
cudamat/cudamat.py