  For a $P$-indexed persistence module ${\sf M}$, the (generalized) rank of
${\sf M}$ is defined as the rank of the limit-to-colimit map for the diagram of
vector spaces of ${\sf M}$ over the poset $P$. For $2$-parameter persistence
modules, recently a zigzag persistence based algorithm has been proposed that
takes advantage of the fact that generalized rank for $2$-parameter modules is
equal to the number of full intervals in a zigzag module defined on the
boundary of the poset. Analogous definition of boundary for $d$-parameter
persistence modules or general $P$-indexed persistence modules does not seem
plausible. To overcome this difficulty, we first unfold a given $P$-indexed
module ${\sf M}$ into a zigzag module ${\sf M}_{ZZ}$ and then check how many
full interval modules in a decomposition of ${\sf M}_{ZZ}$ can be folded back
to remain full in a decomposition of ${\sf M}$. This number determines the
generalized rank of ${\sf M}$. For special cases of degree-$d$ homology for
$d$-complexes, we obtain a more efficient algorithm including a linear time
algorithm for degree-$1$ homology in graphs.
