@@ -2088,19 +2088,20 @@ def get_contacts(self, as_tensor: bool = True, to_torch: bool = True):
20882088 # Allocate output buffer
20892089 if to_torch :
20902090 iout = torch .full ((out_size , 4 ), - 1 , dtype = gs .tc_int , device = gs .device )
2091- fout = torch .empty ((out_size , 10 ), dtype = gs .tc_float , device = gs .device )
2091+ fout = torch .zeros ((out_size , 10 ), dtype = gs .tc_float , device = gs .device )
20922092 else :
20932093 iout = np .full ((out_size , 4 ), - 1 , dtype = gs .np_int )
2094- fout = np .empty ((out_size , 10 ), dtype = gs .np_float )
2094+ fout = np .zeros ((out_size , 10 ), dtype = gs .np_float )
20952095
20962096 # Copy contact data
2097- self ._kernel_get_contacts (as_tensor , iout , fout )
2097+ if n_contacts_max > 0 :
2098+ self ._kernel_get_contacts (as_tensor , iout , fout )
20982099
2099- # Return structured view (no copy)
2100+ # Build structured view (no copy)
21002101 if as_tensor :
21012102 if self ._solver .n_envs > 0 :
2102- iout = iout .reshape ((n_contacts_max , n_envs , - 1 ))
2103- fout = fout .reshape ((n_contacts_max , n_envs , - 1 ))
2103+ iout = iout .reshape ((n_envs , n_contacts_max , 4 ))
2104+ fout = fout .reshape ((n_envs , n_contacts_max , 10 ))
21042105 iout_chunks = (iout [..., 0 ], iout [..., 1 ], iout [..., 2 ], iout [..., 3 ])
21052106 fout_chunks = (fout [..., 0 ], fout [..., 1 :4 ], fout [..., 4 :7 ], fout [..., 7 :])
21062107 values = (* iout_chunks , * fout_chunks )
@@ -2135,10 +2136,7 @@ def get_contacts(self, as_tensor: bool = True, to_torch: bool = True):
21352136 values = (* iout_chunks , * fout_chunks )
21362137
21372138 contacts_info = dict (
2138- zip (
2139- ("link_a" , "link_b" , "geom_a" , "geom_b" , "penetration" , "position" , "normal" , "force" ),
2140- (value .swapaxes (0 , 1 ) for value in values ) if as_tensor and self ._solver .n_envs > 0 else values ,
2141- )
2139+ zip (("link_a" , "link_b" , "geom_a" , "geom_b" , "penetration" , "position" , "normal" , "force" ), values )
21422140 )
21432141
21442142 # Cache contact information before returning
0 commit comments