keras-team/keras

ops.copy makes object (arrays only?) immutable

Mrutyunjay01 opened this issue · 1 comments

Issue:

When trying to overwrite an object after making a copy using ops.copy, it makes the object immutable. Even after explicitly converting to numpy using ops.convert_to_numpy, the copied object remains immutable.

How to Reproduce:

import numpy as np
from keras import ops

arr = np.arange(10)
ops_arr = ops.copy(arr)

print(type(ops_arr)) # now it's EagerTensor

ops_arr_np = ops.convert_to_numpy(ops_arr)
print(ops_arr_np) # of type ndarray

ops_arr_np[0] = 10

And the error that follows:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
# in <cell line: 9>()
      7 print(ops_arr_np) # of type ndarray
      8 
----> 9 ops_arr_np[0] = 10

ValueError: assignment destination is read-only

Thanks for the report, this is now fixed at HEAD.