@@ -66,15 +66,17 @@ def test_order_components_by_energy_descending():
6666 scales = np .array ([0.01 , 10.0 , 1.0 , 5.0 ])
6767 A = A * scales
6868 expected_energy_order = np .argsort (
69- np .linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
69+ np .abs ( weights ) * np . linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
7070 )[::- 1 ]
7171
7272 adata = _mock_adata (A .copy (), B .copy (), C .copy (), weights .copy (), projections )
7373 ordered = order_components_by_energy (adata )
7474
75- new_energy = np .linalg .norm (
76- np .array (ordered .uns ["Pf2_A" ]), axis = 0
77- ) * np .linalg .norm (np .array (ordered .varm ["Pf2_C" ]), axis = 0 )
75+ new_energy = (
76+ np .abs (np .array (ordered .uns ["Pf2_weights" ]))
77+ * np .linalg .norm (np .array (ordered .uns ["Pf2_A" ]), axis = 0 )
78+ * np .linalg .norm (np .array (ordered .varm ["Pf2_C" ]), axis = 0 )
79+ )
7880 assert np .all (np .diff (new_energy ) <= 1e-8 )
7981
8082 # Check that the columns were permuted as expected (up to sign).
@@ -109,7 +111,7 @@ def test_order_components_by_energy_preserves_reconstruction():
109111
110112 # Column r of after_wp, weighted by A/C for that component, should match
111113 # some permuted (and consistently signed) column of before_wp.
112- energy = np .linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
114+ energy = np .abs ( weights ) * np . linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
113115 order = np .argsort (energy )[::- 1 ]
114116
115117 # B itself is left as the unflipped sign reference, so weighted_projections
@@ -128,7 +130,7 @@ def test_order_components_by_energy_reorders_weights_and_B():
128130 weights = np .arange (rank , dtype = float )
129131 projections , _ = np .linalg .qr (rng .normal (size = (n_cells , rank )))
130132
131- energy = np .linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
133+ energy = np .abs ( weights ) * np . linalg .norm (A , axis = 0 ) * np .linalg .norm (C , axis = 0 )
132134 order = np .argsort (energy )[::- 1 ]
133135
134136 adata = _mock_adata (A .copy (), B .copy (), C .copy (), weights .copy (), projections )
0 commit comments