@@ -160,24 +160,35 @@ def compute_nonzero_block_shapes(charges: List[np.ndarray],
160160 return charge_shape_dict
161161
162162
163- def retrieve_non_zero_diagonal_blocks_old_version (
163+ def retrieve_non_zero_diagonal_blocks (
164164 data : np .ndarray ,
165- charges : List [np .ndarray ],
166- flows : List [Union [bool , int ]],
165+ row_charges : List [Union [List , np .ndarray ]],
166+ column_charges : List [Union [List , np .ndarray ]],
167+ row_flows : List [Union [bool , int ]],
168+ column_flows : List [Union [bool , int ]],
167169 return_data : Optional [bool ] = True ) -> Dict :
168170 """
169- Deprecated: this version is about 2 times slower (worst case) than the current used
170- implementation
171171 Given the meta data and underlying data of a symmetric matrix, compute
172172 all diagonal blocks and return them in a dict.
173+ `row_charges` and `column_charges` are lists of np.ndarray. The tensor
174+ is viewed as a matrix with rows given by fusing `row_charges` and
175+ columns given by fusing `column_charges`. Note that `column_charges`
176+ are never explicitly fused (`row_charges` are).
173177 Args:
174178 data: An np.ndarray of the data. The number of elements in `data`
175179 has to match the number of non-zero elements defined by `charges`
176180 and `flows`
177- charges : List of np.ndarray, one for each leg.
178- Each np.ndarray `charges [leg]` is of shape `(D[leg],)`.
181+ row_charges : List of np.ndarray, one for each leg of the row-indices.
182+ Each np.ndarray `row_charges [leg]` is of shape `(D[leg],)`.
179183 The bond dimension `D[leg]` can vary on each leg.
180- flows: A list of integers, one for each leg,
184+ column_charges: List of np.ndarray, one for each leg of the column-indices.
185+ Each np.ndarray `row_charges[leg]` is of shape `(D[leg],)`.
186+ The bond dimension `D[leg]` can vary on each leg.
187+ row_flows: A list of integers, one for each entry in `row_charges`.
188+ with values `1` or `-1`, denoting the flow direction
189+ of the charges on each leg. `1` is inflowing, `-1` is outflowing
190+ charge.
191+ column_flows: A list of integers, one for each entry in `column_charges`.
181192 with values `1` or `-1`, denoting the flow direction
182193 of the charges on each leg. `1` is inflowing, `-1` is outflowing
183194 charge.
@@ -193,20 +204,25 @@ def retrieve_non_zero_diagonal_blocks_old_version(
193204 dict: Dictionary mapping quantum numbers (integers) to either an np.ndarray
194205 or a python list of locations and shapes, depending on the value of `return_data`.
195206 """
196- if len ( charges ) != 2 :
197- raise ValueError ( "input has to be a two-dimensional symmetric matrix" )
207+ flows = row_flows . copy ()
208+ flows . extend ( column_flows )
198209 check_flows (flows )
199- if len (flows ) != len (charges ):
200- raise ValueError ("`len(flows)` is different from `len(charges)`" )
210+ if len (flows ) != (len (row_charges ) + len (column_charges )):
211+ raise ValueError (
212+ "`len(flows)` is different from `len(row_charges) + len(column_charges)`"
213+ )
201214
202- #we multiply the flows into the charges
203- row_charges = flows [0 ] * charges [0 ] # a list of charges on each row
204- column_charges = flows [1 ] * charges [1 ] # a list of charges on each column
215+ #since we are using row-major we have to fuse the row charges anyway.
216+ fused_row_charges = fuse_charges (row_charges , row_flows )
217+ #get the unique row-charges
218+ unique_row_charges , row_dims = np .unique (
219+ fused_row_charges , return_counts = True )
205220
206- #get the unique charges
207- unique_row_charges , row_dims = np .unique (row_charges , return_counts = True )
208- unique_column_charges , column_dims = np .unique (
209- column_charges , return_counts = True )
221+ #get the unique column-charges
222+ #we only care about their degeneracies, not their order; that's much faster
223+ #to compute since we don't have to fuse all charges explicitly
224+ unique_column_charges , column_dims = compute_fused_charge_degeneracies (
225+ column_charges , column_flows )
210226 #get the charges common to rows and columns (only those matter)
211227 common_charges = np .intersect1d (
212228 unique_row_charges , - unique_column_charges , assume_unique = True )
@@ -217,8 +233,8 @@ def retrieve_non_zero_diagonal_blocks_old_version(
217233 column_degeneracies = dict (zip (unique_column_charges , column_dims ))
218234
219235 # we only care about charges common to row and columns
220- mask = np .isin (row_charges , common_charges )
221- relevant_row_charges = row_charges [mask ]
236+ mask = np .isin (fused_row_charges , common_charges )
237+ relevant_row_charges = fused_row_charges [mask ]
222238
223239 #some numpy magic to get the index locations of the blocks
224240 #we generate a vector of `len(relevant_row_charges) which,
@@ -261,35 +277,24 @@ def retrieve_non_zero_diagonal_blocks_old_version(
261277 return blocks
262278
263279
264- def retrieve_non_zero_diagonal_blocks (
280+ def retrieve_non_zero_diagonal_blocks_old_version (
265281 data : np .ndarray ,
266- row_charges : List [Union [List , np .ndarray ]],
267- column_charges : List [Union [List , np .ndarray ]],
268- row_flows : List [Union [bool , int ]],
269- column_flows : List [Union [bool , int ]],
282+ charges : List [np .ndarray ],
283+ flows : List [Union [bool , int ]],
270284 return_data : Optional [bool ] = True ) -> Dict :
271285 """
286+ Deprecated: this version is about 2 times slower (worst case) than the current used
287+ implementation
272288 Given the meta data and underlying data of a symmetric matrix, compute
273289 all diagonal blocks and return them in a dict.
274- `row_charges` and `column_charges` are lists of np.ndarray. The tensor
275- is viewed as a matrix with rows given by fusing `row_charges` and
276- columns given by fusing `column_charges`. Note that `column_charges`
277- are never explicitly fused (`row_charges` are).
278290 Args:
279291 data: An np.ndarray of the data. The number of elements in `data`
280292 has to match the number of non-zero elements defined by `charges`
281293 and `flows`
282- row_charges: List of np.ndarray, one for each leg of the row-indices.
283- Each np.ndarray `row_charges[leg]` is of shape `(D[leg],)`.
284- The bond dimension `D[leg]` can vary on each leg.
285- column_charges: List of np.ndarray, one for each leg of the column-indices.
286- Each np.ndarray `row_charges[leg]` is of shape `(D[leg],)`.
294+ charges: List of np.ndarray, one for each leg.
295+ Each np.ndarray `charges[leg]` is of shape `(D[leg],)`.
287296 The bond dimension `D[leg]` can vary on each leg.
288- row_flows: A list of integers, one for each entry in `row_charges`.
289- with values `1` or `-1`, denoting the flow direction
290- of the charges on each leg. `1` is inflowing, `-1` is outflowing
291- charge.
292- column_flows: A list of integers, one for each entry in `column_charges`.
297+ flows: A list of integers, one for each leg,
293298 with values `1` or `-1`, denoting the flow direction
294299 of the charges on each leg. `1` is inflowing, `-1` is outflowing
295300 charge.
@@ -305,25 +310,20 @@ def retrieve_non_zero_diagonal_blocks(
305310 dict: Dictionary mapping quantum numbers (integers) to either an np.ndarray
306311 or a python list of locations and shapes, depending on the value of `return_data`.
307312 """
308- flows = row_flows . copy ()
309- flows . extend ( column_flows )
313+ if len ( charges ) != 2 :
314+ raise ValueError ( "input has to be a two-dimensional symmetric matrix" )
310315 check_flows (flows )
311- if len (flows ) != (len (row_charges ) + len (column_charges )):
312- raise ValueError (
313- "`len(flows)` is different from `len(row_charges) + len(column_charges)`"
314- )
316+ if len (flows ) != len (charges ):
317+ raise ValueError ("`len(flows)` is different from `len(charges)`" )
315318
316- #since we are using row-major we have to fuse the row charges anyway.
317- fused_row_charges = fuse_charges (row_charges , row_flows )
318- #get the unique row-charges
319- unique_row_charges , row_dims = np .unique (
320- fused_row_charges , return_counts = True )
319+ #we multiply the flows into the charges
320+ row_charges = flows [0 ] * charges [0 ] # a list of charges on each row
321+ column_charges = flows [1 ] * charges [1 ] # a list of charges on each column
321322
322- #get the unique column-charges
323- #we only care about their degeneracies, not their order; that's much faster
324- #to compute since we don't have to fuse all charges explicitly
325- unique_column_charges , column_dims = compute_fused_charge_degeneracies (
326- column_charges , column_flows )
323+ #get the unique charges
324+ unique_row_charges , row_dims = np .unique (row_charges , return_counts = True )
325+ unique_column_charges , column_dims = np .unique (
326+ column_charges , return_counts = True )
327327 #get the charges common to rows and columns (only those matter)
328328 common_charges = np .intersect1d (
329329 unique_row_charges , - unique_column_charges , assume_unique = True )
@@ -334,8 +334,8 @@ def retrieve_non_zero_diagonal_blocks(
334334 column_degeneracies = dict (zip (unique_column_charges , column_dims ))
335335
336336 # we only care about charges common to row and columns
337- mask = np .isin (fused_row_charges , common_charges )
338- relevant_row_charges = fused_row_charges [mask ]
337+ mask = np .isin (row_charges , common_charges )
338+ relevant_row_charges = row_charges [mask ]
339339
340340 #some numpy magic to get the index locations of the blocks
341341 #we generate a vector of `len(relevant_row_charges) which,
@@ -585,8 +585,8 @@ def compute_mapping_table(charges: List[np.ndarray],
585585 # is moving quickest when iterating through the linear data
586586 # transposing is done taking, for each value of the indices i_0 to i_N-2
587587 # the junk i_N-1 that gives non-zero
588- tables = np . meshgrid ([ np . arange ( c . shape [ 0 ]) for c in charges ], indexing = 'ij' )
589- tables = tables [:: - 1 ] #reverse the order
588+
589+ #for example
590590 raise NotImplementedError ()
591591
592592
0 commit comments