コード例 #1
0
ファイル: interface.py プロジェクト: trigrass2/nengo-loihi
    def __init__(self, block_info, inputs, dt):
        self.dt = dt

        self.probes = OrderedDict()
        for block in block_info.blocks:
            for probe in block.probes:
                self.probes[probe] = block_info.slices[block]

        self.filters = {}
        self.filter_pos = {}
        for probe, sl in self.probes.items():
            if probe.synapse is not None:
                if probe.weights is None or is_number(probe.weights):
                    size = sl.stop - sl.start
                else:
                    assert is_array(probe.weights) and probe.weights.ndim == 2
                    size = probe.weights.shape[1]
                self.filters[probe] = probe.synapse.make_step(
                    shape_in=(size, ),
                    shape_out=(size, ),
                    dt=self.dt,
                    rng=None,
                    dtype=np.float32,
                )
                self.filter_pos[probe] = 0

        self.outputs = defaultdict(list)
コード例 #2
0
 def checked(inst, other):
     if self.conversion is not None:
         other = self.conversion(other)
     if is_array(other):
         raise TypeError("Bare array not allowed in SPA operation.")
     elif not isinstance(other, self.expected_type):
         return NotImplemented
     return fn(inst, other)
コード例 #3
0
ファイル: sermo.py プロジェクト: tbekolay/phd
 def audio(self, audio_):
     if is_string(audio_):
         # Assuming this is a wav file
         audio_, fs = sf.read(audio_)
         self.fs = fs
     assert is_array(audio_)
     if audio_.ndim == 1:
         audio_ = audio_[:, np.newaxis]
     self.mfcc.audio = audio_
     self.periphery.sound_process = ArrayProcess(audio_)
コード例 #4
0
ファイル: sermo.py プロジェクト: jamboshell/phd
 def audio(self, audio_):
     if is_string(audio_):
         # Assuming this is a wav file
         audio_, fs = sf.read(audio_)
         self.fs = fs
     assert is_array(audio_)
     if audio_.ndim == 1:
         audio_ = audio_[:, np.newaxis]
     self.mfcc.audio = audio_
     self.periphery.sound_process = ArrayProcess(audio_)
コード例 #5
0
 def _mul(self, other, swap=False):
     if is_array(other):
         raise TypeError(
             "Multiplication of Semantic Pointers with arrays in not "
             "allowed.")
     elif is_number(other):
         return SemanticPointer(data=self.v * other,
                                vocab=self.vocab,
                                algebra=self.algebra,
                                name=self._get_binary_name(
                                    other, "*", swap))
     elif isinstance(other, Fixed):
         if other.type == TScalar:
             return SemanticPointer(data=self.v * other.evaluate(),
                                    vocab=self.vocab,
                                    algebra=self.algebra,
                                    name=self._get_binary_name(
                                        other, "*", swap))
         else:
             return self._bind(other, swap=swap)
     else:
         return NotImplemented
コード例 #6
0
ファイル: params.py プロジェクト: jmdelahanty/nengo
    def coerce(self, instance, num):
        if num is not None:
            if is_array(num) and num.shape == ():
                num = num.item()  # convert scalar array to Python object

            if not is_number(num):
                raise ValidationError("Must be a number; got '%s'" % num,
                                      attr=self.name, obj=instance)
            low_comp = 0 if self.low_open else -1
            if self.low is not None and compare(num, self.low) <= low_comp:
                raise ValidationError(
                    "Value must be greater than %s%s (got %s)" % (
                        "" if self.low_open else "or equal to ",
                        self.low,
                        num), attr=self.name, obj=instance)
            high_comp = 0 if self.high_open else 1
            if self.high is not None and compare(num, self.high) >= high_comp:
                raise ValidationError(
                    "Value must be less than %s%s (got %s)" % (
                        "" if self.high_open else "or equal to ",
                        self.high,
                        num), attr=self.name, obj=instance)
        return super(NumberParam, self).coerce(instance, num)
コード例 #7
0
ファイル: params.py プロジェクト: shaunren/nengo
 def __set__(self, instance, value):
     if is_array(value) and value.shape == ():
         value = value.item()  # convert scalar array to Python object
     super(NumberParam, self).__set__(instance, value)
コード例 #8
0
ファイル: params.py プロジェクト: thingimon/nengo
 def __set__(self, instance, value):
     if is_array(value) and value.shape == ():
         value = value.item()  # convert scalar array to Python object
     super(NumberParam, self).__set__(instance, value)
コード例 #9
0
 def send(self, data):
     assert is_array(data)
     self.ws.write_binary(data.tobytes())