@@ -135,3 +135,84 @@ def test_spectrum_moment_0d(backend_class_with_jax, skip_division_by_m0):
135135 actual = sum (actual if skip_division_by_m0 else actual * spectrum_moment_0 .to_ndarray ()),
136136 significant = 4 ,
137137 )
138+
139+
140+ @staticmethod
141+ @pytest .mark .parametrize ('skip_division_by_m0' , (True , False ))
142+ def test_spectrum_moment_0d_one_drop_outside_of_bins (backend_class_with_jax , skip_division_by_m0 ):
143+ # Arrange
144+ particulator = DummyParticulator (backend_class_with_jax , n_sd = 1 )
145+ attribute = {
146+ "multiplicity" : np .ones (1 ),
147+ "volume" : np .ones (1 ),
148+ }
149+ particulator .build (attribute )
150+
151+ v_bins = np .linspace (0 , .5 , num = 2 , endpoint = True )
152+
153+ assert len (v_bins ) == 2
154+ spectrum_moment_0 = particulator .backend .Storage .empty (
155+ (len (v_bins ) - 1 , 1 ), dtype = float
156+ )
157+ spectrum_moments = particulator .backend .Storage .empty (
158+ (len (v_bins ) - 1 , 1 ), dtype = float
159+ )
160+ v_bins_edges = particulator .backend .Storage .from_ndarray (v_bins )
161+
162+ # Act
163+ particulator .spectrum_moments (
164+ moment_0 = spectrum_moment_0 ,
165+ moments = spectrum_moments ,
166+ attr = "volume" ,
167+ attr_name = 'volume' ,
168+ rank = 1 ,
169+ attr_bins = v_bins_edges ,
170+ skip_division_by_m0 = skip_division_by_m0 ,
171+ )
172+
173+ # Assert
174+ assert spectrum_moment_0 .to_ndarray () == [0 ]
175+ assert spectrum_moments .to_ndarray () == [0 ]
176+
177+ @staticmethod
178+ def test_moment_1d (backend_class_with_jax ):
179+ # Arrange
180+ grid = (2 ,)
181+ particulator = DummyParticulator (
182+ backend_class_with_jax ,
183+ n_sd = 1 ,
184+ grid = grid
185+ )
186+
187+ attribute = {
188+ "multiplicity" : np .ones (1 ),
189+ "volume" : np .ones (1 ),
190+ "cell id" : np .ones (1 , dtype = int ),
191+ }
192+ particulator .build (attribute )
193+
194+ v_bins = np .linspace (0 , 2 , num = 2 , endpoint = True )
195+
196+ assert len (v_bins ) == 2
197+ spectrum_moment_0 = particulator .backend .Storage .empty (
198+ (len (v_bins ) - 1 , np .prod (grid )), dtype = float
199+ )
200+ spectrum_moments = particulator .backend .Storage .empty (
201+ (len (v_bins ) - 1 , np .prod (grid )), dtype = float
202+ )
203+ v_bins_edges = particulator .backend .Storage .from_ndarray (v_bins )
204+
205+ # Act
206+ particulator .spectrum_moments (
207+ moment_0 = spectrum_moment_0 ,
208+ moments = spectrum_moments ,
209+ attr = "volume" ,
210+ attr_name = 'volume' ,
211+ rank = 1 ,
212+ attr_bins = v_bins_edges ,
213+ skip_division_by_m0 = True ,
214+ )
215+
216+ # Assert
217+ assert np .prod (spectrum_moment_0 .to_ndarray () == [0 , 1 ])
218+ assert np .prod (spectrum_moments .to_ndarray () == [0 , 1 ])
0 commit comments