M2 icon indicating copy to clipboard operation
M2 copied to clipboard

submatrix keeps hash unchanged

Open mahrud opened this issue 6 years ago • 3 comments
trafficstars

Despite the fact that submatrix makes a copy of mutable matrices, hash of the two objects stays the same.

i1 : A = mutableMatrix {{10}}
o1 = | 10 |
o1 : MutableMatrix

i2 : B = submatrix(A,{0},{0})
o2 = | 10 |
o2 : MutableMatrix

i3 : A_(0,0) = 11
o3 = 11

i4 : B_(0,0) = 12
o4 = 12

i5 : A
o5 = | 11 |
o5 : MutableMatrix

i6 : B
o6 = | 12 |
o6 : MutableMatrix

i7 : hash A == hash B
o7 = true

i8 : hash A
o8 = 1527355229

mahrud avatar Sep 04 '19 04:09 mahrud

It should be easy to make the submatrix routine produce a new hash code, the next one in the sequence. It's probably doing a low-level copy operation that simply copies the hash code, too.

DanGrayson avatar Sep 04 '19 15:09 DanGrayson

Does hash also depend on the location of the object in ram?

I wanted to use it to distinguish pointers to the same object. Is there a way to do that? (I understand that the location of an object can change, but it can be used to detect when two mutable objects are pointing to the same location)

mahrud avatar Sep 04 '19 15:09 mahrud

Does hash also depend on the location of the object in ram?

No. One design principle used is that Macaulay2 should give the same answers on all machines.

I wanted to use it to distinguish pointers to the same object. Is there a way to do that? (I understand that the location of an object can change, but it can be used to detect when two mutable objects are pointing to the same location)

No, there is no way to do that. It doesn't make much sense to want that either -- pointers to the same object have exactly the same behavior, and it's the object they point to that is what's important for us.

DanGrayson avatar Sep 04 '19 15:09 DanGrayson