void assembleIRKState(
  const int stageIndex,
  const Teuchos::SerialDenseMatrix<int,Scalar> &A_in,
  const Scalar dt,
  const Thyra::VectorBase<Scalar> &x_base,
  const Thyra::ProductVectorBase<Scalar> &x_stage_bar,
  Teuchos::Ptr<Thyra::VectorBase<Scalar> > x_out_ptr
  )
{

  typedef ScalarTraits<Scalar> ST;

  const int numStages_in = A_in.numRows();
  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( stageIndex, 0, numStages_in );
  TEUCHOS_ASSERT_EQUALITY( A_in.numRows(), numStages_in );
  TEUCHOS_ASSERT_EQUALITY( A_in.numCols(), numStages_in );
  TEUCHOS_ASSERT_EQUALITY( x_stage_bar.productSpace()->numBlocks(), numStages_in );
  Thyra::VectorBase<Scalar>& x_out = *x_out_ptr;

  V_V( outArg(x_out), x_base );
  for ( int j = 0; j < numStages_in; ++j ) {
    Vp_StV( outArg(x_out), dt * A_in(stageIndex,j), *x_stage_bar.getVectorBlock(j) );
  }

}
예제 #2
0
파일: add.cpp 프로젝트: achabill/symengine
RCP<const Basic> Add::subs(const map_basic_basic &subs_dict) const
{
    RCP<const Add> self = rcp_from_this_cast<const Add>();
    auto it = subs_dict.find(self);
    if (it != subs_dict.end())
        return it->second;

    SymEngine::umap_basic_num d;
    RCP<const Number> coef;

    it = subs_dict.find(coef_);
    if (it != subs_dict.end()) {
        coef = zero;
        coef_dict_add_term(outArg(coef), d, one, it->second);
    } else {
        coef = coef_;
    }

    for (const auto &p: dict_) {
        auto it = subs_dict.find(Add::from_dict(zero, {{p.first, p.second}}));
        if (it != subs_dict.end()) {
            coef_dict_add_term(outArg(coef), d, one, it->second);
        } else {
            it = subs_dict.find(p.second);
            if (it != subs_dict.end()) {
                coef_dict_add_term(outArg(coef), d, one, mul(it->second, p.first->subs(subs_dict)));
            } else {
                coef_dict_add_term(outArg(coef), d, p.second, p.first->subs(subs_dict));
            }
        }
    }

    return Add::from_dict(coef, std::move(d));
}
예제 #3
0
파일: add.cpp 프로젝트: MridulS/csympy
RCP<const Basic> Add::subs(const map_basic_basic &subs_dict) const
{
    RCP<const Add> self = rcp_const_cast<Add>(rcp(this));
    auto it = subs_dict.find(self);
    if (it != subs_dict.end())
        return it->second;

    CSymPy::umap_basic_num d;
    RCP<const Number> coef=coef_, coef2;
    RCP<const Basic> t;
    for (auto &p: dict_) {
        RCP<const Basic> term = p.first->subs(subs_dict);
        if (term == p.first) {
            Add::dict_add_term(d, p.second, p.first);
        } else if (is_a<Integer>(*term) &&
                rcp_static_cast<const Integer>(term)->is_zero()) {
            continue;
        } else if (is_a_Number(*term)) {
            iaddnum(outArg(coef),
                    mulnum(p.second, rcp_static_cast<const Number>(term)));
        } else if (is_a<Add>(*term)) {
            for (auto &q: (rcp_static_cast<const Add>(term))->dict_)
                Add::dict_add_term(d, q.second, q.first);
            iaddnum(outArg(coef), rcp_static_cast<const Add>(term)->coef_);
        } else {
            Add::as_coef_term(mul(p.second, term), outArg(coef2), outArg(t));
            Add::dict_add_term(d, coef2, t);
        }
    }
    return Add::from_dict(coef, std::move(d));
}
예제 #4
0
파일: pow.cpp 프로젝트: rajithv/symengine
RCP<const Basic> log(const RCP<const Basic> &arg)
{
    if (eq(*arg, *zero)) {
        throw NotImplementedError(
            "log(0) is complex infinity. Yet to be implemented");
    }
    if (eq(*arg, *one))
        return zero;
    if (eq(*arg, *E))
        return one;
    if (is_a_Number(*arg)) {
        RCP<const Number> _arg = rcp_static_cast<const Number>(arg);
        if (not _arg->is_exact()) {
            return _arg->get_eval().log(*_arg);
        } else if (_arg->is_negative()) {
            throw NotImplementedError(
                "Imaginary Result. Yet to be implemented");
        }
    }
    if (is_a<Rational>(*arg)) {
        RCP<const Integer> num, den;
        get_num_den(static_cast<const Rational &>(*arg), outArg(num),
                    outArg(den));
        return sub(log(num), log(den));
    }
    return make_rcp<const Log>(arg);
}
예제 #5
0
파일: mul.cpp 프로젝트: MridulS/csympy
RCP<const Basic> Mul::power_all_terms(const RCP<const Basic> &exp) const
{
    CSymPy::map_basic_basic d;
    RCP<const Basic> new_coef = pow(coef_, exp);
    RCP<const Number> coef_num = one;
    RCP<const Basic> new_exp;
    for (auto &p: dict_) {
        new_exp = mul(p.second, exp);
        if (is_a_Number(*new_exp)) {
            // No need for additional dict checks here.
            // The dict should be of standard form before this is
            // called.
            if (rcp_static_cast<const Number>(new_exp)->is_zero()) {
                continue;
            } else {
                Mul::dict_add_term_new(outArg(coef_num), d, new_exp, p.first);
            }
        } else {
            Mul::dict_add_term_new(outArg(coef_num), d, new_exp, p.first);
        }
    }
    if (is_a_Number(*new_coef)) {
        imulnum(outArg(coef_num), rcp_static_cast<const Number>(new_coef));
        return Mul::from_dict(coef_num, std::move(d));
    } else {
        // TODO: this can be made faster probably:
        return mul(mul(new_coef, coef_num), Mul::from_dict(one, std::move(d)));
    }
}
예제 #6
0
파일: mul.cpp 프로젝트: MridulS/csympy
RCP<const Basic> mul_expand(const RCP<const Mul> &self)
{
    RCP<const Basic> a, b;
    self->as_two_terms(outArg(a), outArg(b));
    a = expand(a);
    b = expand(b);
    return mul_expand_two(a, b);
}
예제 #7
0
bool Cos::is_canonical(const RCP<const Basic> &arg)
{
    // e.g. cos(0)
    if (is_a<Integer>(*arg) &&
            rcp_static_cast<const Integer>(arg)->is_zero())
        return false;
    // e.g cos(k*pi/12)
    RCP<const Integer> n;
    RCP<const Basic> r;
    bool b = get_pi_shift(arg, outArg(n), outArg(r));
    if (b)
        return false;
    return true;
}
예제 #8
0
bool Cot::is_canonical(const RCP<const Basic> &arg)
{
    // TODO: Add further checks for +inf -inf cases 
    if (is_a<Integer>(*arg) &&
            rcp_static_cast<const Integer>(arg)->is_zero())
        return false;
    // e.g cot(k*pi/12)
    RCP<const Integer> n;
    RCP<const Basic> r;
    bool b = get_pi_shift(arg, outArg(n), outArg(r));
    if (b)
        return false;
    return true;
}
예제 #9
0
double 
NOX::Thyra::Vector::
norm(const NOX::Abstract::Vector& weights) const
{
  const NOX::Thyra::Vector& w = 
    dynamic_cast<const NOX::Thyra::Vector&>(weights);

  if (nonnull(weightVec_) && do_implicit_weighting_) {
    ::Thyra::copy(*thyraVec, outArg(*tmpVec_));
    ::Thyra::ele_wise_scale(*weightVec_, outArg(*tmpVec_));
    return ::Thyra::norm_2(*w.thyraVec, *tmpVec_);
  }

  return ::Thyra::norm_2(*w.thyraVec, *thyraVec);
}
예제 #10
0
GaloisFieldDict GaloisFieldDict::gf_gcd(const GaloisFieldDict &o) const
{
    if (modulo_ != o.modulo_)
        throw std::runtime_error("Error: field must be same.");
    GaloisFieldDict f = static_cast<GaloisFieldDict>(*this);
    GaloisFieldDict g = o;
    GaloisFieldDict temp_out;
    while (not g.dict_.empty()) {
        f.gf_div(g, outArg(temp_out), outArg(f)); // f, g = f % g, g
        f.dict_.swap(g.dict_);
    }
    integer_class temp_LC;
    f.gf_monic(temp_LC, outArg(f));
    return f;
}
예제 #11
0
bool Sec::is_canonical(const RCP<const Basic> &arg)
{
    // e.g. Sec(0)
    if (is_a<Integer>(*arg) &&
            rcp_static_cast<const Integer>(arg)->is_zero())
        return false;
    // TODO: Update for +inf/-inf constraints
    // e.g sec(k*pi/12)
    RCP<const Integer> n;
    RCP<const Basic> r;
    bool b = get_pi_shift(arg, outArg(n), outArg(r));
    if (b)
        return false;
    return true;
}
예제 #12
0
RCP<const Basic> sin(const RCP<const Basic> &arg)
{
    if (eq(arg, zero)) return zero;
    RCP<const Basic> ret_arg;
    int index;
    int sign;
    bool conjugate =  eval(arg, 2, 1, 0, //input
                      outArg(ret_arg), index, sign); //output

    if (conjugate) {
        // cos has to be returned
        if (sign == 1)
            return rcp(new Cos(ret_arg));
        else
            return mul(minus_one, rcp(new Cos(ret_arg)));
    }
    else {
        if (eq(ret_arg, zero)) {
            return mul(integer(sign), sin_table[index]);
        }
        else {
            if (sign == 1)
                return rcp(new Sin(ret_arg));
            else
                return mul(minus_one, rcp(new Sin(ret_arg)));
        }
    }
}
예제 #13
0
NOX::Abstract::Vector& 
NOX::Thyra::Vector::
init(double value)
{
  ::Thyra::put_scalar(value, outArg(*thyraVec));
  return *this;
}
예제 #14
0
파일: mul.cpp 프로젝트: MridulS/csympy
// Mul (t^exp) to the dict "d"
void Mul::dict_add_term(map_basic_basic &d, const RCP<const Basic> &exp,
        const RCP<const Basic> &t)
{
    auto it = d.find(t);
    if (it == d.end()) {
        insert(d, t, exp);
    } else {
        // Very common case, needs to be fast:
        if (is_a_Number(*it->second) && is_a_Number(*exp)) {
            RCP<const Number> tmp = rcp_static_cast<const Number>(it->second);
            iaddnum(outArg(tmp), rcp_static_cast<const Number>(exp));
            if (tmp->is_zero()) {
                d.erase(it);
            } else {
                it->second = tmp;
            }
        } else {
            // General case:
            it->second = add(it->second, exp);
            if (is_a<Integer>(*it->second) &&
                    rcp_static_cast<const Integer>(it->second)->is_zero()) {
                d.erase(it);
            }
        }
    }
}
예제 #15
0
NOX::Abstract::Vector& 
NOX::Thyra::Vector::
scale(double alpha)
{
  ::Thyra::scale(alpha, outArg(*thyraVec));
  return *this;
}
예제 #16
0
RCP<const Basic> sec(const RCP<const Basic> &arg)
{
    RCP<const Basic> ret_arg;
    int index;
    int sign;
    bool conjugate =  eval(arg, 2, 0, 1, //input
                      outArg(ret_arg), index, sign); //output

    if (conjugate) {
        // cos has to be returned
        if (sign == 1)
            return rcp(new Csc(ret_arg));
        else
            return mul(minus_one, rcp(new Csc(ret_arg)));
    }
    else {
        if (eq(ret_arg, zero)) {
            return mul(integer(sign),
                   div(one, sin_table[(index + 6)% 24]));
        }
        else {
            if (sign == 1)
                return rcp(new Sec(ret_arg));
            else
                return mul(minus_one, rcp(new Sec(ret_arg)));
        }
    }
}
예제 #17
0
    void bvisit(const Pow &x)
    {

        RCP<const Basic> base_, exp_, num, den;
        base_ = x.get_base();
        exp_ = x.get_exp();
        as_numer_denom(base_, outArg(num), outArg(den));

        // if the exp is a negative numer, or is intuitively 'negative'
        if (handle_minus(exp_, outArg(exp_))) {
            *numer_ = pow(den, exp_);
            *denom_ = pow(num, exp_);
        } else {
            *numer_ = pow(num, exp_);
            *denom_ = pow(den, exp_);
        }
    }
