This causes the problem: You let eigen handle the matrix.
Instead, allocate a shogun matrix SGMatrix<float64_t> S(dim, N) and then fill with randn.
Then use eigen's Map