jeudi 16 avril 2020

Vector multiplication faster if factor is not 1

I'm currently facing a problem for which I don't have any explanation. Basically in a loop I'm multiplying a vector of 100 random points with a number. Like this:

for(i in 1:10000) {
  xs <- runif(100,0,1)
  ys <- runif(100,0,1)
  data <- factor*cbind(xs,ys)
  #do something with the data
}

If I set for example factor <- 3 it works fine and after some time I have my result. But if factor is set to 1 (as parameter of a function) it takes forever. Is there any logical reason for this behavior? Thank you very much!




Aucun commentaire:

Enregistrer un commentaire