@@ -155,6 +155,25 @@ def fast_det(matrix):
155155
156156
157157def circumsphere (pts ):
158+ """Compute the center and radius of a N dimension sphere which touches each point in pts.
159+
160+ Parameters
161+ ----------
162+ pts : array-like, of shape (N-dim + 1, N-dim)
163+ The points for which we would like to compute a circumsphere.
164+
165+ Returns
166+ -------
167+ center : tuple of floats of size N-dim
168+ radius : a positive float
169+ A valid center and radius, if a circumsphere is possible, and no points are repeated.
170+ If points are repeated, or a circumsphere is not possible, will return nans, and a
171+ ZeroDivisionError may occur.
172+ Will fail for matrices which are not (N-dim + 1, N-dim) in size due to non-square determinants:
173+ will raise numpy.linalg.LinAlgError.
174+ May fail for points that are integers (due to 32bit integer overflow).
175+ """
176+
158177 dim = len (pts ) - 1
159178 if dim == 2 :
160179 return fast_2d_circumcircle (pts )
@@ -166,15 +185,18 @@ def circumsphere(pts):
166185 center = zeros (dim )
167186 a = 1 / (2 * ndet (mat [:, 1 :]))
168187 factor = a
188+ # Use ind to index into the matrix columns
169189 ind = ones ((dim + 2 ,), bool )
170190 for i in range (1 , len (pts )):
171191 ind [i - 1 ] = True
172192 ind [i ] = False
173193 center [i - 1 ] = factor * ndet (mat [:, ind ])
174194 factor *= - 1
175195
196+ # Use subtract as we don't know the type of x0.
176197 x0 = pts [0 ]
177198 vec = subtract (center , x0 )
199+ # Vector norm.
178200 radius = sqrt (dot (vec , vec ))
179201
180202 return tuple (center ), radius
@@ -223,7 +245,7 @@ def simplex_volume_in_embedding(vertices) -> float:
223245
224246 Returns
225247 -------
226- volume : int
248+ volume : float
227249 the volume of the simplex with given vertices.
228250
229251 Raises
@@ -257,7 +279,7 @@ def simplex_volume_in_embedding(vertices) -> float:
257279 vol_square = fast_det (sq_dists_mat ) / coeff
258280
259281 if vol_square < 0 :
260- if - 1e-15 < vol_square < 1e-15 :
282+ if vol_square > - 1e-15 :
261283 return 0
262284 raise ValueError ("Provided vertices do not form a simplex" )
263285
0 commit comments