cvxgrp / CVXR

An R modeling language for convex optimization problems.

Home Page:https://cvxr.rbind.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`geo_mean` hangs for some values of `p`

karldw opened this issue · comments

Describe the bug
For some values of p, the geo_mean() function hangs, seemingly forever. In the example below, it has been using ~100% CPU for several minutes. When I press Ctrl-C to cancel, there is no stack trace.

To Reproduce

library(CVXR)
x = Variable(3)

p_bad = c(0.9, 0.8, 0.7)
m = geo_mean(x, p_bad)   # hangs forever

p_good = c(0.7, 0.8, 0.9)
m = geo_mean(x, p_good)  # runs

Expected behavior
I expected geo_mean to run identically in both cases.

Version

CVXR 1.0-1

Session info
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] CVXR_1.0-1

loaded via a namespace (and not attached):
 [1] bit_4.0.4       compiler_4.0.2  R6_2.4.1        Matrix_1.2-18  
 [5] gmp_0.6-0       Rcpp_1.0.5      bit64_4.0.5     grid_4.0.2     
 [9] Rmpfr_0.8-1     lattice_0.20-41

Yes, I see this. I know the current geo_mean implementation is more involved than it needs to be as the comments in the source code (R/atoms.R) indicate. We need a cleaner implementation but a fix should be possible for now.