make gradient optimizer get functions constant (to guarantee that the arrays are not modified)