BTW, I can write a scalable methods to achieve by using block matrix. (chopping the mu and sigma2 vector into sub small vectors)
Of course, this is a trade-off between time complexity and space complexity.
Let me know if you think this is a good idea. Currently I just follow the Matlab code.