/src/R/examples/optim.R

http://github.com/beechung/Latent-Factor-Models · R · 26 lines · 14 code · 4 blank · 8 comment · 0 complexity · b68c8d3bf8ed5f50303c5e44203e2b8f MD5 · raw file

  1. ### Copyright (c) 2011, Yahoo! Inc. All rights reserved.
  2. ### Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  3. ###
  4. ### Author: Bee-Chung Chen
  5. ###
  6. ### Compile C code:
  7. ### R CMD SHLIB src/R/examples/optim.c -o lib/my_optim.so
  8. ###
  9. dyn.load("lib/my_optim.so");
  10. x = c( 0, 0, 0, 0);
  11. w = c(-1, 2, 3, 4);
  12. lower = c(1,1,1,1);
  13. upper = c(3,3,3,3);
  14. .C("min_sum_of_squares",
  15. as.double(x),
  16. as.double(w),
  17. as.double(lower),
  18. as.double(upper),
  19. length(w),
  20. as.integer(1),
  21. as.integer(1)
  22. );