Remove unneeded braces
parent
661e5c7e9f
commit
5b8b63924d
|
@ -280,28 +280,26 @@ Approximation::calcStochShift(Vector &out, double at_sigma) const
|
|||
|
||||
int dfac = 1;
|
||||
for (int d = 1; d <= rule_ders->getMaxDim(); d++, dfac *= d)
|
||||
{
|
||||
if (KOrder::is_even(d))
|
||||
{
|
||||
Symmetry sym{0, d, 0, 0};
|
||||
if (KOrder::is_even(d))
|
||||
{
|
||||
Symmetry sym{0, d, 0, 0};
|
||||
|
||||
// calculate F_u′ᵈ via ZAuxContainer
|
||||
auto ten = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(sym, nvs));
|
||||
ten->zeros();
|
||||
for (int l = 1; l <= d; l++)
|
||||
{
|
||||
const FSSparseTensor &f = model.getModelDerivatives().get(Symmetry{l});
|
||||
zaux.multAndAdd(f, *ten);
|
||||
}
|
||||
// calculate F_u′ᵈ via ZAuxContainer
|
||||
auto ten = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(sym, nvs));
|
||||
ten->zeros();
|
||||
for (int l = 1; l <= d; l++)
|
||||
{
|
||||
const FSSparseTensor &f = model.getModelDerivatives().get(Symmetry{l});
|
||||
zaux.multAndAdd(f, *ten);
|
||||
}
|
||||
|
||||
// multiply with shocks and add to result
|
||||
auto tmp = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(Symmetry{0, 0, 0, 0}, nvs));
|
||||
tmp->zeros();
|
||||
ten->contractAndAdd(1, *tmp, mom.get(Symmetry{d}));
|
||||
// multiply with shocks and add to result
|
||||
auto tmp = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(Symmetry{0, 0, 0, 0}, nvs));
|
||||
tmp->zeros();
|
||||
ten->contractAndAdd(1, *tmp, mom.get(Symmetry{d}));
|
||||
|
||||
out.add(pow(at_sigma, d)/dfac, tmp->getData());
|
||||
}
|
||||
}
|
||||
out.add(pow(at_sigma, d)/dfac, tmp->getData());
|
||||
}
|
||||
}
|
||||
|
||||
/* This method calculates and reports
|
||||
|
|
|
@ -532,14 +532,12 @@ DRFixPoint<t>::fillTensors(const _Tg &g, double sigma)
|
|||
g_yd->zeros();
|
||||
int kfact = 1;
|
||||
for (int k = 0; d+k <= g.getMaxDim(); k++, kfact *= k)
|
||||
{
|
||||
if (g.check(Symmetry{d, 0, 0, k}))
|
||||
{
|
||||
const _Ttensor &ten = g.get(Symmetry{d, 0, 0, k});
|
||||
double mult = pow(sigma, k)/dfact/kfact;
|
||||
g_yd->add(mult, ten);
|
||||
}
|
||||
}
|
||||
if (g.check(Symmetry{d, 0, 0, k}))
|
||||
{
|
||||
const _Ttensor &ten = g.get(Symmetry{d, 0, 0, k});
|
||||
double mult = pow(sigma, k)/dfact/kfact;
|
||||
g_yd->add(mult, ten);
|
||||
}
|
||||
this->insert(std::move(g_yd));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,17 +256,15 @@ FGSTensor::FGSTensor(const FFSTensor &t, const IntSequence &ss,
|
|||
Tensor::index ubi(t, ub);
|
||||
++ubi;
|
||||
for (Tensor::index run = lbi; run != ubi; ++run)
|
||||
{
|
||||
if (lb.lessEq(run.getCoor()) && run.getCoor().lessEq(ub))
|
||||
{
|
||||
IntSequence c(run.getCoor());
|
||||
c.add(-1, lb);
|
||||
Tensor::index ind(*this, c);
|
||||
TL_RAISE_IF(*ind < 0 || *ind >= ncols(),
|
||||
"Internal error in slicing constructor of FGSTensor");
|
||||
copyColumn(t, *run, *ind);
|
||||
}
|
||||
}
|
||||
if (lb.lessEq(run.getCoor()) && run.getCoor().lessEq(ub))
|
||||
{
|
||||
IntSequence c(run.getCoor());
|
||||
c.add(-1, lb);
|
||||
Tensor::index ind(*this, c);
|
||||
TL_RAISE_IF(*ind < 0 || *ind >= ncols(),
|
||||
"Internal error in slicing constructor of FGSTensor");
|
||||
copyColumn(t, *run, *ind);
|
||||
}
|
||||
}
|
||||
|
||||
// FGSTensor conversion from GSSparseTensor
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright © 2004 Ondra Kamenik
|
||||
* Copyright © 2019 Dynare Team
|
||||
* Copyright © 2019-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -388,28 +388,26 @@ KronProdAllOptim::optimizeOrder()
|
|||
{
|
||||
int swaps = 0;
|
||||
for (int j = 0; j < dimen()-1; j++)
|
||||
{
|
||||
if (static_cast<double>(kpd.rows[j])/kpd.cols[j]
|
||||
< static_cast<double>(kpd.rows[j+1])/kpd.cols[j+1])
|
||||
{
|
||||
// swap dimensions and matrices at j and j+1
|
||||
int s = kpd.rows[j+1];
|
||||
kpd.rows[j+1] = kpd.rows[j];
|
||||
kpd.rows[j] = s;
|
||||
s = kpd.cols[j+1];
|
||||
kpd.cols[j+1] = kpd.cols[j];
|
||||
kpd.cols[j] = s;
|
||||
const TwoDMatrix *m = matlist[j+1];
|
||||
matlist[j+1] = matlist[j];
|
||||
matlist[j] = m;
|
||||
if (static_cast<double>(kpd.rows[j])/kpd.cols[j]
|
||||
< static_cast<double>(kpd.rows[j+1])/kpd.cols[j+1])
|
||||
{
|
||||
// swap dimensions and matrices at j and j+1
|
||||
int s = kpd.rows[j+1];
|
||||
kpd.rows[j+1] = kpd.rows[j];
|
||||
kpd.rows[j] = s;
|
||||
s = kpd.cols[j+1];
|
||||
kpd.cols[j+1] = kpd.cols[j];
|
||||
kpd.cols[j] = s;
|
||||
const TwoDMatrix *m = matlist[j+1];
|
||||
matlist[j+1] = matlist[j];
|
||||
matlist[j] = m;
|
||||
|
||||
// project the swap to the permutation ‘oper’
|
||||
s = oper.getMap()[j+1];
|
||||
oper.getMap()[j+1] = oper.getMap()[j];
|
||||
oper.getMap()[j] = s;
|
||||
swaps++;
|
||||
}
|
||||
}
|
||||
// project the swap to the permutation ‘oper’
|
||||
s = oper.getMap()[j+1];
|
||||
oper.getMap()[j+1] = oper.getMap()[j];
|
||||
oper.getMap()[j] = s;
|
||||
swaps++;
|
||||
}
|
||||
if (swaps == 0)
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright © 2004 Ondra Kamenik
|
||||
* Copyright © 2019 Dynare Team
|
||||
* Copyright © 2019-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -237,23 +237,21 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
|
|||
auto lbi = t.getMap().lower_bound(lb_srt);
|
||||
auto ubi = t.getMap().upper_bound(ub_srt);
|
||||
for (auto run = lbi; run != ubi; ++run)
|
||||
{
|
||||
if (lb_srt.lessEq(run->first) && run->first.lessEq(ub_srt))
|
||||
{
|
||||
IntSequence c(run->first);
|
||||
c.add(-1, lb_srt);
|
||||
unsort.apply(c);
|
||||
for (auto &i : pp)
|
||||
{
|
||||
IntSequence cp(coor.size());
|
||||
i.apply(c, cp);
|
||||
Tensor::index ind(*this, cp);
|
||||
TL_RAISE_IF(*ind < 0 || *ind >= ncols(),
|
||||
"Internal error in slicing constructor of UPSTensor");
|
||||
get(run->second.first, *ind) = run->second.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lb_srt.lessEq(run->first) && run->first.lessEq(ub_srt))
|
||||
{
|
||||
IntSequence c(run->first);
|
||||
c.add(-1, lb_srt);
|
||||
unsort.apply(c);
|
||||
for (auto &i : pp)
|
||||
{
|
||||
IntSequence cp(coor.size());
|
||||
i.apply(c, cp);
|
||||
Tensor::index ind(*this, cp);
|
||||
TL_RAISE_IF(*ind < 0 || *ind >= ncols(),
|
||||
"Internal error in slicing constructor of UPSTensor");
|
||||
get(run->second.first, *ind) = run->second.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Here we calculate the maximum offsets in each folded dimension
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright © 2004 Ondra Kamenik
|
||||
* Copyright © 2019 Dynare Team
|
||||
* Copyright © 2019-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -44,20 +44,18 @@ USubTensor::USubTensor(const TensorDimens &bdims,
|
|||
const EquivalenceSet &eset = TLStatic::getEquiv(bdims.dimen());
|
||||
zeros();
|
||||
for (const auto &it : eset)
|
||||
{
|
||||
if (it.numClasses() == hdims.dimen())
|
||||
{
|
||||
Permutation per(it);
|
||||
std::vector<const FGSTensor *> ts
|
||||
= cont.fetchTensors(bdims.getSym(), it);
|
||||
for (int i = 0; i < static_cast<int>(lst.size()); i++)
|
||||
{
|
||||
IntSequence perindex(lst[i].size());
|
||||
per.apply(lst[i], perindex);
|
||||
addKronColumn(i, ts, perindex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it.numClasses() == hdims.dimen())
|
||||
{
|
||||
Permutation per(it);
|
||||
std::vector<const FGSTensor *> ts
|
||||
= cont.fetchTensors(bdims.getSym(), it);
|
||||
for (int i = 0; i < static_cast<int>(lst.size()); i++)
|
||||
{
|
||||
IntSequence perindex(lst[i].size());
|
||||
per.apply(lst[i], perindex);
|
||||
addKronColumn(i, ts, perindex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This makes a Kronecker product of appropriate columns from tensors in ‘fs’
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright © 2004 Ondra Kamenik
|
||||
* Copyright © 2019 Dynare Team
|
||||
* Copyright © 2019-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -230,15 +230,12 @@ GSSparseTensor::GSSparseTensor(const FSSparseTensor &t, const IntSequence &ss,
|
|||
auto lbi = t.getMap().lower_bound(lb);
|
||||
auto ubi = t.getMap().upper_bound(ub);
|
||||
for (auto run = lbi; run != ubi; ++run)
|
||||
{
|
||||
if (lb.lessEq(run->first) && run->first.lessEq(ub))
|
||||
{
|
||||
IntSequence c(run->first);
|
||||
c.add(-1, lb);
|
||||
insert(c, run->second.first, run->second.second);
|
||||
}
|
||||
}
|
||||
|
||||
if (lb.lessEq(run->first) && run->first.lessEq(ub))
|
||||
{
|
||||
IntSequence c(run->first);
|
||||
c.add(-1, lb);
|
||||
insert(c, run->second.first, run->second.second);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright © 2004 Ondra Kamenik
|
||||
* Copyright © 2019 Dynare Team
|
||||
* Copyright © 2019-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -120,26 +120,24 @@ WorkerFoldMAASparse1::operator()(std::mutex &mut)
|
|||
IntSequence percoor(coor.size());
|
||||
per.apply(coor, percoor);
|
||||
for (const auto &it : eset)
|
||||
{
|
||||
if (it.numClasses() == t.dimen())
|
||||
{
|
||||
StackProduct<FGSTensor> sp(cont, it, out.getSym());
|
||||
if (!sp.isZero(percoor))
|
||||
{
|
||||
KronProdStack<FGSTensor> kp(sp, percoor);
|
||||
kp.optimizeOrder();
|
||||
const Permutation &oper = kp.getPer();
|
||||
if (Permutation(oper, per) == iden)
|
||||
if (it.numClasses() == t.dimen())
|
||||
{
|
||||
StackProduct<FGSTensor> sp(cont, it, out.getSym());
|
||||
if (!sp.isZero(percoor))
|
||||
{
|
||||
KronProdStack<FGSTensor> kp(sp, percoor);
|
||||
kp.optimizeOrder();
|
||||
const Permutation &oper = kp.getPer();
|
||||
if (Permutation(oper, per) == iden)
|
||||
{
|
||||
FPSTensor fps(out.getDims(), it, slice, kp);
|
||||
{
|
||||
FPSTensor fps(out.getDims(), it, slice, kp);
|
||||
{
|
||||
std::unique_lock<std::mutex> lk{mut};
|
||||
fps.addTo(out);
|
||||
}
|
||||
std::unique_lock<std::mutex> lk{mut};
|
||||
fps.addTo(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue