Skip to content

Commit

Permalink
feat(ParameterVector): vectors for the remaining parameters
Browse files Browse the repository at this point in the history
* [1] added to tests so they pass
* Updated Namespace
* setMethods updated for R 1-based indexing
* exit(1) calls are commented out
* json output is updated for vectors creating better cohesion
* uses fims_math::dnorm, fims_math::dmultinom
* creates new methods in ParameterVector
* Initializes values to zero
  • Loading branch information
kellijohnson-NOAA committed Sep 19, 2024
1 parent a3a09e8 commit 4c0e009
Show file tree
Hide file tree
Showing 26 changed files with 2,311 additions and 1,401 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export(AgeComp)
export(BevertonHoltRecruitment)
export(CreateTMBModel)
export(SetFIMSFunctions)
export(Finalize)
export(DoubleLogisticSelectivity)
export(EWAAgrowth)
export(FIMSFrame)
Expand All @@ -16,7 +18,9 @@ export(Population)
export(TMBDlnormDistribution)
export(TMBDmultinomDistribution)
export(TMBDnormDistribution)
export(ToJSON)
export(clear)
export(get_log)
export(clear_logs)
export(get_fixed)
export(get_random)
Expand Down
12 changes: 6 additions & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Rcpp::loadModule(module = "fims", what = TRUE)
library.dynam.unload("FIMS", libpath)
}

setMethod("[<-", signature(x = "Rcpp_ParameterVector", i = "numeric"),
function(x, i) {
(x$at(i))
return(x)
})

setMethod("[<-", signature(x = "Rcpp_ParameterVector"), function(x, i, j, value) {
x$set(i - 1, value) # R uses 1-based indexing, C++ uses 0-based indexing
x # Return the modified object
})

setMethod("[", signature(x = "Rcpp_ParameterVector", i = "numeric"),
function(x, i) {
return(x$at(i))
return(x$get(i-1))
})

# setMethod("lapply", signature(X = "Rcpp_ParameterVector", FUN = "sum"),
Expand Down
27 changes: 1 addition & 26 deletions inst/include/common/def.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** \file def.hpp
*/

#define TMB_MODEL
/*
* File: def.hpp
*
Expand Down Expand Up @@ -50,31 +50,6 @@ std::ofstream DEBUG_LOG(

namespace fims {

/**
* A static class for FIMS logging.
*/

class fims_log {
public:
static std::map<std::string, std::ofstream>
FIMS_LOGS; /**< Map Log of files */
/**
* Static getter for retrieving a specific log file.
*/
static std::ofstream& get(const std::string& l) {
typename std::map<std::string, std::ofstream>::iterator it;
it = fims_log::FIMS_LOGS.find(l);
if (it == fims_log::FIMS_LOGS.end()) {
std::ofstream& of = fims_log::FIMS_LOGS[l];
of.open(l.c_str());
}

return fims_log::FIMS_LOGS[l];
}
};

std::map<std::string, std::ofstream> fims_log::FIMS_LOGS;

} // namespace fims

#endif /* TRAITS_HPP */
Loading

0 comments on commit 4c0e009

Please sign in to comment.