예제 #18
0
void XferObject::ErrorCode(const InterfaceDescription::Member* member, Message& msg)
{
    MsgArg outArg("i", errorCode);
    QStatus status = MethodReply(msg, &outArg, 1);
    if (ER_OK != status) {
        NotifyUser(MSG_ERROR, "XferObject::ErrorCode : Error sending reply");
    }
}
예제 #19
0
double 
NOX::Thyra::Vector::
innerProduct(const NOX::Abstract::Vector& y) const
{
  const NOX::Thyra::Vector& yy = 
    dynamic_cast<const NOX::Thyra::Vector&>(y);

  if (nonnull(weightVec_) && do_implicit_weighting_) {
    ::Thyra::copy(*thyraVec, tmpVec_.ptr());
    // double the scaling one for each vector in product
    ::Thyra::ele_wise_scale(*weightVec_, outArg(*tmpVec_));
    ::Thyra::ele_wise_scale(*weightVec_, outArg(*tmpVec_));
    return thyraVec->space()->scalarProd(*tmpVec_, *yy.thyraVec);
  }

  return thyraVec->space()->scalarProd(*thyraVec, *yy.thyraVec);
}
예제 #20
0
파일: mul.cpp 프로젝트: MridulS/csympy
RCP<const Basic> Mul::subs(const map_basic_basic &subs_dict) const
{
    RCP<const Mul> self = rcp_const_cast<Mul>(rcp(this));
    auto it = subs_dict.find(self);
    if (it != subs_dict.end())
        return it->second;

    RCP<const Number> coef = coef_;
    map_basic_basic d;
    for (auto &p: dict_) {
        RCP<const Basic> factor_old = pow(p.first, p.second);
        RCP<const Basic> factor = factor_old->subs(subs_dict);
        if (factor == factor_old) {
            Mul::dict_add_term_new(outArg(coef), d, p.second, p.first);
        } else if (is_a<Integer>(*factor) &&
                rcp_static_cast<const Integer>(factor)->is_zero()) {
            return zero;
        } else if (is_a_Number(*factor)) {
            imulnum(outArg(coef), rcp_static_cast<const Number>(factor));
        } else if (is_a<Mul>(*factor)) {
            RCP<const Mul> tmp = rcp_static_cast<const Mul>(factor);
            imulnum(outArg(coef), tmp->coef_);
            for (auto &q: tmp->dict_) {
                Mul::dict_add_term_new(outArg(coef), d, q.second, q.first);
            }
        } else {
            RCP<const Basic> exp, t;
            Mul::as_base_exp(factor, outArg(exp), outArg(t));
            Mul::dict_add_term_new(outArg(coef), d, exp, t);
        }
    }
    return Mul::from_dict(coef, std::move(d));
}
예제 #21
0
 static RCP<const Basic> diff(const Mul &self,
         const RCP<const Symbol> &x) {
     RCP<const Number> overall_coef = zero;
     umap_basic_num add_dict;
     for (auto &p: self.dict_) {
         RCP<const Number> coef = self.coef_;
         RCP<const Basic> factor = pow(p.first, p.second)->diff(x);
         if (is_a<Integer>(*factor) &&
                 rcp_static_cast<const Integer>(factor)->is_zero()) continue;
         map_basic_basic d = self.dict_;
         d.erase(p.first);
         if (is_a_Number(*factor)) {
             imulnum(outArg(coef), rcp_static_cast<const Number>(factor));
         } else if (is_a<Mul>(*factor)) {
             RCP<const Mul> tmp = rcp_static_cast<const Mul>(factor);
             imulnum(outArg(coef), tmp->coef_);
             for (auto &q: tmp->dict_) {
                 Mul::dict_add_term_new(outArg(coef), d, q.second, q.first);
             }
         } else {
             RCP<const Basic> exp, t;
             Mul::as_base_exp(factor, outArg(exp), outArg(t));
             Mul::dict_add_term_new(outArg(coef), d, exp, t);
         }
         if (d.size() == 0) {
             iaddnum(outArg(overall_coef), coef);
         } else {
             RCP<const Basic> mul = Mul::from_dict(one, std::move(d));
             Add::dict_add_term(add_dict, coef, mul);
         }
     }
     return Add::from_dict(overall_coef, std::move(add_dict));
 }
예제 #22
0
NOX::Abstract::Vector& 
NOX::Thyra::Vector::
scale(const NOX::Abstract::Vector& src)
{  
  const NOX::Thyra::Vector& source = 
    dynamic_cast<const NOX::Thyra::Vector&>(src);
  ::Thyra::ele_wise_scale(*source.thyraVec, outArg(*thyraVec));
  return *this;
}
예제 #23
0
NOX::Abstract::Vector& 
NOX::Thyra::Vector::
random(bool useSeed, int seed)
{
  if (useSeed)
    ::Thyra::seed_randomize<double>(seed);
  ::Thyra::randomize(-1.0, 1.0, outArg(*thyraVec));
  return *this;
}
예제 #24
0
RCP<const Basic> log(const RCP<const Basic> &arg)
{
    if (eq(arg, zero)) {
        throw std::runtime_error("log(0) is complex infinity. Yet to be implemented");
    }
    if (eq(arg, one)) return zero;
    if (eq(arg, E)) return one;
    if (is_a_Number(*arg) &&
        rcp_static_cast<const Number>(arg)->is_negative()) {
        throw std::runtime_error("Imaginary Result. Yet to be implemented");
    }
    if (is_a<Rational>(*arg)) {
        RCP<const Integer> num, den;
        get_num_den(rcp_static_cast<const Rational>(arg), outArg(num), outArg(den));
        return sub(log(num), log(den));
    }
    return rcp(new Log(arg));
}
예제 #25
0
NOX::Abstract::Vector& 
NOX::Thyra::Vector::
reciprocal(const NOX::Abstract::Vector& src)
{
  const NOX::Thyra::Vector& source = 
    dynamic_cast<const NOX::Thyra::Vector&>(src);
  ::Thyra::reciprocal(*source.thyraVec, outArg(*thyraVec));
  return *this;
}
예제 #26
0
RCP<const Basic> add(const vec_basic &a)
{
    SymEngine::umap_basic_num d;
    RCP<const Number> coef = zero;
    for (const auto &i : a) {
        Add::coef_dict_add_term(outArg(coef), d, one, i);
    }
    return Add::from_dict(coef, std::move(d));
}
예제 #27
0
bool GaloisFieldDict::gf_is_sqf() const
{
    if (dict_.empty())
        return true;
    integer_class LC;
    GaloisFieldDict monic;
    gf_monic(LC, outArg(monic));
    monic = monic.gf_gcd(monic.gf_diff());
    return monic.is_one();
}
예제 #28
0
파일: add.cpp 프로젝트: achabill/symengine
void Add::coef_dict_add_term(const Ptr<RCP<const Number>> &coef, umap_basic_num &d,
        const RCP<const Number> &c, const RCP<const Basic> &term)
{
    if (is_a_Number(*term)) {
        iaddnum(coef, mulnum(c, rcp_static_cast<const Number>(term)));
    } else if (is_a<Add>(*term)) {
        if (c->is_one()) {
            for (const auto &q: (rcp_static_cast<const Add>(term))->dict_)
                Add::dict_add_term(d, q.second, q.first);
            iaddnum(coef, rcp_static_cast<const Add>(term)->coef_);
        } else {
            Add::dict_add_term(d, c, term);
        }
    } else {
        RCP<const Number> coef2;
        RCP<const Basic> t;
        Add::as_coef_term(term, outArg(coef2), outArg(t));
        Add::dict_add_term(d, mulnum(c, coef2), t);
    }
}
예제 #29
0
파일: add.cpp 프로젝트: jrioux/csympy
// Adds (coef*t) to the dict "d"
// Assumption: "t" does not have any numerical coefficients, those are in "coef"
void Add::dict_add_term(umap_basic_int &d, const RCP<Number> &coef,
        const RCP<Basic> &t)
{
    auto it = d.find(t);
    if (it == d.end()) {
        // Not found, add it in if it is nonzero:
        if (!(coef->is_zero())) insert(d, t, coef);
    } else {
        iaddnum(outArg(it->second), coef);
        if (it->second->is_zero()) d.erase(it);
    }
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdVector, getMultiVectorLocalData,
  Scalar )
{
  out << "Test that we can grab MV data from Vector ...\n";

  typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
  RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
  const int procRank = Teuchos::DefaultComm<Ordinal>::getComm()->getRank();
  RCP<VectorBase<Scalar> > v = createMember(*vs);
  const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps();
  const Ordinal globalOffset = procRank * g_localDim;

  out << "Get non-const MV local data and set it ...\n";
  {
    ArrayRCP<Scalar> localValues;
    Ordinal leadingDim = -1;
    rcp_dynamic_cast<SpmdMultiVectorBase<Scalar> >(v,true)->getNonconstLocalData(
      outArg(localValues), outArg(leadingDim));
    TEST_EQUALITY(localValues.size(), g_localDim);
    TEST_EQUALITY(leadingDim, g_localDim);
    for (int i = 0; i < localValues.size(); ++i) {
      localValues[i] = globalOffset + i + 1;
    } 
  }
  const Ordinal n = vs->dim();
  TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>((n*(n+1))/2.0), tol);

  out << "Get const MV local data and check it ...\n";
  {
    ArrayRCP<const Scalar> localValues;
    Ordinal leadingDim = -1;
    rcp_dynamic_cast<const SpmdMultiVectorBase<Scalar> >(v,true)->getLocalData(
      outArg(localValues), outArg(leadingDim));
    TEST_EQUALITY(localValues.size(), g_localDim);
    TEST_EQUALITY(leadingDim, g_localDim);
    for (int i = 0; i < localValues.size(); ++i) {
      TEST_EQUALITY(localValues[i], as<Scalar>(globalOffset + i + 1));
    } 
  }
}