@@ -102,14 +102,14 @@ def __del__(self):
102102Correspond_dtype = np .dtype ([
103103 ('p1' , np .int32 ), # PT_UNUSED
104104 ('n' , np .int32 ), # 0
105- ('p2' , (np .float64 , MAXCAND )), # np.zeros
105+ ('p2' , (np .int32 , MAXCAND )), # np.zeros
106106 ('corr' , (np .float64 , MAXCAND )), # np.zeros
107107 ('dist' , (np .float64 , MAXCAND )) # np.zeros
108108])
109109
110110def safely_allocate_target_usage_marks (
111111 num_cams : int , nmax : int = NMAX
112- ) -> List [List [int ]]:
112+ ) -> np . ndarray : # num_cams x nmax instead of List[List[int]]:
113113 """Allocate space for per-camera arrays marking whether a certain target was used.
114114
115115 If some allocation failed, it cleans up memory and returns NULL. Allocated arrays are zeroed
@@ -123,39 +123,48 @@ def safely_allocate_target_usage_marks(
123123 -------
124124 A list of lists of integers, or `None` if an allocation failed.
125125 """
126- tusage = []
127- for cam in range (num_cams ):
128- tusage .append ([0 ] * nmax ) # Initialize the array to all zeros.
126+ # tusage = []
127+ # for cam in range(num_cams):
128+ # tusage.append([0] * nmax) # Initialize the array to all zeros.
129129
130- # Check if any of the allocations failed.
131- for cam in range (num_cams ):
132- if tusage [cam ] is None :
133- return [] # was None
130+ # # Check if any of the allocations failed.
131+ # for cam in range(num_cams):
132+ # if tusage[cam] is None:
133+ # return [] # was None
134134
135- return tusage
135+ return np . zeros (( num_cams , nmax ), dtype = np . int32 )
136136
137137def safely_allocate_adjacency_lists (
138138 num_cams : int , target_counts : List [int ]
139- ) -> List [ List [ List [ np .recarray ]]] :
139+ ) -> np .recarray :
140140 """Allocate space for the adjacency lists."""
141- one_element = np .array (
142- [(PT_UNUSED , 0 , np .zeros (MAXCAND ), np .zeros (MAXCAND ), np .zeros (MAXCAND ))],
143- dtype = Correspond_dtype ).view (np .recarray )
141+ # one_element = np.array(
142+ # [(PT_UNUSED, 0, np.zeros(MAXCAND), np.zeros(MAXCAND), np.zeros(MAXCAND))],
143+ # dtype=Correspond_dtype).view(np.recarray)
144144
145145 try :
146- lists = [
147- [[one_element for _ in range (target_counts [c1 ])] for _ in range (num_cams )]
148- for c1 in range (num_cams )
149- ]
146+ # lists = [
147+ # [[one_element for _ in range(target_counts[c1])] for _ in range(num_cams)]
148+ # for c1 in range(num_cams)
149+ # ]
150+
151+ lists = np .recarray ((num_cams , num_cams , max (target_counts )),dtype = Correspond_dtype )
152+
153+ except MemoryError as exc :
154+ raise MemoryError ("Failed to allocate adjacency lists." ) from exc
155+ # lists = [[[one_element]]]
156+
157+ lists .p1 = PT_UNUSED
158+ lists .n = 0
159+ lists .p2 = np .zeros (MAXCAND )
160+ lists .corr = np .zeros (MAXCAND )
161+ lists .dist = np .zeros (MAXCAND )
150162
151- except MemoryError :
152- print ("Memory allocation failed." )
153- lists = [[[one_element ]]]
154163
155164 return lists
156165
157166def four_camera_matching (
158- corr_list : List [ List [ List [ np .recarray ]]] ,
167+ corr_list : np .recarray ,
159168 base_target_count ,
160169 accept_corr ,
161170 scratch ,
@@ -231,7 +240,7 @@ def four_camera_matching(
231240
232241
233242def three_camera_matching (
234- corr_list : List [ List [ List [ np .recarray ]]],
243+ corr_list : np .recarray , # num_cam, num_cam, num_targets
235244 num_cams ,
236245 target_counts ,
237246 accept_corr ,
@@ -310,13 +319,13 @@ def three_camera_matching(
310319
311320
312321def consistent_pair_matching (
313- corr_list : List [ List [ List [ np .recarray ]]] ,
322+ corr_list : np .recarray ,
314323 num_cams : int ,
315324 target_counts : List [int ],
316325 accept_corr : float ,
317- scratch ,
326+ scratch : np . recarray ,
318327 scratch_size : int ,
319- tusage : List [ List [ int ]] ,
328+ tusage : np . ndarray ,
320329) -> int :
321330 """Find consistent pairs of correspondences."""
322331 matched = 0
@@ -356,8 +365,8 @@ def consistent_pair_matching(
356365
357366
358367def match_pairs (
359- corr_lists : List [ List [ List [ np .recarray ]]],
360- corrected : np .ndarray , # List[List[Coord2d]],
368+ corr_lists : np .recarray , # num_cam, num_cam, num_targets
369+ corrected : np .recarray , # List[List[Coord2d]],
361370 frm : Frame ,
362371 vpar : VolumePar ,
363372 cpar : ControlPar ,
@@ -457,7 +466,7 @@ def match_pairs(
457466
458467
459468def take_best_candidates (
460- src : np .recarray , dst : np .recarray , num_cams : int , tusage : List [ List [ int ]] #List[n_tupel]
469+ src : np .recarray , dst : np .recarray , num_cams : int , tusage : np . ndarray #List[n_tupel]
461470):
462471 """
463472 Take the best candidates from the candidate list based on their correlation measure.
@@ -532,7 +541,7 @@ def take_best_candidates(
532541
533542def py_correspondences (
534543 img_pts : List [List [Target ]], # num_cams * num_targets[cam]
535- flat_coords : List [ List [ np .recarray ]] ,
544+ flat_coords : np .recarray ,
536545 calib : List [Calibration ],
537546 vparam : VolumePar ,
538547 cparam : ControlPar ,
@@ -648,12 +657,12 @@ def py_correspondences(
648657
649658def correspondences (
650659 frm : Frame ,
651- corrected : List [ List [ np .recarray ]] , # List[List[Coord2d]],
660+ corrected : np .recarray , # List[List[Coord2d]],
652661 vpar : VolumePar ,
653662 cpar : ControlPar ,
654663 calib : List [Calibration ],
655664 match_counts : List [int ],
656- ) -> List [ np .ndarray ] : # n_tupel
665+ ) -> np .recarray : # n_tupel_dtype
657666 """Find correspondences between cameras.
658667
659668 /* correspondences() generates a list of tuple target numbers (one for each
@@ -690,8 +699,8 @@ def correspondences(
690699 nmax = NMAX
691700
692701 # Allocation of scratch buffers for internal tasks and return-value space
693- con0 = np .empty ((nmax * cpar .num_cams , ), dtype = n_tupel_dtype )
694- con = np .empty ((nmax * cpar .num_cams , ), dtype = n_tupel_dtype )
702+ con0 = np .recarray ((nmax * cpar .num_cams ), dtype = n_tupel_dtype )
703+ con = np .recarray ((nmax * cpar .num_cams ), dtype = n_tupel_dtype )
695704
696705 tim = safely_allocate_target_usage_marks (cpar .num_cams , nmax )
697706
0 commit comments