Skip to content

Commit

Permalink
#314 supplemental: cov and corr safe (U)Int64 aggregations when argum…
Browse files Browse the repository at this point in the history
…ents are ints.
  • Loading branch information
MaartenHilferink committed Oct 6, 2023
1 parent ca23a86 commit c8c857c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
14 changes: 9 additions & 5 deletions clc/dll/include/AggrBinStructNum.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ template <typename T>
struct corr_accumulation_type : cov_accumulation_type<T>
{
using corr_type = typename cov_accumulation_type<T>::cov_type;
using sum_type = typename acc_type<T>::type;
using agregator = typename aggr_type<T>::type;

corr_accumulation_type(): xx(), yy() {}
Expand All @@ -172,25 +173,28 @@ struct corr_accumulation_type : cov_accumulation_type<T>
}
friend corr_type make_result(const corr_accumulation_type& output) { return output.operator corr_type(); } // move casting stuff here

agregator xx, yy;
sum_type xx, yy;
};

template <typename T>
struct binary_assign_corr: binary_assign<corr_accumulation_type<T>, T, T>
{
static ConstUnitRef unit_creator(const AbstrOperGroup* gr, const ArgSeqType& args) { return default_unit_creator<T>(); }

typedef typename aggr_type<T>::type agregator;
using sum_type = typename acc_type<T>::type;
using agregator = typename aggr_type<T>::type;

void operator () (typename binary_assign_corr::assignee_ref a, typename binary_assign_corr::arg1_cref x, typename binary_assign_corr::arg2_cref y) const
void operator () (typename binary_assign_corr::assignee_ref a, cref_t<T> x, cref_t<T> y) const
{
m_CovAssign(a, x, y);
a.xx += agregator(x)*agregator(x);
a.yy += agregator(y)*agregator(y);
a.xx = m_SafePlus(a.xx, m_MulX(x, x));
a.yy = m_SafePlus(a.yy, m_MulX(y, y));
}

private:
binary_assign_cov<T> m_CovAssign;
mulx_func<T> m_MulX;
safe_plus<sum_type> m_SafePlus;
};

template <class T>
Expand Down
6 changes: 3 additions & 3 deletions clc/dll/include/AggrUniStructNum.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ struct var_accumulation_type
typedef typename aggr_type<sum_type>::type var_type;
typedef typename scalar_of<var_type>::type var_scalar_type;

var_accumulation_type(): n(), x(), xx() {}
var_accumulation_type() {}
var_accumulation_type(count_type n_, sum_type x_, sum_type xx_): n(n_), x(x_), xx(xx_) {}

operator var_type() const
Expand All @@ -367,8 +367,8 @@ struct var_accumulation_type
return res;
}

count_type n;
sum_type x, xx;
count_type n = 0;
sum_type x = sum_type(), xx = sum_type();
};

template <typename T>
Expand Down
22 changes: 20 additions & 2 deletions tic/dll/src/Explain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,15 @@ namespace Explain { // local defs
{
if (!isFirst)
NewLine(stream);
stream << (m_Expr.size() > 1 ? "Addition " : "Factors");
switch(m_Expr.size())
{
case 0:
return;
case 1:
stream << mySSPrintF("Summary of %d factors", m_Expr[0].second.size()).c_str();
default:
stream << mySSPrintF("Summary of %d terms ", m_Expr.size()).c_str();
}
PrintSeqNr(stream);
stream << ": " << m_CalcPtr->GetAsFLispExprOrg(FormattingFlags::ThousandSeparator).c_str();
NewLine(stream);
Expand Down Expand Up @@ -1108,12 +1116,22 @@ namespace Explain { // local defs
}
}
}

void UnionOfAndsExplanation::GetDescrImpl(CalcExplImpl* self, OutStreamBase& stream, bool isFirst, bool showHidden) const
{
if (!isFirst)
NewLine(stream);

stream << (m_Expr.size() > 1 ? "Union of conditions " : "Conditions");
switch (m_Expr.size())
{
case 0:
return;
case 1:
stream << mySSPrintF("Summary of %d conjunctions of boolean values", m_Expr[0].size()).c_str();
default:
stream << mySSPrintF("Summary of %d disjuctions of (conjuncted) boolean values", m_Expr.size()).c_str();
}

PrintSeqNr(stream);
stream << ": " << m_CalcPtr->GetAsFLispExprOrg(FormattingFlags::ThousandSeparator).c_str();
NewLine(stream);
Expand Down

0 comments on commit c8c857c

Please sign in to comment.