Thanks much for the reply! I understand that forming the tensor K might have caused the issue. However my cost function involves matrix operations (such as the one I have mentioned, ie., (c_transpose * K * c), where K is composed of the 2 element parameter I want to optimize). Any suggestion how to circumvent that? TIA!