amuse icon indicating copy to clipboard operation
amuse copied to clipboard

particles attributes now return reference instead of copy

Open ipelupessy opened this issue 10 years ago • 4 comments

ce7207c5da1b25103eecda7104628b65646f8270 has changed p.x from returning a copy to returning a reference to data. This introduces different behaviour for in-memory sets and in-code sets, difference between grids and Particles, and issues with subsets:

p=Particles(5)

p.x=range(5) 
tmp=p.x
print tmp is p.x

#behaviour of index expressions
tmp=p[::2].x

p.x=p.x+1

print tmp == p[::2].x

tmp=p.x[::2]
p.x=p.x+1

print tmp == p[::2].x


# behaviour of grids
p=Grid(5)
p.x=range(5) | units.m
tmp=p.x
print tmp is p.x

gives on 4168ed99b8ccc163a5f9311722c6f28b7c1aeee4:

False
[False False False]
[False False False]
False

while on ce7207c5da1b25103eecda7104628b65646f8270:

True
[False False False]
[ True  True  True]
False

ipelupessy avatar Mar 07 '16 17:03 ipelupessy

Which of the two is the desired behaviour?

rieder avatar Mar 10 '17 07:03 rieder

for me consistency between in-memory and code sets is most important..

ipelupessy avatar Mar 10 '17 09:03 ipelupessy

still relevant

ipelupessy avatar Mar 12 '22 16:03 ipelupessy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 11 '22 17:05 stale[bot]