示例#1
0
    def get_indices_of(self, keys):
        if keys is None:
            return self.index_array

        if len(self.particle_keys) == 0:
            return ()

        indices = numpy.searchsorted(self.sorted_keys, keys)
        indices = numpy.where(indices >= len(self.sorted_keys), 0, indices)
        foundkeys = self.sorted_keys[indices]
        are_found = foundkeys == keys
        are_all_found = numpy.all(are_found)
        if not are_all_found:
            arrayedkeys = numpy.asarray(keys)
            notfoundkeys = arrayedkeys[numpy.logical_not(are_found)]
            raise exceptions.KeysNotInStorageException(
                arrayedkeys[are_found],
                self.sorted_indices[indices[are_found]], notfoundkeys)
        return self.sorted_indices[indices]
示例#2
0
    def get_indices_of(self, particles):
        if particles is None:
            return numpy.arange(0, len(self.particle_keys))

        mapping_from_particle_to_index = self.mapping_from_particle_to_index
        result = []
        notfoundkeys = []
        foundkeys = []
        for index, particle_key in enumerate(particles):
            try:
                result.append(mapping_from_particle_to_index[particle_key])
                foundkeys.append(particle_key)
            except KeyError:
                notfoundkeys.append(particle_key)

        if not len(notfoundkeys) == 0:
            raise exceptions.KeysNotInStorageException(
                numpy.asarray(foundkeys), numpy.asarray(result),
                numpy.asarray(notfoundkeys))
        return numpy.asarray(result)
示例#3
0
    def lookup(self, inkeys):
        N = len(inkeys)
        keys = numpy.ascontiguousarray(inkeys, dtype="uintp")

        values = numpy.ascontiguousarray(numpy.zeros(N), dtype="uintp")
        errors = numpy.ascontiguousarray(numpy.zeros(N), dtype="int32")
        ckeys = keys.ctypes.data_as(c_size_t_pointer)
        cvalues = values.ctypes.data_as(c_size_t_pointer)
        cerrors = errors.ctypes.data_as(c_int_pointer)
        with self.lock:
            err = self._lib.hash_lookups(self._map_ref, N, ckeys, cvalues,
                                         cerrors)
        if err != 0:
            has_errors = errors != 0
            missing_keys = keys[has_errors]
            no_errors = ~has_errors
            raise exceptions.KeysNotInStorageException(keys[no_errors],
                                                       values[no_errors],
                                                       missing_keys)
        return values
示例#4
0
 def get_indices_of(self, keys):
     indices_in_the_code = []
     if keys is None:
         keys = self.particle_keys
     
     notfoundkeys = []
     foundkeys = []
     for particle_key in keys:
         try:
             indices_in_the_code.append(self.mapping_from_particle_key_to_index_in_the_code[particle_key])
             foundkeys.append(particle_key)
         except KeyError:
             notfoundkeys.append(particle_key)
       
     if not len(notfoundkeys) == 0:
         raise exceptions.KeysNotInStorageException(
             numpy.asarray(foundkeys), 
             numpy.asarray(indices_in_the_code), 
             numpy.asarray(notfoundkeys)
         )
     
     return numpy.asarray(indices_in_the_code)