Exemple #1
0
    def set_initial_value(self, variable, value, selector=None):
        (key, parameter) = self._get_init_key_and_parameter(variable)

        full = getattr(self._neuron_model, parameter)
        if isinstance(full, AbstractList):
            ranged_list = full
        else:
            # Keep all the setting stuff in one place by creating a RangedList
            ranged_list = SpynnakerRangedList(size=self.n_atoms, value=full)
            # Now that we have created a RangedList why not use it.
            self.initialize(key, ranged_list)

        ranged_list.set_value_by_selector(selector, value)
 def __copy_ranged_dict(source, merge=None, merge_keys=None):
     target = SpynnakerRangeDictionary(len(source))
     for key in source.keys():
         copy_list = SpynnakerRangedList(len(source))
         if merge_keys is None or key not in merge_keys:
             init_list = source.get_list(key)
         else:
             init_list = merge.get_list(key)
         for start, stop, value in init_list.iter_ranges():
             is_list = (hasattr(value, '__iter__')
                        and not isinstance(value, str))
             copy_list.set_value_by_slice(start, stop, value, is_list)
         target[key] = copy_list
     return target
Exemple #3
0
def range_list_as_list(spec):
    value = SpynnakerRangedList(size=10, value=_generator(10), key="test")
    param = NeuronParameter(value, DataType.S1615)
    iterator = param.iterator_by_slice(0, 5, spec)
    values = _iterate_parameter_values(iterator, DataType.S1615)
    assert list(value[0:5]) == values
    assert isinstance(iterator, _Range_Iterator)
Exemple #4
0
    def set_value_by_selector(self, selector, key, value):
        """ Sets the value for a particular key but only for the selected \
            subset.

        :param selector: See RangedList.set_value_by_selector as this is just\
            a pass through method
        :param key: the name of the parameter to change
        :param value: the new value of the parameter to assign
        """
        old_values = self.get_value(key)
        if isinstance(old_values, AbstractList):
            ranged_list = old_values
        else:
            # Keep all the setting stuff in one place by creating a RangedList
            ranged_list = SpynnakerRangedList(
                size=self.n_atoms, value=old_values)
            self.set_value(key, ranged_list)
        ranged_list.set_value_by_selector(selector, value)
    def set_value_by_selector(self, selector, key, value):
        """ Sets the value for a particular key but only for the selected \
            subset.

        :param selector: See \
            :py:class:`~spinn_utilities.ranged.RangedList`.set_value_by_selector\
            as this is just a pass through method
        :type selector: None or slice or int or list(bool) or list(int)
        :param str key: the name of the parameter to change
        :param value: the new value of the parameter to assign
        :type value: float or int or list(float) or list(int)
        """
        old_values = self.get_value(key)
        if isinstance(old_values, AbstractList):
            ranged_list = old_values
        else:
            # Keep all the setting stuff in one place by creating a RangedList
            ranged_list = SpynnakerRangedList(size=self.n_atoms,
                                              value=old_values)
            self.set_value(key, ranged_list)
        ranged_list.set_value_by_selector(selector, value)
    def get_value_by_selector(self, selector, key):
        """ Gets the value for a particular key but only for the selected\
            subset.

        :param selector: See \
            :py:meth:`~spinn_utilities.ranged.RangedList.get_value_by_selector`\
            as this is just a pass through method
        :type selector: None or slice or int or list(bool) or list(int)
        :param str key: the name of the parameter to change
        :rtype: list(float or int)
        """
        old_values = self.get_value(key)
        if isinstance(old_values, AbstractList):
            ranged_list = old_values
        else:
            # Keep all the getting stuff in one place by creating a RangedList
            ranged_list = SpynnakerRangedList(size=self.n_atoms,
                                              value=old_values)
            # Now that we have created a RangedList why not use it.
            self.set_value(key, ranged_list)
        return ranged_list.get_values(selector)
Exemple #7
0
def test_range_list_as_list():
    MockSimulator.setup()

    spec_writer = FileDataWriter("test.dat")
    spec = DataSpecificationGenerator(spec_writer, None)
    try:
        value = SpynnakerRangedList(size=10, value=_generator(10), key="test")
        param = NeuronParameter(value, DataType.S1615)
        iterator = param.iterator_by_slice(0, 5, spec)
        values = _iterate_parameter_values(iterator, DataType.S1615)
        assert list(value[0:5]) == values
        assert isinstance(iterator, _Range_Iterator)
    finally:
        spec.end_specification()
        os.remove("test.dat")