Skip to content

Commit

Permalink
fix smalln test and long standing weirdness with particle links
Browse files Browse the repository at this point in the history
underlying problem with the acceptance of None or Ellipsis as indices
  • Loading branch information
ipelupessy committed Oct 16, 2019
1 parent 9684fd2 commit 368b2d4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/amuse/datamodel/incode_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@

from amuse.rfi.async_request import ASyncRequestSequence, PoolDependentASyncRequest

try:
from types import EllipsisType
except:
EllipsisType = type(Ellipsis)

class ParticleMappingMethod(AbstractCodeMethodWrapper):
def __init__(self, method, attribute_names = None):
AbstractCodeMethodWrapper.__init__(self, method)
Expand Down Expand Up @@ -898,7 +903,7 @@ def get_value_of(self, index, attribute):

def get_values_in_store(self, indices_in_the_code, attributes):

if indices_in_the_code is None:
if indices_in_the_code is None or isinstance(indices_in_the_code, EllipsisType):
indices_in_the_code = self.code_indices

if len(indices_in_the_code) == 0:
Expand Down
3 changes: 3 additions & 0 deletions src/amuse/io/store_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def get_values(self, indices):
linked_set = self.loader.load_particles_from_group(referenced_group)
else:
linked_set = mapping_from_groupid_to_set[referenced_group.id]

if indices is None:
indices=slice(None)

keys = self.keys[:][indices]
mask = self.masked[:][indices]
Expand Down
2 changes: 2 additions & 0 deletions src/amuse/io/store_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def __init__(self, name, group, loader):
self.loader = loader

def get_values(self, indices):
if indices is None:
indices=slice(None)
kinds = self.kind_dataset[:][indices]
references = self.ref_dataset[:][indices]
keys = self.keys_dataset[:][indices]
Expand Down
24 changes: 22 additions & 2 deletions test/core_tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ def test15(self):

def test16(self):
import h5py
print h5py.version.version
print h5py
#~ print h5py.version.version
#~ print h5py
test_results_path = self.get_path_to_results()
output_file = os.path.join(test_results_path, "test16"+self.store_version()+".hdf5")
if os.path.exists(output_file):
Expand Down Expand Up @@ -758,6 +758,24 @@ def test30(self):

self.assertEquals(output.new_attribute, 2 * output.mass)

def test31(self):
test_results_path = self.get_path_to_results()
output_file = os.path.join(test_results_path, "test31"+self.store_version()+".h5")
if os.path.exists(output_file):
os.remove(output_file)

p=Particles(10)
p.mass=numpy.arange(10)
q=Particles(3)
q[0].link=p[1]
q[1].link=p[3]
q[2].link=p[4]
io.write_set_to_file(q,output_file,"amuse",version=self.store_version())
r=io.read_set_from_file(output_file,"amuse")
self.assertEqual(len(r.link.shape),1)
self.assertEqual(r[0].link.mass,1)
self.assertEqual(r[1].link.mass,3)
self.assertEqual(r[2].link.mass,4)



Expand Down Expand Up @@ -1064,3 +1082,5 @@ def test61(self):

os.remove(output_file)



0 comments on commit 368b2d4

Please sign in to comment.