Skip to content

Commit

Permalink
Merge fa258f3 into 450b910
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed May 29, 2021
2 parents 450b910 + fa258f3 commit 011536b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qupulse/_program/waveforms.py
Expand Up @@ -342,7 +342,10 @@ def unsafe_sample(self,
output_array: Union[np.ndarray, None] = None) -> np.ndarray:
evaluated = self._expression.evaluate_numeric(t=sample_times)
if output_array is None:
return evaluated.astype(float)
if self._expression.variables:
return evaluated.astype(float)
else:
return np.full_like(sample_times, fill_value=float(evaluated), dtype=float)
else:
output_array[:] = evaluated
return output_array
Expand Down
13 changes: 13 additions & 0 deletions tests/pulses/function_pulse_tests.py
Expand Up @@ -250,6 +250,19 @@ def test_unsafe_sample(self):
np.testing.assert_equal(result, expected_result)
self.assertIs(result, out_array)

def test_constant_evaluation(self):
# cause for 596
fw = FunctionWaveform(Expression(3), 5, channel='A')
t = np.linspace(0, 5, dtype=float)
expected_result = np.full_like(t, fill_value=3.)
out_array = np.full_like(t, fill_value=np.nan)
result = fw.unsafe_sample(channel='A', sample_times=t, output_array=out_array)
self.assertIs(result, out_array)
np.testing.assert_equal(result, expected_result)

result = fw.unsafe_sample(channel='A', sample_times=t)
np.testing.assert_equal(result, expected_result)

def test_unsafe_get_subset_for_channels(self):
fw = FunctionWaveform(Expression('sin(2*pi*t) + 3'), 5, channel='A')
self.assertIs(fw.unsafe_get_subset_for_channels({'A'}), fw)
Expand Down

0 comments on commit 011536b

Please sign in to comment.