Dynare++ tensor library: changes to exception handling
- TL_RAISE now unconditionally raises an exception - rathe use TL_RAISE_IF at some places, to save a test in non-debug modetime-shift
parent
b72857d4ce
commit
790c56612c
|
@ -384,13 +384,9 @@ EquivalenceBundle::EquivalenceBundle(int nmax)
|
|||
const EquivalenceSet &
|
||||
EquivalenceBundle::get(int n) const
|
||||
{
|
||||
if (n > static_cast<int>(bundle.size()) || n < 1)
|
||||
{
|
||||
TL_RAISE("Equivalence set not found in EquivalenceBundle::get");
|
||||
return bundle[0];
|
||||
}
|
||||
else
|
||||
return bundle[n-1];
|
||||
TL_RAISE_IF(n > static_cast<int>(bundle.size()) || n < 1,
|
||||
"Equivalence set not found in EquivalenceBundle::get");
|
||||
return bundle[n-1];
|
||||
}
|
||||
|
||||
/* Get |curmax| which is a maximum size in the bundle, and generate for
|
||||
|
|
|
@ -62,7 +62,6 @@ std::unique_ptr<FTensor>
|
|||
UPSTensor::fold() const
|
||||
{
|
||||
TL_RAISE("Never should come to this place in UPSTensor::fold");
|
||||
return std::make_unique<FFSTensor>(0, 0, 0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -319,7 +318,6 @@ std::unique_ptr<UTensor>
|
|||
FPSTensor::unfold() const
|
||||
{
|
||||
TL_RAISE("Unfolding of FPSTensor not implemented");
|
||||
return std::make_unique<UFSTensor>(0, 0, 0);
|
||||
}
|
||||
|
||||
/* We only call |calcOffset| of the |PerTensorDimens2|. */
|
||||
|
|
|
@ -147,7 +147,7 @@ public:
|
|||
int
|
||||
getOffset(const IntSequence &v) const override
|
||||
{
|
||||
TL_RAISE("Not implemented error in IrregTensor::getOffset"); return 0;
|
||||
TL_RAISE("Not implemented error in IrregTensor::getOffset");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,11 +24,7 @@ SparseTensor::insert(const IntSequence &key, int r, double c)
|
|||
// check that pair |key| and |r| is unique
|
||||
auto last_pos = m.upper_bound(key);
|
||||
for (auto it = first_pos; it != last_pos; ++it)
|
||||
if ((*it).second.first == r)
|
||||
{
|
||||
TL_RAISE("Duplicate <key, r> insertion in SparseTensor::insert");
|
||||
return;
|
||||
}
|
||||
TL_RAISE_IF(it->second.first == r, "Duplicate <key, r> insertion in SparseTensor::insert");
|
||||
|
||||
m.insert(first_pos, Map::value_type(key, Item(r, c)));
|
||||
if (first_nz_row > r)
|
||||
|
|
|
@ -381,7 +381,6 @@ public:
|
|||
return _Stype::zero;
|
||||
|
||||
TL_RAISE("Wrong stack index in ZContainer::getType");
|
||||
return _Stype::zero;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -464,7 +463,6 @@ public:
|
|||
return _Stype::zero;
|
||||
|
||||
TL_RAISE("Wrong stack index in GContainer::getType");
|
||||
return _Stype::zero;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
the exceptions. If the |TL_DEBUG| is equal or higher than
|
||||
|TL_DEBUG_EXCEPTION|, the exception conditions are checked.
|
||||
|
||||
We define |TL_RAISE|, and |TL_RAISE_IF| macros which throw an instance
|
||||
of |TLException| if |TL_DEBUG >= TL_DEBUG_EXCEPTION|. The first is
|
||||
unconditional throw, the second is conditioned by a given
|
||||
expression. Note that if |TL_DEBUG < TL_DEBUG_EXCEPTION| then the code
|
||||
is compiled but evaluation of the condition is passed. If code is
|
||||
optimized, the optimizer also passes evaluation of |TL_DEBUG| and
|
||||
|TL_DEBUG_EXCEPTION| comparison (I hope).
|
||||
We define |TL_RAISE|, and |TL_RAISE_IF| macros which throw an instance of
|
||||
|TLException| (only if |TL_DEBUG >= TL_DEBUG_EXCEPTION| for the latter). The
|
||||
first is unconditional throw, the second is conditioned by a given
|
||||
expression. Note that if |TL_DEBUG < TL_DEBUG_EXCEPTION| then the code is
|
||||
compiled but evaluation of the condition is passed. If code is optimized,
|
||||
the optimizer also passes evaluation of |TL_DEBUG| and |TL_DEBUG_EXCEPTION|
|
||||
comparison (I hope).
|
||||
|
||||
We provide default values for |TL_DEBUG| and |TL_DEBUG_EXCEPTION|. */
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
|||
#endif
|
||||
|
||||
#define TL_RAISE(mes) \
|
||||
if (TL_DEBUG >= TL_DEBUG_EXCEPTION) throw TLException(__FILE__, __LINE__, mes);
|
||||
throw TLException(__FILE__, __LINE__, mes)
|
||||
|
||||
#define TL_RAISE_IF(expr, mes) \
|
||||
if (TL_DEBUG >= TL_DEBUG_EXCEPTION && (expr)) throw TLException(__FILE__, __LINE__, mes);
|
||||
|
|
Loading…
Reference in New Issue