@@ -44,17 +44,6 @@ class WhiteNoise(Block):
4444 random seed for reproducibility
4545 """
4646
47- def to_checkpoint (self , prefix , recordings = False ):
48- """Serialize WhiteNoise state including current sample."""
49- json_data , npz_data = super ().to_checkpoint (prefix , recordings = recordings )
50- json_data ["_current_sample" ] = float (self ._current_sample )
51- return json_data , npz_data
52-
53- def load_checkpoint (self , prefix , json_data , npz ):
54- """Restore WhiteNoise state including current sample."""
55- super ().load_checkpoint (prefix , json_data , npz )
56- self ._current_sample = json_data .get ("_current_sample" , 0.0 )
57-
5847 input_port_labels = {}
5948 output_port_labels = {"out" : 0 }
6049
@@ -135,6 +124,19 @@ def update(self, t):
135124 pass
136125
137126
127+ def to_checkpoint (self , prefix , recordings = False ):
128+ """Serialize WhiteNoise state including current sample."""
129+ json_data , npz_data = super ().to_checkpoint (prefix , recordings = recordings )
130+ json_data ["_current_sample" ] = float (self ._current_sample )
131+ return json_data , npz_data
132+
133+
134+ def load_checkpoint (self , prefix , json_data , npz ):
135+ """Restore WhiteNoise state including current sample."""
136+ super ().load_checkpoint (prefix , json_data , npz )
137+ self ._current_sample = json_data .get ("_current_sample" , 0.0 )
138+
139+
138140class PinkNoise (Block ):
139141 """Pink noise (1/f noise) source using the Voss-McCartney algorithm.
140142
@@ -167,22 +169,6 @@ class PinkNoise(Block):
167169 random seed for reproducibility
168170 """
169171
170- def to_checkpoint (self , prefix , recordings = False ):
171- """Serialize PinkNoise state including algorithm state."""
172- json_data , npz_data = super ().to_checkpoint (prefix , recordings = recordings )
173- json_data ["n_samples" ] = self .n_samples
174- json_data ["_current_sample" ] = float (self ._current_sample )
175- npz_data [f"{ prefix } /octave_values" ] = self .octave_values
176- return json_data , npz_data
177-
178- def load_checkpoint (self , prefix , json_data , npz ):
179- """Restore PinkNoise state including algorithm state."""
180- super ().load_checkpoint (prefix , json_data , npz )
181- self .n_samples = json_data .get ("n_samples" , 0 )
182- self ._current_sample = json_data .get ("_current_sample" , 0.0 )
183- if f"{ prefix } /octave_values" in npz :
184- self .octave_values = npz [f"{ prefix } /octave_values" ]
185-
186172 input_port_labels = {}
187173 output_port_labels = {"out" : 0 }
188174
@@ -295,4 +281,22 @@ def sample(self, t, dt):
295281
296282
297283 def update (self , t ):
298- pass
284+ pass
285+
286+
287+ def to_checkpoint (self , prefix , recordings = False ):
288+ """Serialize PinkNoise state including algorithm state."""
289+ json_data , npz_data = super ().to_checkpoint (prefix , recordings = recordings )
290+ json_data ["n_samples" ] = self .n_samples
291+ json_data ["_current_sample" ] = float (self ._current_sample )
292+ npz_data [f"{ prefix } /octave_values" ] = self .octave_values
293+ return json_data , npz_data
294+
295+
296+ def load_checkpoint (self , prefix , json_data , npz ):
297+ """Restore PinkNoise state including algorithm state."""
298+ super ().load_checkpoint (prefix , json_data , npz )
299+ self .n_samples = json_data .get ("n_samples" , 0 )
300+ self ._current_sample = json_data .get ("_current_sample" , 0.0 )
301+ if f"{ prefix } /octave_values" in npz :
302+ self .octave_values = npz [f"{ prefix } /octave_values" ]
0 commit comments