Skip to content

Commit

Permalink
functions/MemoryFunction: Use np.asarray instead of asfarray
Browse files Browse the repository at this point in the history
Rely on numpy type detection and promotion instead of explicitly
converting to float64.

Signed-off-by: Jan Vesely <[email protected]>
  • Loading branch information
jvesely committed Jan 9, 2025
1 parent 9ffe61d commit c1effb2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions psyneulink/core/components/functions/stateful/memoryfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def _parse_selection_function_variable(self, variable, context=None, distance_re
distance_result = self.distance_function(self._parse_distance_function_variable(variable), context=context)
# TEST PRINT:
# print(distance_result, self.distance_function.defaults.value)
return np.asfarray([
return np.asarray([
distance_result if i == 0 else np.zeros_like(distance_result)
for i in range(self.defaults.max_entries)
])
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def _validate(self, context=None):

# Default to full memory
selection_function = self.selection_function
test_var = np.asfarray([
test_var = np.asarray([
distance_result if i == 0 else np.zeros_like(distance_result)
for i in range(self._get_current_parameter_value('max_entries', context))
])
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def _parse_selection_function_variable(self, variable, context=None):
distance_result = self.distance_function.parameters.value._get(context)
# TEST PRINT:
# print(distance_result, self.distance_function.defaults.value)
return np.asfarray([
return np.asarray([
distance_result if i == 0 else np.zeros_like(distance_result)
for i in range(self.defaults.max_entries)
])
Expand Down Expand Up @@ -2553,7 +2553,7 @@ def _validate(self, context=None):

# Default to full memory
selection_function = self.selection_function
test_var = np.asfarray([distance_result if i==0
test_var = np.asarray([distance_result if i==0
else np.zeros_like(distance_result)
for i in range(self._get_current_parameter_value('max_entries', context))])
if isinstance(selection_function, type):
Expand Down Expand Up @@ -2709,12 +2709,12 @@ def _function(self,
# Store variable to dict:
rate = self._get_current_parameter_value(RATE, context)
if rate is not None:
key = np.asfarray(key) * np.asfarray(rate)
key = np.asarray(key) * np.asarray(rate)
assert len(key) == len(variable[KEYS]), "{} vs. {}".format(key, variable[KEYS])

if noise is not None:
# TODO: does val need noise?
key = np.asfarray(key) + np.asfarray(noise)[KEYS]
key = np.asarray(key) + np.asarray(noise)[KEYS]
assert len(key) == len(variable[KEYS]), "{} vs. {}".format(key, variable[KEYS])

if storage_prob == 1.0 or (storage_prob > 0.0 and storage_prob > random_state.uniform()):
Expand Down

0 comments on commit c1effb2

Please sign in to comment.