static int xconvert(const char* x, pod_vector<T>& out, const char** errPos, int sep) { if (sep == 0) { sep = Potassco::def_sep; } typename pod_vector<T>::size_type sz = out.size(); std::size_t t = Potassco::convert_seq<T>(x, out.max_size() - sz, std::back_inserter(out), static_cast<char>(sep), errPos); if (!t) { out.resize(sz); } return static_cast<int>(t); }
void subgraph_info::get_rev( const play::const_random_iterator<Addr>& random_itr , const pod_vector<size_t>& dep_taddr , addr_t i_dep , pod_vector<addr_t>& subgraph ) { // check sizes CPPAD_ASSERT_UNKNOWN( map_user_op_.size() == n_op_ ); // process_range_ CPPAD_ASSERT_UNKNOWN( process_range_[i_dep] == false ); process_range_[i_dep] = true; // special value; see init_rev_in_subgraph addr_t depend_yes = addr_t( n_dep_ ); // assumption on i_dep CPPAD_ASSERT_UNKNOWN( i_dep < depend_yes ); // start with an empty subgraph for this dependent variable subgraph.resize(0); // tape index corresponding to this dependent variable size_t i_var = dep_taddr[i_dep]; // operator corresponding to this dependent variable size_t i_op = random_itr.var2op(i_var); i_op = size_t( map_user_op_[i_op] ); // if this variable depends on the selected indepent variables // process its subgraph CPPAD_ASSERT_UNKNOWN( in_subgraph_[i_op] != i_dep ) if( in_subgraph_[i_op] <= depend_yes ) { subgraph.push_back( addr_t(i_op) ); in_subgraph_[i_op] = i_dep; } // space used to return set of arguments that are variables pod_vector<size_t> argument_variable; // temporary space used by get_argument_variable pod_vector<bool> work; // scan all the operators in this subgraph size_t sub_index = 0; while(sub_index < subgraph.size() ) { // this operator connected to this dependent and selected independent i_op = size_t( subgraph[sub_index] ); CPPAD_ASSERT_UNKNOWN( in_subgraph_[i_op] == i_dep ); // // There must be a result for this operator # ifndef NDEBUG OpCode op = random_itr.get_op(i_op); CPPAD_ASSERT_UNKNOWN(op == AFunOp || NumRes(op) > 0 ); # endif // // which variables are connected to this operator get_argument_variable(random_itr, i_op, argument_variable, work); for(size_t j = 0; j < argument_variable.size(); ++j) { // add the corresponding operators to the subgraph size_t j_var = argument_variable[j]; size_t j_op = random_itr.var2op(j_var); j_op = size_t( map_user_op_[j_op] ); bool add = in_subgraph_[j_op] <= depend_yes; add &= in_subgraph_[j_op] != i_dep; if( random_itr.get_op(j_op) == InvOp ) { CPPAD_ASSERT_UNKNOWN( j_op == j_var ); add &= select_domain_[j_var - 1]; } if( add ) { subgraph.push_back( addr_t(j_op) ); in_subgraph_[j_op] = i_dep; } } // we are done scaning this subgraph operator ++sub_index; } }
void arg_is_variable( OpCode op , const Addr* arg , pod_vector<bool>& is_variable ) { size_t num_arg = NumArg(op); is_variable.resize( num_arg ); // switch(op) { // ------------------------------------------------------------------- // cases where true number of arugments = NumArg(op) == 0 case EndOp: case InvOp: case FunrvOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 ); break; // ------------------------------------------------------------------- // cases where NumArg(op) == 1 case AbsOp: case AcoshOp: case AcosOp: case AsinhOp: case AsinOp: case AtanhOp: case AtanOp: case CoshOp: case CosOp: case Expm1Op: case ExpOp: case Log1pOp: case LogOp: case SignOp: case SinhOp: case SinOp: case SqrtOp: case TanhOp: case TanOp: case FunavOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); is_variable[0] = true; break; case BeginOp: case ParOp: case FunapOp: case FunrpOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); is_variable[0] = false; break; // ------------------------------------------------------------------- // cases where NumArg(op) == 2 case AddpvOp: case DisOp: case DivpvOp: case EqpvOp: case LepvOp: case LtpvOp: case MulpvOp: case NepvOp: case PowpvOp: case SubpvOp: case ZmulpvOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); is_variable[0] = false; is_variable[1] = true; break; case DivvpOp: case LevpOp: case LtvpOp: case PowvpOp: case SubvpOp: case ZmulvpOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); is_variable[0] = true; is_variable[1] = false; break; case AddvvOp: case DivvvOp: case EqvvOp: case LevvOp: case LtvvOp: case MulvvOp: case NevvOp: case PowvvOp: case SubvvOp: case ZmulvvOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); is_variable[0] = true; is_variable[1] = true; break; case ErfOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); is_variable[0] = true; is_variable[1] = false; // parameter index corresponding to zero is_variable[2] = false; // parameter index corresponding to one break; // -------------------------------------------------------------------- // cases where NumArg(op) == 3 case LdpOp: case StppOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); is_variable[0] = false; is_variable[1] = false; is_variable[2] = false; break; case LdvOp: case StvpOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); is_variable[0] = false; is_variable[1] = true; is_variable[2] = false; break; case StpvOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); is_variable[0] = false; is_variable[1] = false; is_variable[2] = true; break; case StvvOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); is_variable[0] = false; is_variable[1] = true; is_variable[2] = true; break; // -------------------------------------------------------------------- // case where NumArg(op) == 4 case AFunOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 4 ); for(size_t i = 0; i < 4; i++) is_variable[i] = false; break; // -------------------------------------------------------------------- // case where NumArg(op) == 5 case PriOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 5 ); is_variable[0] = false; is_variable[1] = (arg[0] & 1) != 0; is_variable[2] = false; is_variable[3] = (arg[0] & 2) != 0; is_variable[4] = false; break; // -------------------------------------------------------------------- // case where NumArg(op) == 6 case CExpOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 6 ); is_variable[0] = false; is_variable[1] = false; is_variable[2] = (arg[0] & 1) != 0; is_variable[3] = (arg[0] & 2) != 0; is_variable[4] = (arg[0] & 4) != 0; is_variable[5] = (arg[0] & 8) != 0; break; // ------------------------------------------------------------------- // CSkipOp: case CSkipOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 ) // // true number of arguments num_arg = size_t(7 + arg[4] + arg[5]); is_variable.resize(num_arg); is_variable[0] = false; is_variable[1] = false; is_variable[2] = (arg[1] & 1) != 0; is_variable[3] = (arg[1] & 2) != 0; for(size_t i = 4; i < num_arg; ++i) is_variable[i] = false; break; // ------------------------------------------------------------------- // CSumOp: case CSumOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 ) // // true number of arguments num_arg = size_t(arg[4]); // is_variable.resize( num_arg ); for(size_t i = 0; i < num_arg; ++i) is_variable[i] = (5 <= i) & (i < size_t(arg[2])); break; case EqppOp: case LeppOp: case LtppOp: case NeppOp: CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); is_variable[0] = false; is_variable[1] = false; break; // -------------------------------------------------------------------- default: CPPAD_ASSERT_UNKNOWN(false); break; } return; }