File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,13 @@ impl<'a> Constraint for Sphere2<'a> {
21
21
fn project ( & self , x : & mut [ f64 ] ) {
22
22
if let Some ( center) = & self . center {
23
23
let mut norm_difference = 0.0 ;
24
- x. iter ( ) . zip ( center. iter ( ) ) . for_each ( |( a , b ) | {
25
- let diff_ = * a - * b ;
24
+ x. iter ( ) . zip ( center. iter ( ) ) . for_each ( |( xi , ci ) | {
25
+ let diff_ = * xi - * ci ;
26
26
norm_difference += diff_ * diff_
27
27
} ) ;
28
28
norm_difference = norm_difference. sqrt ( ) ;
29
29
x. iter_mut ( ) . zip ( center. iter ( ) ) . for_each ( |( x, c) | {
30
- * x = * c + ( * x - * c) / norm_difference;
30
+ * x = * c + self . radius * ( * x - * c) / norm_difference;
31
31
} ) ;
32
32
} else {
33
33
let norm_x = crate :: matrix_operations:: norm2 ( x) ;
@@ -37,6 +37,6 @@ impl<'a> Constraint for Sphere2<'a> {
37
37
}
38
38
39
39
fn is_convex ( & self ) -> bool {
40
- true
40
+ false
41
41
}
42
42
}
Original file line number Diff line number Diff line change @@ -765,9 +765,9 @@ fn t_ball1_random_optimality_conditions_centered() {
765
765
766
766
#[ test]
767
767
fn t_sphere2_no_center ( ) {
768
- let radius = 1.0 ;
768
+ let radius = 0.9 ;
769
769
let mut x_out = [ 1.0 , 1.0 ] ;
770
- let mut x_in = [ 1.0 , 1.0 ] ;
770
+ let mut x_in = [ - 0.3 , - 0.2 ] ;
771
771
let unit_sphere = Sphere2 :: new ( None , radius) ;
772
772
unit_sphere. project ( & mut x_out) ;
773
773
unit_sphere. project ( & mut x_in) ;
@@ -779,7 +779,7 @@ fn t_sphere2_no_center() {
779
779
780
780
#[ test]
781
781
fn t_sphere2_center ( ) {
782
- let radius = 1.0 ;
782
+ let radius = 1.3 ;
783
783
let center = [ -3.0 , 5.0 ] ;
784
784
let mut x = [ 1.0 , 1.0 ] ;
785
785
let unit_sphere = Sphere2 :: new ( Some ( & center) , radius) ;
You can’t perform that action at this time.
0 commit comments