Skip to content

Commit

Permalink
address numpy deprecation warning (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
odedstein authored Jun 2, 2024
1 parent d9a134b commit 3235115
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/gpytoolbox/particle_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def particle_swarm(fun,lb,ub,n_particles=100,max_iter=100,momentum=0.9,phi=0.1,v
f = fun(xi)
# print(xi)
best_xi[i,:] = xi.copy()
best_fi[i] = f.copy()
best_fi[i] = np.squeeze(f.copy())
# if verbose:
# print("Particle %d: f = %f" % (i,f))
if f < current_best_f:
Expand Down Expand Up @@ -77,7 +77,7 @@ def particle_swarm(fun,lb,ub,n_particles=100,max_iter=100,momentum=0.9,phi=0.1,v
# Update best position
if f < best_fi[i]:
best_xi[i,:] = x[i,:].copy()
best_fi[i] = f.copy()
best_fi[i] = np.squeeze(f.copy())
if f < current_best_f:
current_best_x = x[i,:].copy()
current_best_f = f.copy()
Expand Down
2 changes: 1 addition & 1 deletion src/gpytoolbox/ray_mesh_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def ray_mesh_intersect(cam_pos,cam_dir,V,F,use_embree=True,C=None,W=None,CH=None
add_to_queue_fun = trav.add_to_queue
_ = traverse_aabbtree(C,W,CH,tri_ind,None,traverse_fun,add_to_queue=add_to_queue_fun)
ts[i] = trav.t
ids[i] = trav.id
ids[i] = np.squeeze(trav.id)
lambdas[i,:] = trav.lmbd
# print("computed distances")
return ts, ids, lambdas
4 changes: 2 additions & 2 deletions src/gpytoolbox/squared_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def squared_distance(P,V,F=None,use_cpp=False,use_aabb=False,C=None,W=None,CH=No
# print(tri_ind)
_ = traverse_aabbtree(C,W,CH,tri_ind,split_dir,traverse_fun,add_to_queue=add_to_queue_fun)
# print(t.num_traversal)
indices[j] = t.current_best_element
squared_distances[j] = t.current_best_guess
indices[j] = np.squeeze(t.current_best_element)
squared_distances[j] = np.squeeze(t.current_best_guess)
lmbs[j,:] = t.current_best_lmb
else:
# Loop over every element
Expand Down
4 changes: 2 additions & 2 deletions test/test_particle_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def dropwave_function(x):
return -(1 + np.cos(12*np.sqrt(np.sum(x**2))))/(0.5*np.sum(x**2) + 2)
lb = np.array([-5,-5])
ub = np.array([5,5])
x,f = gpy.particle_swarm(dropwave_function,lb,ub,verbose=True,max_iter=100,topology='full')
xring,fring = gpy.particle_swarm(dropwave_function,lb,ub,verbose=True,max_iter=100,topology='ring')
x,f = gpy.particle_swarm(dropwave_function,lb,ub,verbose=False,max_iter=100,topology='full')
xring,fring = gpy.particle_swarm(dropwave_function,lb,ub,verbose=False,max_iter=100,topology='ring')
# print(x)
self.assertTrue(np.isclose(x,random_center,atol=1e-3).all())

Expand Down

0 comments on commit 3235115

Please sign in to comment.