本文整理汇总了C++中Tuple::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::size方法的具体用法?C++ Tuple::size怎么用?C++ Tuple::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PluginError
// Standard function takes the query as an input and evaluates the associated function
void KBModActionPlugin::ExecuteAtom::execute(Environment& environment,
RegistryPtr pregistry, const Tuple& parms,
const InterpretationConstPtr interpretationPtr) {
Registry& registry = *pregistry;
assert(parms.size() > 0);
std::string command;
for (int i = 0; i < parms.size(); i++) {
if (parms[i].isIntegerTerm()) {
std::ostringstream a_int;
a_int << parms[i].address;
std::string int_str = a_int.str();
command += int_str;
} else if (parms[i].isConstantTerm() || parms[i].isVariableTerm()) {
std::string termStr = registry.getTermStringByID(parms[i]);
command += termStr;
} else {
std::string termStr = registry.getTermStringByID(parms[i]);
if (termStr[0] != '\"' || termStr[termStr.size() - 1] != '\"') {
throw PluginError(
"The parameter of the atom #execute should be a quoted string!");
}
command += termStr.substr(1, termStr.size() - 2);
}
}
system(command.c_str());
}
示例2: thisAnswerSetContainsThisAction
/**
* @brief if the Tuple passed as the second parameter is present in the AnswerSets passed as first parameter
*/
bool ActionPluginFinalCallback::thisAnswerSetContainsThisAction(
const AnswerSetPtr& answerSetPtr, const Tuple& action_tuple) {
// used to have only the Action Atoms
InterpretationPtr intr = InterpretationPtr(new Interpretation(registryPtr));
intr->getStorage() |= ctxData.myAuxiliaryPredicateMask.mask()->getStorage();
intr->getStorage() &= answerSetPtr->interpretation->getStorage();
Interpretation::TrueBitIterator bit, bit_end;
for (boost::tie(bit, bit_end) = intr->trueBits(); bit != bit_end; ++bit) {
const Tuple & tuple = registryPtr->ogatoms.getByAddress(*bit).tuple;
if (tuple.size() - 5 == action_tuple.size()) {
bool different = false;
for (int i = 0; i < action_tuple.size() && !different; i++)
if (tuple[i + 1] != action_tuple[i])
different = true;
if (!different)
return true;
}
}
return false;
}
示例3: operator
bool operator()(const Tuple &t1, const Tuple &t2) const {
vector<size_t>::const_iterator it = this->order.begin();
for (; it != this->order.end(); ++it) {
if (*it >= t1.size()) {
if (*it < t2.size()) {
return false;
}
} else if (*it >= t2.size()) {
return true;
} else if (t1[*it] != t2[*it]) {
return t1[*it] < t2[*it];
}
}
if (this->total_ordering) {
Tuple::const_iterator cit1 = t1.begin();
Tuple::const_iterator cit2 = t2.begin();
while (cit1 != t1.end() && cit2 != t2.end()) {
if (*cit1 != *cit2) {
return *cit1 < *cit2;
}
++cit1;
++cit2;
}
if (cit1 == t1.end()) {
return cit2 != t2.end();
}
}
return false;
}
示例4: error
Adapt::Adapt(Tuple<Space *> spaces_, Tuple<int> proj_norms) : num_act_elems(-1), have_solutions(false), have_errors(false)
{
// sanity check
if (proj_norms.size() > 0 && spaces_.size() != proj_norms.size())
error("Mismatched numbers of spaces and projection types in Adapt::Adapt().");
this->neq = spaces_.size();
// sanity checks
error_if(this->neq <= 0, "Too few components (%d), only %d supported.", this->neq, H2D_MAX_COMPONENTS);
error_if(this->neq >= H2D_MAX_COMPONENTS, "Too many components (%d), only %d supported.", this->neq, H2D_MAX_COMPONENTS);
for (int i = 0; i < this->neq; i++) {
if (spaces_[i] == NULL) error("spaces[%d] is NULL in Adapt::Adapt().", i);
this->spaces.push_back(spaces_[i]);
}
// reset values
memset(errors_squared, 0, sizeof(errors_squared));
memset(form, 0, sizeof(form));
memset(ord, 0, sizeof(ord));
memset(sln, 0, sizeof(sln));
memset(rsln, 0, sizeof(rsln));
if (proj_norms.size() > 0) {
for (int i = 0; i < this->neq; i++) {
switch (proj_norms[i]) {
case H2D_L2_NORM: form[i][i] = l2_form<double, scalar>; ord[i][i] = l2_form<Ord, Ord>; break;
case H2D_H1_NORM: form[i][i] = h1_form<double, scalar>; ord[i][i] = h1_form<Ord, Ord>; break;
case H2D_HCURL_NORM: form[i][i] = hcurl_form<double, scalar>; ord[i][i] = hcurl_form<Ord, Ord>; break;
case H2D_HDIV_NORM: form[i][i] = hdiv_form<double, scalar>; ord[i][i] = hdiv_form<Ord, Ord>; break;
default: error("Unknown projection type in Adapt::Adapt().");
}
}
}
}
示例5: VEC_DOT
/**
* \param Tuple The first numeric tuple.
* \param Tuple The second numeric tuple.
*
* \return Number The result of the dot product.
*
* If one of the tuples is shorter, the remaining of the elements will be interpreted as 0.
*/
void VEC_DOT(Machine & machine){
Number result = 0;
Tuple b = machine.stack.popTuple();
Tuple a = machine.stack.popTuple();
Size min_size = a.size() < b.size() ? a.size() : b.size();
for(Index i = 0; i < min_size; i++) result += a[i].asNumber() * b[i].asNumber();
machine.stack.push(result);
}
示例6: init
void Adapt::init(Tuple<Space *> sp, Tuple<ProjNormType> proj_norms)
{
_F_
this->num = sp.size();
this->proj_norms = proj_norms;
this->spaces = new Space *[this->num];
for (int i = 0; i < this->num; i++) spaces[i] = sp[i];
this->sln = new Solution *[this->num];
this->rsln = new Solution *[this->num];
this->errors = new double *[this->num];
this->norms = new double [this->num];
for (int i = 0; i < this->num; i++) {
this->sln[i] = NULL;
this->rsln[i] = NULL;
this->errors[i] = NULL;
this->norms[i] = 0.0;
}
form = new_matrix<biform_val_t>(num, num);
ord = new_matrix<biform_ord_t>(num, num);
for (int i = 0; i < num; i++)
for (int j = 0; j < num; j++) {
if (i == j && proj_norms.size() > 0) {
switch (proj_norms[i]) {
case HERMES_H1_NORM: form[i][i] = h1_form<double, scalar>; ord[i][i] = h1_form<Ord, Ord>; break;
case HERMES_HCURL_NORM: form[i][i] = hcurl_form<double, scalar>; ord[i][i] = hcurl_form<Ord, Ord>; break;
default: error("Unknown projection type in Adapt::Adapt().");
}
}
else {
form[i][j] = NULL;
ord[i][j] = NULL;
}
}
esort = NULL;
have_errors = false;
// default parameters
h_only = false;
strategy = 0;
max_order = H3D_MAX_ELEMENT_ORDER;
aniso = true;
exponent = 1.0 / 3.0;
log_file = NULL;
}
示例7: VEC_MUL
/**
* \param Tuple The first numeric tuple.
* \param Tuple The second numeric tuple.
*
* \return Tuple The result of an element wise multiplication.
*
* If one of the tuples is shorter, the remaining of the elements will be interpreted as 0.
*/
void VEC_MUL(Machine & machine){
Tuple & result = machine.globals[machine.nextInt8()].asTuple() = Tuple();
Tuple b = machine.stack.popTuple ();
Number a = machine.stack.popNumber();
for(Index i = 0; i < b.size(); i++) result.push(a * b[i].asNumber());
machine.stack.push(result);
}
示例8: reallocate
template<class T> void Tuple<T>::append(const Tuple<T>& t) {
int old_sz = sz;
reallocate(t.size()+size());
assert(alloc_sz >= sz);
for(int i=0; i<t.sz; i++)
data[i+old_sz] = t.data[i];
}
示例9: joinTuples
void Relation::joinTuples(Schema &s1, Schema &s2, Tuple t1, Tuple t2){
Tuple t3 = t1;
for(int i = 0; i < (int)t2.size(); i++)
if(!s1.contains(s2.attributes[i]))
t3.push_back(t2[i]);
tuples.insert(t3);
}
示例10:
bool Tuple::operator < (const Tuple &right) const {
if (this->size() < right.size()) {
return true;
}
if (this->size() == right.size()) {
for (std::size_t i = 0; i < this->size(); ++i) {
if ((*this)[i] < right[i]) {
return true;
}
if (right[i] < (*this)[i]) {
return false;
}
}
}
return false;
}
示例11: paranoidInsertTypeCheck
void TupleStorageSubBlock::paranoidInsertTypeCheck(const Tuple &tuple, const AllowedTypeConversion atc) {
#ifdef QUICKSTEP_DEBUG
assert(relation_.size() == tuple.size());
Tuple::const_iterator value_it = tuple.begin();
CatalogRelation::const_iterator attr_it = relation_.begin();
while (value_it != tuple.end()) {
switch (atc) {
case kNone:
assert(value_it->getType().equals(attr_it->getType()));
break;
case kSafe:
assert(value_it->getType().isSafelyCoercibleTo(attr_it->getType()));
break;
case kUnsafe:
assert(value_it->getType().isCoercibleTo(attr_it->getType()));
break;
}
++value_it;
++attr_it;
}
#endif
}
示例12: toVector
bool toVector(PyObjectPtr obj, std::vector<double>& result)
{
bool knownType = true;
if(NdArray::check(obj))
{
NdArray ndarray = {obj};
const unsigned size = ndarray.size();
result.resize(size);
const int ndim = ndarray.ndim();
if(ndim != 1)
throw std::runtime_error("Array object has " + std::to_string(ndim)
+ " dimensions, expected 1");
if(!ndarray.isDouble())
throw std::runtime_error("Array object does not contain doubles");
for(unsigned i = 0; i < size; i++)
result[i] = ndarray.get(i);
}
else if(List::check(obj))
{
List list = {obj};
const unsigned size = list.size();
result.resize(size);
for(unsigned i = 0; i < size; i++)
{
if(!list.isDouble(i))
throw std::runtime_error(
"List object contains item that is not a double at index "
+ std::to_string(i));
result[i] = list.get(i);
throwPythonException();
}
}
else if(Tuple::check(obj))
{
Tuple tuple = {obj};
const unsigned size = tuple.size();
result.resize(size);
for(unsigned i = 0; i < size; i++)
{
if(!tuple.isDouble(i))
throw std::runtime_error(
"Tuple object contains item that is not a double at index "
+ std::to_string(i));
result[i] = tuple.get(i);
throwPythonException();
}
}
else
{
knownType = false;
}
return knownType;
}
示例13: lvs
std::pair<ConstraintTree*,ConstraintTree*>
ConstraintTree::split (const Tuple& tuple)
{
// assumes that my log vars are already on top
LogVars lvs (logVars_.begin(), logVars_.begin() + tuple.size());
ConstraintTree tempCt (logVars_, {tuple});
return split (lvs, &tempCt, lvs);
}
示例14: operator
bool operator()(const Tuple& tup, std::vector<size_t>& mv) const {
if ((*this)(tup)) {
mv.resize(size);
std::iota(mv.begin(), mv.end(), tup.size() - size);
return true;
}
return false;
}
示例15: solve_newton
// Newton's method for an arbitrary number of equations.
bool NonlinSystem::solve_newton(Tuple<Solution*> u_prev, double newton_tol,
int newton_max_iter, bool verbose,
Tuple<MeshFunction*> mesh_fns)
{
// sanity checks
int n = u_prev.size();
if (n != this->wf->neq)
error("The number of solutions in newton_solve() must match the number of equation in the PDE system.");
if (this->spaces == NULL) error("spaces is NULL in solve_newton().");
for (int i=0; i < n; i++) {
if (this->spaces[i] == NULL) error("spaces[%d] is NULL in solve_newton().", i);
}
int n_mesh_fns;
if (mesh_fns == Tuple<MeshFunction*>()) n_mesh_fns = 0;
else n_mesh_fns = mesh_fns.size();
for (int i=0; i<n_mesh_fns; i++) {
if (mesh_fns[i] == NULL) error("a filter is NULL in solve_newton().");
}
int it = 1;
double res_l2_norm;
do
{
info("---- Newton iter %d:", it);
// reinitialize filters
for (int i=0; i < n_mesh_fns; i++) mesh_fns[i]->reinit();
// assemble the Jacobian matrix and residual vector,
// solve the system
this->assemble();
this->solve(u_prev);
// calculate the l2-norm of residual vector
res_l2_norm = this->get_residual_l2_norm();
if (verbose) printf("---- Newton iter %d, ndof %d, res. l2 norm %g\n",
it, this->get_num_dofs(), res_l2_norm);
it++;
}
while (res_l2_norm > newton_tol && it <= newton_max_iter);
// returning "true" if converged, otherwise returning "false"
if (it <= newton_max_iter) return true;
else return false;
}