|
2 | 2 | import numpy as np
|
3 | 3 | from diffpy.snmf.containers import ComponentSignal
|
4 | 4 | from diffpy.snmf.subroutines import objective_function, get_stretched_component, reconstruct_data, get_residual_matrix, \
|
5 |
| - update_weights_matrix, initialize_arrays, lift_data, initialize_components, construct_stretching_matrix, construct_component_matrix |
| 5 | + update_weights_matrix, initialize_arrays, lift_data, initialize_components, construct_stretching_matrix, construct_component_matrix, construct_weight_matrix |
6 | 6 |
|
7 | 7 | to = [
|
8 | 8 | ([[[1, 2], [3, 4]], [[5, 6], [7, 8]], 1e11, [[1, 2], [3, 4]], [[1, 2], [3, 4]], 1], 2.574e14),
|
@@ -206,3 +206,22 @@ def test_construct_component_matrix(tccm):
|
206 | 206 | actual = construct_component_matrix(tccm)
|
207 | 207 | for component in tccm:
|
208 | 208 | np.testing.assert_allclose(actual[component.id], component.iq)
|
| 209 | + |
| 210 | +tcwm = [ |
| 211 | + ([ComponentSignal([0,.25,.5,.75,1],20,0)]), |
| 212 | + # ([ComponentSignal([0,.25,.5,.75,1],0,0)]), # 0 signal length. Failure expected |
| 213 | + ([ComponentSignal([0,.25,.5,.75,1],20,0),ComponentSignal([0,.25,.5,.75,1],20,1),ComponentSignal([0,.25,.5,.75,1],20,2)]), |
| 214 | + ([ComponentSignal([0, .25, .5, .75, 1], 20, 0), ComponentSignal([0, .25, .5, .75, 1], 20, 1), |
| 215 | + ComponentSignal([0, .25, .5, .75, 1], 20, 2)]), |
| 216 | + ([ComponentSignal([0, .25, .5, .75, 1], 20, 0), ComponentSignal([0, .25, .5, 2.75, 1], 20, 1), |
| 217 | + ComponentSignal([0, .25, .5, .75, 1], 20, 2)]), |
| 218 | + ([ComponentSignal([.25], 20, 0), ComponentSignal([.25], 20, 1), ComponentSignal([.25], 20, 2)]), |
| 219 | + ([ComponentSignal([0, .25, .5, .75, 1], 20, 0), ComponentSignal([0, .25, .5, .75, 1], 20, 1)]), |
| 220 | + #(ComponentSignal([], 20, 0)), # Expected to fail |
| 221 | + #([]), #Expected to fail |
| 222 | +] |
| 223 | +@pytest.mark.parametrize('tcwm',tcwm) |
| 224 | +def test_construct_weight_matrix(tcwm): |
| 225 | + actual = construct_weight_matrix(tcwm) |
| 226 | + for component in tcwm: |
| 227 | + np.testing.assert_allclose(actual[component.id], component.weights) |
0 commit comments