diff --git a/DESCRIPTION b/DESCRIPTION index 3721a13..85edb9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,8 @@ LinkingTo: Rcpp, RcppEigen, BH, - RcppParallel + RcppParallel, + rapidjsonr Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/R/util.R b/R/util.R index 5e96406..d14a88c 100644 --- a/R/util.R +++ b/R/util.R @@ -1,26 +1,26 @@ write_data <- function(Npars, finite_diff, lower_bounds, upper_bounds, bounds_types, data_filepath) { no_bounds <- all(lower_bounds == -Inf) && all(upper_bounds == Inf) - dat_string <- paste0( + dat_string <- paste( '{', - '"Npars":', Npars, ',', - '"finite_diff":', finite_diff, ',', - '"no_bounds":', as.integer(no_bounds), ',', - '"lower_bounds":[', paste0(lower_bounds, collapse = ','), '],', - '"upper_bounds":[', paste0(upper_bounds, collapse = ','), '],', - '"bounds_types":[', paste0(bounds_types, collapse = ','), ']', + '"Npars" : ', Npars, ',', + '"finite_diff" : ', finite_diff, ',', + '"no_bounds" : ', as.integer(no_bounds), ',', + '"lower_bounds" : [', paste0(lower_bounds, collapse = ','), '],', + '"upper_bounds" : [', paste0(upper_bounds, collapse = ','), '],', + '"bounds_types" : [', paste0(bounds_types, collapse = ','), ']', '}' ) - cat(dat_string, file = data_filepath) + writeLines(dat_string, con = data_filepath) invisible(NULL) } write_inits <- function(inits, init_filepath) { - dat_string <- paste0( + dat_string <- paste( '{', - '"pars":[', paste0(inits, collapse = ','), ']', + '"pars" : [', paste0(inits, collapse = ','), ']', '}' ) - cat(dat_string, file = init_filepath) + writeLines(dat_string, con = init_filepath) invisible(NULL) } diff --git a/README.md b/README.md index 3f8d01c..579e406 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,6 @@ provide a function for analytical calculation. ## Installation -You can install pre-built binaries using: - -``` r -# we recommend running this is a fresh R session or restarting your current session -install.packages("StanEstimators", - repos = c("https://andrjohns.github.io/StanEstimators/", getOption("repos"))) -``` - Or you can build from source using: ``` r diff --git a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES index 478c5a4..902ab4c 100644 --- a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES +++ b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES @@ -1,7 +1,7 @@ Package: StanEstimators Version: 0.0.0.9000 Imports: Rcpp, RcppParallel, posterior, methods, stats, callr -LinkingTo: Rcpp, RcppEigen, BH, RcppParallel +LinkingTo: Rcpp, RcppEigen, BH, RcppParallel, rapidjsonr Suggests: testthat (>= 3.0.0) License: MIT + file LICENSE -MD5sum: 82d792fb542890c43034a2255d57b0ef +MD5sum: 311eb91c5636f71f94276f5bf59e15ec diff --git a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.gz b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.gz index 6af4ba5..524ef8c 100644 Binary files a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.gz and b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.gz differ diff --git a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.rds b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.rds index b542241..7299077 100644 Binary files a/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.rds and b/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES.rds differ diff --git a/bin/macosx/big-sur-x86_64/contrib/4.3/StanEstimators_0.0.0.9000.tgz b/bin/macosx/big-sur-x86_64/contrib/4.3/StanEstimators_0.0.0.9000.tgz index 6fda99e..4c8f95c 100644 Binary files a/bin/macosx/big-sur-x86_64/contrib/4.3/StanEstimators_0.0.0.9000.tgz and b/bin/macosx/big-sur-x86_64/contrib/4.3/StanEstimators_0.0.0.9000.tgz differ diff --git a/bin/macosx/contrib/4.2/PACKAGES b/bin/macosx/contrib/4.2/PACKAGES index a097abf..f6fb750 100644 --- a/bin/macosx/contrib/4.2/PACKAGES +++ b/bin/macosx/contrib/4.2/PACKAGES @@ -1,7 +1,7 @@ Package: StanEstimators Version: 0.0.0.9000 Imports: Rcpp, RcppParallel, posterior, methods, stats, callr -LinkingTo: Rcpp, RcppEigen, BH, RcppParallel +LinkingTo: Rcpp, RcppEigen, BH, RcppParallel, rapidjsonr Suggests: testthat (>= 3.0.0) License: MIT + file LICENSE -MD5sum: bf0926fec280104551e92f20cc56d549 +MD5sum: 49499bc184ea8294a2a297bf9164403e diff --git a/bin/macosx/contrib/4.2/PACKAGES.gz b/bin/macosx/contrib/4.2/PACKAGES.gz index adec93c..c7e5ac7 100644 Binary files a/bin/macosx/contrib/4.2/PACKAGES.gz and b/bin/macosx/contrib/4.2/PACKAGES.gz differ diff --git a/bin/macosx/contrib/4.2/PACKAGES.rds b/bin/macosx/contrib/4.2/PACKAGES.rds index d14a814..5e678da 100644 Binary files a/bin/macosx/contrib/4.2/PACKAGES.rds and b/bin/macosx/contrib/4.2/PACKAGES.rds differ diff --git a/bin/macosx/contrib/4.2/StanEstimators_0.0.0.9000.tgz b/bin/macosx/contrib/4.2/StanEstimators_0.0.0.9000.tgz index 2e71e57..09f15d8 100644 Binary files a/bin/macosx/contrib/4.2/StanEstimators_0.0.0.9000.tgz and b/bin/macosx/contrib/4.2/StanEstimators_0.0.0.9000.tgz differ diff --git a/bin/windows/contrib/4.2/PACKAGES b/bin/windows/contrib/4.2/PACKAGES index 2109e53..cae440e 100644 --- a/bin/windows/contrib/4.2/PACKAGES +++ b/bin/windows/contrib/4.2/PACKAGES @@ -1,7 +1,7 @@ Package: StanEstimators Version: 0.0.0.9000 Imports: Rcpp, RcppParallel, posterior, methods, stats, callr -LinkingTo: Rcpp, RcppEigen, BH, RcppParallel +LinkingTo: Rcpp, RcppEigen, BH, RcppParallel, rapidjsonr Suggests: testthat (>= 3.0.0) License: MIT + file LICENSE Archs: x64 diff --git a/bin/windows/contrib/4.2/PACKAGES.gz b/bin/windows/contrib/4.2/PACKAGES.gz index f6523f7..47b9b29 100644 Binary files a/bin/windows/contrib/4.2/PACKAGES.gz and b/bin/windows/contrib/4.2/PACKAGES.gz differ diff --git a/bin/windows/contrib/4.2/PACKAGES.rds b/bin/windows/contrib/4.2/PACKAGES.rds index 112d185..25897ed 100644 Binary files a/bin/windows/contrib/4.2/PACKAGES.rds and b/bin/windows/contrib/4.2/PACKAGES.rds differ diff --git a/bin/windows/contrib/4.2/StanEstimators_0.0.0.9000.zip b/bin/windows/contrib/4.2/StanEstimators_0.0.0.9000.zip index 7df6036..84bf0ed 100644 Binary files a/bin/windows/contrib/4.2/StanEstimators_0.0.0.9000.zip and b/bin/windows/contrib/4.2/StanEstimators_0.0.0.9000.zip differ diff --git a/bin/windows/contrib/4.3/PACKAGES b/bin/windows/contrib/4.3/PACKAGES index 2109e53..cae440e 100644 --- a/bin/windows/contrib/4.3/PACKAGES +++ b/bin/windows/contrib/4.3/PACKAGES @@ -1,7 +1,7 @@ Package: StanEstimators Version: 0.0.0.9000 Imports: Rcpp, RcppParallel, posterior, methods, stats, callr -LinkingTo: Rcpp, RcppEigen, BH, RcppParallel +LinkingTo: Rcpp, RcppEigen, BH, RcppParallel, rapidjsonr Suggests: testthat (>= 3.0.0) License: MIT + file LICENSE Archs: x64 diff --git a/bin/windows/contrib/4.3/PACKAGES.gz b/bin/windows/contrib/4.3/PACKAGES.gz index f6523f7..47b9b29 100644 Binary files a/bin/windows/contrib/4.3/PACKAGES.gz and b/bin/windows/contrib/4.3/PACKAGES.gz differ diff --git a/bin/windows/contrib/4.3/PACKAGES.rds b/bin/windows/contrib/4.3/PACKAGES.rds index 112d185..25897ed 100644 Binary files a/bin/windows/contrib/4.3/PACKAGES.rds and b/bin/windows/contrib/4.3/PACKAGES.rds differ diff --git a/bin/windows/contrib/4.3/StanEstimators_0.0.0.9000.zip b/bin/windows/contrib/4.3/StanEstimators_0.0.0.9000.zip index c585ae8..818ecdd 100644 Binary files a/bin/windows/contrib/4.3/StanEstimators_0.0.0.9000.zip and b/bin/windows/contrib/4.3/StanEstimators_0.0.0.9000.zip differ diff --git a/binaries/StanEstimators-macOS-latest-oldrel/macOS-latest_oldrel/StanEstimators_0.0.0.9000.tgz b/binaries/StanEstimators-macOS-latest-oldrel/macOS-latest_oldrel/StanEstimators_0.0.0.9000.tgz index 2e71e57..09f15d8 100644 Binary files a/binaries/StanEstimators-macOS-latest-oldrel/macOS-latest_oldrel/StanEstimators_0.0.0.9000.tgz and b/binaries/StanEstimators-macOS-latest-oldrel/macOS-latest_oldrel/StanEstimators_0.0.0.9000.tgz differ diff --git a/binaries/StanEstimators-macOS-latest-release/StanEstimators_0.0.0.9000.tar.gz b/binaries/StanEstimators-macOS-latest-release/StanEstimators_0.0.0.9000.tar.gz index 3013b9b..24c9e15 100644 Binary files a/binaries/StanEstimators-macOS-latest-release/StanEstimators_0.0.0.9000.tar.gz and b/binaries/StanEstimators-macOS-latest-release/StanEstimators_0.0.0.9000.tar.gz differ diff --git a/binaries/StanEstimators-macOS-latest-release/macOS-latest_release/StanEstimators_0.0.0.9000.tgz b/binaries/StanEstimators-macOS-latest-release/macOS-latest_release/StanEstimators_0.0.0.9000.tgz index 6fda99e..4c8f95c 100644 Binary files a/binaries/StanEstimators-macOS-latest-release/macOS-latest_release/StanEstimators_0.0.0.9000.tgz and b/binaries/StanEstimators-macOS-latest-release/macOS-latest_release/StanEstimators_0.0.0.9000.tgz differ diff --git a/binaries/StanEstimators-windows-latest-oldrel/windows-latest_oldrel/StanEstimators_0.0.0.9000.zip b/binaries/StanEstimators-windows-latest-oldrel/windows-latest_oldrel/StanEstimators_0.0.0.9000.zip index 7df6036..84bf0ed 100644 Binary files a/binaries/StanEstimators-windows-latest-oldrel/windows-latest_oldrel/StanEstimators_0.0.0.9000.zip and b/binaries/StanEstimators-windows-latest-oldrel/windows-latest_oldrel/StanEstimators_0.0.0.9000.zip differ diff --git a/binaries/StanEstimators-windows-latest-release/windows-latest_release/StanEstimators_0.0.0.9000.zip b/binaries/StanEstimators-windows-latest-release/windows-latest_release/StanEstimators_0.0.0.9000.zip index c585ae8..818ecdd 100644 Binary files a/binaries/StanEstimators-windows-latest-release/windows-latest_release/StanEstimators_0.0.0.9000.zip and b/binaries/StanEstimators-windows-latest-release/windows-latest_release/StanEstimators_0.0.0.9000.zip differ diff --git a/inst/include/cmdstan/command.hpp b/inst/include/cmdstan/command.hpp index e7e4151..6b77843 100644 --- a/inst/include/cmdstan/command.hpp +++ b/inst/include/cmdstan/command.hpp @@ -90,7 +90,6 @@ stan::math::mpi_cluster &get_mpi_cluster() { #endif int command(int argc, const char *argv[]) { - Rcpp::Rcout << "a" << std::endl; stan::callbacks::stream_writer info(Rcpp::Rcout); stan::callbacks::stream_writer err(Rcpp::Rcerr); stan::callbacks::stream_logger logger(Rcpp::Rcout, Rcpp::Rcout, Rcpp::Rcout, @@ -154,18 +153,15 @@ int command(int argc, const char *argv[]) { throw std::invalid_argument(thread_msg.str()); } } - Rcpp::Rcout << "b" << std::endl; stan::math::init_threadpool_tbb(num_threads); unsigned int num_chains = get_num_chains(parser); check_file_config(parser); - Rcpp::Rcout << "c" << std::endl; parser.print(info); write_parallel_info(info); write_opencl_device(info); info(); - Rcpp::Rcout << "d" << std::endl; // General config for all methods unsigned int id = get_arg_val(parser, "id"); @@ -175,21 +171,17 @@ int command(int argc, const char *argv[]) { ////////////////////////////////////////////////// // Initialize Model // ////////////////////////////////////////////////// - Rcpp::Rcout << "e" << std::endl; arg_seed *random_arg = dynamic_cast(parser.arg("random")->arg("seed")); unsigned int random_seed = random_arg->random_value(); std::string filename = get_arg_val(parser, "data", "file"); - Rcpp::Rcout << "f" << std::endl; std::shared_ptr var_context = get_var_context(filename); - Rcpp::Rcout << "g" << std::endl; stan::model::model_base &model = new_model(*var_context, random_seed, &Rcpp::Rcout); - Rcpp::Rcout << "h" << std::endl; // Setup callbacks stan::callbacks::interrupt interrupt; @@ -204,11 +196,9 @@ int command(int argc, const char *argv[]) { std::vector> diagnostic_json_writers; - Rcpp::Rcout << "i" << std::endl; init_callbacks(parser, sample_writers, diagnostic_csv_writers, diagnostic_json_writers); - Rcpp::Rcout << "j" << std::endl; // Setup initial parameter values - arg "init" // arg is either filename or init radius value std::string init = get_arg_val(parser, "init"); @@ -219,13 +209,10 @@ int command(int argc, const char *argv[]) { } catch (const std::logic_error &e) { } - Rcpp::Rcout << "k" << std::endl; std::vector> init_contexts = get_vec_var_context(init, num_chains, id); - Rcpp::Rcout << "l" << std::endl; std::vector model_compile_info = model.model_compile_info(); - Rcpp::Rcout << "m" << std::endl; for (int i = 0; i < num_chains; ++i) { write_stan(sample_writers[i]); write_model(sample_writers[i], model.model_name()); @@ -238,7 +225,6 @@ int command(int argc, const char *argv[]) { write_model(diagnostic_csv_writers[i], model.model_name()); parser.print(diagnostic_csv_writers[i]); } - Rcpp::Rcout << "n" << std::endl; ////////////////////////////////////////////////// // Invoke Services // @@ -474,14 +460,12 @@ int command(int argc, const char *argv[]) { tol_rel_grad, tol_param, num_iterations, save_iterations, refresh, interrupt, logger, init_writers[0], sample_writers[0]); } else { - Rcpp::Rcout << "o" << std::endl; return_code = stan::services::optimize::lbfgs( model, *(init_contexts[0]), random_seed, id, init_radius, history_size, init_alpha, tol_obj, tol_rel_obj, tol_grad, tol_rel_grad, tol_param, num_iterations, save_iterations, refresh, interrupt, logger, init_writers[0], sample_writers[0]); - Rcpp::Rcout << "p" << std::endl; } } // ---- optimize end ---- // diff --git a/inst/include/cmdstan/command_helper.hpp b/inst/include/cmdstan/command_helper.hpp index 76de92f..766ffce 100644 --- a/inst/include/cmdstan/command_helper.hpp +++ b/inst/include/cmdstan/command_helper.hpp @@ -174,19 +174,13 @@ using shared_context_ptr = std::shared_ptr; * @param file A system file to read from */ inline shared_context_ptr get_var_context(const std::string &file) { - Rcpp::Rcout << "f1" << std::endl; if (file.empty()) { return std::make_shared(); } - Rcpp::Rcout << "f2" << std::endl; - std::fstream stream(file.c_str(), std::fstream::in); - Rcpp::Rcout << "f3" << std::endl; + std::ifstream stream = safe_open(file); if (get_suffix(file) == ".json") { - Rcpp::Rcout << "f4" << std::endl; stan::json::json_data var_context(stream); - Rcpp::Rcout << "f5" << std::endl; return std::make_shared(var_context); - Rcpp::Rcout << "f6" << std::endl; } Rcpp::Rcerr << "Warning: file '" << file diff --git a/inst/include/stan/io/json/json_data.hpp b/inst/include/stan/io/json/json_data.hpp index 1a30c1a..13c771c 100644 --- a/inst/include/stan/io/json/json_data.hpp +++ b/inst/include/stan/io/json/json_data.hpp @@ -71,11 +71,8 @@ class json_data : public stan::io::var_context { * @throws json_exception if data is not well-formed stan data declaration */ explicit json_data(std::istream &in) : vars_r_(), vars_i_() { - Rcpp::Rcout << "f41" << std::endl; json_data_handler handler(vars_r_, vars_i_); - Rcpp::Rcout << "f42" << std::endl; rapidjson_parse(in, handler); - Rcpp::Rcout << "f43" << std::endl; } /** diff --git a/inst/include/stan/io/json/json_data_handler.hpp b/inst/include/stan/io/json/json_data_handler.hpp index 9780203..44861ad 100644 --- a/inst/include/stan/io/json/json_data_handler.hpp +++ b/inst/include/stan/io/json/json_data_handler.hpp @@ -457,17 +457,13 @@ class json_data_handler : public stan::json::json_handler { * but we still need to track the number of tuple slots. */ void key(const std::string& key) { - Rcpp::Rcout << "f423.9.5.6.1.9.1" << std::endl; if (event != meta_event::OBJ_OPEN) { - Rcpp::Rcout << "f423.9.5.6.1.9.2" << std::endl; save_key_value_pair(); } - Rcpp::Rcout << "f423.9.5.6.1.9.3" << std::endl; event = meta_event::KEY; reset_values(); std::string outer = key_str(); key_stack.push_back(key); - Rcpp::Rcout << "f423.9.5.6.1.9.4" << std::endl; if (key_stack.size() == 1) { not_stan_var = !valid_varname(key); } @@ -485,7 +481,6 @@ class json_data_handler : public stan::json::json_handler { tuple_slots_map[outer].slots_acc++; } } - Rcpp::Rcout << "f423.9.5.6.1.9.5" << std::endl; std::string vname = key_str(); if (slot_types_map.count(vname) == 0) { slot_types_map[vname] = meta_type::SCALAR; diff --git a/inst/include/stan/io/json/rapidjson_parser.hpp b/inst/include/stan/io/json/rapidjson_parser.hpp index 98a43f1..7341b3d 100644 --- a/inst/include/stan/io/json/rapidjson_parser.hpp +++ b/inst/include/stan/io/json/rapidjson_parser.hpp @@ -109,17 +109,13 @@ struct RapidJSONHandler { */ template void rapidjson_parse(std::istream &in, Handler &handler) { - Rcpp::Rcout << "f421" << std::endl; rapidjson::Reader reader; RapidJSONHandler filter(handler); rapidjson::IStreamWrapper isw(in); - Rcpp::Rcout << "f422" << std::endl; handler.start_text(); - Rcpp::Rcout << "f423" << std::endl; if (!reader.Parse(isw, filter)) { - Rcpp::Rcout << "f424" << std::endl; rapidjson::ParseErrorCode err = reader.GetParseErrorCode(); std::stringstream ss; ss << "Error in JSON parsing " << std::endl @@ -131,7 +127,6 @@ void rapidjson_parse(std::istream &in, Handler &handler) { } throw json_error(ss.str()); } - Rcpp::Rcout << "f425" << std::endl; handler.end_text(); } } // namespace json diff --git a/inst/upgrade_headers.sh b/inst/upgrade_headers.sh index c8eb0d8..c64ed0c 100644 --- a/inst/upgrade_headers.sh +++ b/inst/upgrade_headers.sh @@ -8,7 +8,6 @@ mkdir -p include cp -r cmdstan-$CMDSTAN_VER/src/cmdstan include/cmdstan cp -r cmdstan-$CMDSTAN_VER/stan/src/stan include/stan -cp -r cmdstan-$CMDSTAN_VER/stan/lib/rapidjson*/* include/rapidjson cp -r cmdstan-$CMDSTAN_VER/stan/lib/stan_math/stan/math include/stan/math cp -r cmdstan-$CMDSTAN_VER/stan/lib/stan_math/stan/math.hpp include/stan/math.hpp rm -rf include/stan/math/opencl diff --git a/src/Makevars b/src/Makevars index 9672c9e..40016fc 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,6 +1,5 @@ PKG_CPPFLAGS = -I"../inst/include" -I"../inst/include/sundials" -D_REENTRANT -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 PKG_CPPFLAGS += -DSTRICT_R_HEADERS -D_HAS_AUTO_PTR_ETC=0 -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS PKG_CPPFLAGS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::CxxFlags()" | tail -n 1) -PKG_CXXFLAGS += -g -O0 PKG_LIBS = $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::RcppParallelLibs()" | tail -n 1) CXX_STD = CXX17 diff --git a/src/contrib/PACKAGES b/src/contrib/PACKAGES index a3af483..34b6fcd 100644 --- a/src/contrib/PACKAGES +++ b/src/contrib/PACKAGES @@ -1,8 +1,8 @@ Package: StanEstimators Version: 0.0.0.9000 Imports: Rcpp, RcppParallel, posterior, methods, stats, callr -LinkingTo: Rcpp, RcppEigen, BH, RcppParallel +LinkingTo: Rcpp, RcppEigen, BH, RcppParallel, rapidjsonr Suggests: testthat (>= 3.0.0) License: MIT + file LICENSE -MD5sum: dc0f1abdc9e6bd828feb4d99eefaedb4 +MD5sum: c6b4ffdce3d4b58366ac9439eee02b61 NeedsCompilation: yes diff --git a/src/contrib/PACKAGES.gz b/src/contrib/PACKAGES.gz index bd8b61b..3d65381 100644 Binary files a/src/contrib/PACKAGES.gz and b/src/contrib/PACKAGES.gz differ diff --git a/src/contrib/PACKAGES.rds b/src/contrib/PACKAGES.rds index a752646..c2da007 100644 Binary files a/src/contrib/PACKAGES.rds and b/src/contrib/PACKAGES.rds differ diff --git a/src/contrib/StanEstimators_0.0.0.9000.tar.gz b/src/contrib/StanEstimators_0.0.0.9000.tar.gz index 3013b9b..24c9e15 100644 Binary files a/src/contrib/StanEstimators_0.0.0.9000.tar.gz and b/src/contrib/StanEstimators_0.0.0.9000.tar.gz differ