Stan  2.14.0
probability, sampling & optimization
is_user_defined_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_FUN_IS_USER_DEFINED_DEF_HPP
2 #define STAN_LANG_AST_FUN_IS_USER_DEFINED_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 namespace stan {
10  namespace lang {
11 
12  bool is_user_defined(const fun& fx) {
13  return is_user_defined(fx.name_, fx.args_);
14  }
15 
16  bool is_user_defined(const std::string& name,
17  const std::vector<expression>& args) {
18  std::vector<expr_type> arg_types;
19  for (size_t i = 0; i < args.size(); ++i)
20  arg_types.push_back(args[i].expression_type());
22  int matches
24  .get_signature_matches(name, arg_types, sig);
25  if (matches != 1)
26  return false; // reall shouldn't come up; throw instead?
27  std::pair<std::string, function_signature_t>
28  name_sig(name, sig);
30  }
31 
32  }
33 }
34 #endif
Probability, optimization and sampling library.
static function_signatures & instance()
Return the instance of this singleton.
std::vector< expression > args_
Sequence of argument expressions for function.
Definition: fun.hpp:32
Structure for function application.
Definition: fun.hpp:17
int get_signature_matches(const std::string &name, const std::vector< expr_type > &args, function_signature_t &signature)
Return the number of declared function signatures match for the specified name, argument types...
std::string name_
Name of function being applied.
Definition: fun.hpp:21
bool is_user_defined(const std::pair< std::string, function_signature_t > &name_sig)
Return true if the specified name and signature have been added as user-defined functions.
std::pair< expr_type, std::vector< expr_type > > function_signature_t
The type of a function signature, mapping a vector of argument expression types to a result expressio...
bool is_user_defined(const fun &fx)
Return true if the specified function was declared in the functions block.

     [ Stan Home Page ] © 2011–2016, Stan Development Team.