Skip to content

Commit

Permalink
Detect unused complex types
Browse files Browse the repository at this point in the history
A new WARN_UNUSED macro triggers warnings when common container classes are unused.
This can only apply to classes for which ctors are known to have no side effects.
  • Loading branch information
jschueller committed Apr 26, 2024
1 parent b12f3aa commit 6005c95
Show file tree
Hide file tree
Showing 147 changed files with 151 additions and 393 deletions.
21 changes: 12 additions & 9 deletions lib/include/openturns/OTdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@
# ifdef __GNUC__

# ifdef SWIG
# define DEPRECATED
# define UNUSED
# define NOTHROW
# define OT_DEPRECATED
# define OT_UNUSED
# define OT_NOTHROW
# define OT_WARN_UNUSED
# else /* not SWIG */
# define DEPRECATED __attribute__ ((deprecated))
# define UNUSED __attribute__ ((unused))
# define NOTHROW __attribute__ ((nothrow))
# define OT_DEPRECATED __attribute__ ((deprecated))
# define OT_UNUSED __attribute__ ((unused))
# define OT_NOTHROW __attribute__ ((nothrow))
# define OT_WARN_UNUSED __attribute__ ((warn_unused))
# endif /* SWIG */

# else /* not __GNUC_ */

# define DEPRECATED
# define UNUSED
# define NOTHROW
# define OT_DEPRECATED
# define OT_UNUSED
# define OT_NOTHROW
# define OT_WARN_UNUSED

# endif /* __GNUC_ */

Expand Down
5 changes: 1 addition & 4 deletions lib/src/Base/Algo/CorrectedLeaveOneOut.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ Scalar CorrectedLeaveOneOut::run(const Sample & y,
return FittingAlgorithmImplementation::run(y, weight, indices, proxy);
}

Scalar CorrectedLeaveOneOut::run(LeastSquaresMethod & method,
const Sample & y) const
Scalar CorrectedLeaveOneOut::run(LeastSquaresMethod & method, const Sample & y) const
{
const Sample x(method.getInputSample());

const UnsignedInteger sampleSize = y.getSize();

if (y.getDimension() != 1) throw InvalidArgumentException(HERE) << "Output sample should be unidimensional (dim=" << y.getDimension() << ").";
Expand Down
5 changes: 1 addition & 4 deletions lib/src/Base/Algo/KFold.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ Scalar KFold::run(const Sample & y,
return FittingAlgorithmImplementation::run(y, weight, indices, proxy);
}

Scalar KFold::run(LeastSquaresMethod & method,
const Sample & y) const
Scalar KFold::run(LeastSquaresMethod & method, const Sample & y) const
{
const Sample x(method.getInputSample());
const FunctionCollection basis(method.getBasis());

const UnsignedInteger sampleSize = x.getSize();
const Scalar variance = y.computeVariance()[0];

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Common/openturns/ComparisonOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BEGIN_NAMESPACE_OPENTURNS
* The implementation defined what comparison is actually performed.
* @see ComparisonOperatorImplementation
*/
class OT_API ComparisonOperator
class OT_API OT_WARN_UNUSED ComparisonOperator
: public TypedInterfaceObject<ComparisonOperatorImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Func/openturns/Function.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BEGIN_NAMESPACE_OPENTURNS
* the function, the gradient or the hessian.
* @see FunctionImplementation
*/
class OT_API Function
class OT_API OT_WARN_UNUSED Function
: public TypedInterfaceObject<FunctionImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Geom/openturns/Domain.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BEGIN_NAMESPACE_OPENTURNS
*
* A class that holds a domain
*/
class OT_API Domain
class OT_API OT_WARN_UNUSED Domain
: public TypedInterfaceObject<DomainImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Geom/openturns/Interval.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BEGIN_NAMESPACE_OPENTURNS
*
* A class that holds a collection of interval
*/
class OT_API Interval
class OT_API OT_WARN_UNUSED Interval
: public DomainImplementation
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Geom/openturns/Mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BEGIN_NAMESPACE_OPENTURNS
*
* A class that holds a mesh
*/
class OT_API Mesh
class OT_API OT_WARN_UNUSED Mesh
: public PersistentObject
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Geom/openturns/RegularGrid.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BEGIN_NAMESPACE_OPENTURNS
* end time = start time + ( timeStep * steps )
*/

class OT_API RegularGrid
class OT_API OT_WARN_UNUSED RegularGrid
: public Mesh
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Graph/openturns/Drawable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN_NAMESPACE_OPENTURNS
* Drawable is an interface to implement graphics
*/

class OT_API Drawable :
class OT_API OT_WARN_UNUSED Drawable :
public TypedInterfaceObject<DrawableImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Graph/openturns/Graph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN_NAMESPACE_OPENTURNS
* and manages drawables to be plotted on the same window
*/

class OT_API Graph :
class OT_API OT_WARN_UNUSED Graph :
public TypedInterfaceObject<GraphImplementation>
{

Expand Down
1 change: 0 additions & 1 deletion lib/src/Base/IterativeStat/IterativeMoments.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ Point IterativeMoments::getKurtosis() const

Point result(dimension_);
const Point varianceEstimator(getVariance());
const Point skewnessEstimator(getSkewness());
const UnsignedInteger n = iteration_;

const Scalar factor1 = n * (n + 1.0) / ((n - 1.0) * (n - 2.0) * (n - 3.0));
Expand Down
5 changes: 1 addition & 4 deletions lib/src/Base/Optim/BonminProblem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ bool BonminProblem::get_nlp_info(int & n,
return true;
}

bool BonminProblem::get_variables_types( int n,
VariableTypeTable var_types)
bool BonminProblem::get_variables_types(int n, VariableTypeTable var_types)
{
Indices variablesTypes(optimProblem_.getVariablesType());

// Conversion from OptimizationProblemImplementation::VariableType to TMINLP::VariableType
for (int i = 0; i < n; ++i)
{
Expand Down
1 change: 0 additions & 1 deletion lib/src/Base/Optim/Pagmo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct PagmoProblem

// pagmo wants the integer components grouped at the end, so renumbering is in order
Indices renum;
Indices renum_inv;
const Indices types(algorithm_->getProblem().getVariablesType());
for (UnsignedInteger i = 0; i < types.getSize(); ++ i)
if (types[i] == OptimizationProblemImplementation::CONTINUOUS)
Expand Down
1 change: 0 additions & 1 deletion lib/src/Base/Stat/DiracCovarianceModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ DiracCovarianceModel::DiracCovarianceModel(const UnsignedInteger inputDimension,
amplitude_[i] = sqrt(covariance(i, i));
if (!covariance.isDiagonal())
{
CorrelationMatrix correlation(outputDimension_);
for(UnsignedInteger j = 0; j < outputDimension_; ++j)
for(UnsignedInteger i = j; i < outputDimension_; ++i)
outputCorrelation_(i, j) = covariance(i, j) / (amplitude_[i] * amplitude_[j]);
Expand Down
1 change: 0 additions & 1 deletion lib/src/Base/Stat/TensorizedCovarianceModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void TensorizedCovarianceModel::setCollection(const CovarianceModelCollection &
// Check if the given models have the same input dimension
const UnsignedInteger size = collection.getSize();
if (!(size > 0)) throw InvalidArgumentException(HERE) << "TensorizedCovarianceModel::setCollection: the collection must have a positive size, here size=0";
Point amplitude(0);
inputDimension_ = collection[0].getInputDimension();
// Get dimension: should be the same for all elements
// Since 1.17, collection should be a list of 1d output models
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Base/Stat/TimeSeries.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ TimeSeries & TimeSeries::add(const Sample & sample)
/* Append another time series to the collection. The time grids must match (one follows the other) */
TimeSeries & TimeSeries::add(const TimeSeries & continuer)
{
Sample vertices(mesh_.getVertices());
if ((timeStep_ != continuer.timeStep_) || (start_ + n_ * timeStep_ != continuer.start_)) LOGWARN(OSS() << "The continuer does not have a compatible time grid. Using the values only.");
if ((timeStep_ != continuer.timeStep_) || (start_ + n_ * timeStep_ != continuer.start_))
LOGWARN(OSS() << "The continuer does not have a compatible time grid. Using the values only.");
return add(continuer.getValues());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/CorrelationMatrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class CorrelationMatrix
*/

class OT_API CorrelationMatrix
class OT_API OT_WARN_UNUSED CorrelationMatrix
: public CovarianceMatrix
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/CovarianceMatrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class CovarianceMatrix
*/

class OT_API CovarianceMatrix
class OT_API OT_WARN_UNUSED CovarianceMatrix
: public SymmetricMatrix
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/CovarianceModel.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class CovarianceModel
*/

class OT_API CovarianceModel
class OT_API OT_WARN_UNUSED CovarianceModel
: public TypedInterfaceObject<CovarianceModelImplementation>
{

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/HistoryStrategy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class HistoryStrategy
*/

class OT_API HistoryStrategy
class OT_API OT_WARN_UNUSED HistoryStrategy
: public TypedInterfaceObject<HistoryStrategyImplementation>
{

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/ProcessSample.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN_NAMESPACE_OPENTURNS
*
* An interface for time series
*/
class OT_API ProcessSample
class OT_API OT_WARN_UNUSED ProcessSample
: public TypedInterfaceObject<ProcessSampleImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Stat/openturns/Sample.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class Sample
*/

class OT_API Sample
class OT_API OT_WARN_UNUSED Sample
: public TypedInterfaceObject<SampleImplementation>
{
CLASSNAME
Expand Down
3 changes: 1 addition & 2 deletions lib/src/Base/Stat/openturns/TestResult.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ BEGIN_NAMESPACE_OPENTURNS
* TestResult implements the result of a statistical test
*/

class OT_API TestResult :
public PersistentObject
class OT_API OT_WARN_UNUSED TestResult : public PersistentObject
{
CLASSNAME

Expand Down
3 changes: 1 addition & 2 deletions lib/src/Base/Stat/openturns/TimeSeries.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ BEGIN_NAMESPACE_OPENTURNS
* @class TimeSeries
*/

class OT_API TimeSeries
: public FieldImplementation
class OT_API OT_WARN_UNUSED TimeSeries : public FieldImplementation
{
CLASSNAME

Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Type/openturns/Collection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ OStream & operator << (OStream & OS,


template <class T>
class Collection
class OT_WARN_UNUSED Collection
{
public:

Expand Down
3 changes: 1 addition & 2 deletions lib/src/Base/Type/openturns/Description.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ BEGIN_NAMESPACE_OPENTURNS
* Description is a collection of string for human usage
*/

class OT_API Description :
public PersistentCollection<String>
class OT_API OT_WARN_UNUSED Description : public PersistentCollection<String>
{
CLASSNAME
public:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Type/openturns/Indices.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN_NAMESPACE_OPENTURNS
*
* A class that holds a collection of indices
*/
class OT_API Indices :
class OT_API OT_WARN_UNUSED Indices :
public PersistentCollection<UnsignedInteger>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Type/openturns/Matrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Sample;
* Matrix implements the classical mathematical matrix
*/

class OT_API Matrix :
class OT_WARN_UNUSED OT_API Matrix :
public TypedInterfaceObject<MatrixImplementation>
{
CLASSNAME
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Base/Type/openturns/Point.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BEGIN_NAMESPACE_OPENTURNS
* Point implements the classical mathematical point
*/

class OT_API Point
class OT_API OT_WARN_UNUSED Point
: public PersistentCollection<Scalar>
{
CLASSNAME
Expand Down
4 changes: 1 addition & 3 deletions lib/src/Base/Type/openturns/Tensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class TensorImplementation;
* Tensor implements the classical mathematical Tensor
*/

class OT_API Tensor :
public TypedInterfaceObject<TensorImplementation>

class OT_API OT_WARN_UNUSED Tensor : public TypedInterfaceObject<TensorImplementation>
{
CLASSNAME

Expand Down
2 changes: 0 additions & 2 deletions lib/src/Uncertainty/Algorithm/Analytical/AnalyticalResult.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@ Graph AnalyticalResult::drawSensitivity(const Sensitivity & sensitivity,
// Create an empty graph
Graph sensitivityGraph("Sensitivity", "parameters", "sensitivities", true, "topright");

BarPlot sensitivityBarPlot(Sample(0, 2), shift, "");

// Create the barplots
const UnsignedInteger sensitivitySize = sensitivity.getSize();
for (UnsignedInteger collectionIndex = 0; collectionIndex < sensitivitySize; ++collectionIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ String FunctionalChaosSobolIndices::__repr_markdown__() const
oss << FunctionalChaosSobolIndices::GetClassName() << "\n";

const Indices indices(functionalChaosResult_.getIndices());
const Sample coefficients(functionalChaosResult_.getCoefficients());
const UnsignedInteger basisSize = indices.getSize();
EnumerateFunction enumerateFunction(functionalChaosResult_.getOrthogonalBasis().getEnumerateFunction());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ Scalar GeneralLinearModelAlgorithm::maximizeReducedLogLikelihood()
{
// initial guess
Point initialParameters(reducedCovarianceModel_.getParameter());
Indices initialActiveParameters(reducedCovarianceModel_.getActiveParameter());
// We use the functional form of the log-likelihood computation to benefit from the cache mechanism
Function reducedLogLikelihoodFunction(getObjectiveFunction());
const Bool noNumericalOptimization = initialParameters.getSize() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ void KrigingResult::computePhi() const
{
// Nothing to do if the design matrix has already been computed
if (Gt_.getNbRows() != 0) return;
Matrix Q;
LOGINFO("Solve linear system L * phi= F");
Matrix phi;
if (0 != covarianceCholeskyFactor_.getNbRows())
Expand All @@ -215,7 +214,7 @@ void KrigingResult::computePhi() const
// Compute QR decomposition of Phi_
LOGINFO("Compute the QR decomposition of phi");
Matrix G;
Q = phi.computeQR(G);
phi.computeQR(G);
Gt_ = G.transpose();
phiT_ = phi.transpose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ LinearModelAlgorithm::LinearModelAlgorithm(const Sample & inputSample,
try
{
// the sample description may contain invalid variable names
const SymbolicFunction constant(inputDescription, Description(1, "1"));
SymbolicFunction(inputDescription, Description({"1"}));
}
catch (const InvalidArgumentException &)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ Graph LinearModelAnalysis::drawCookVsLeverages() const
graph.add(text);
}
const Interval boundingBox(graph.getBoundingBox());
const Point lowerBound(boundingBox.getLowerBound());
const Point upperBound(boundingBox.getUpperBound());
// Add contour plot
Point isovalues(6);
Expand Down
1 change: 0 additions & 1 deletion lib/src/Uncertainty/Algorithm/Sensitivity/FAST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ void FAST::run() const
for (UnsignedInteger i = 0; i < nbIn; ++ i)
phi_i[i] = 2. * M_PI * RandomGenerator::Generate();

Point xi_s(nbIn);
Sample output(0, nbOut);

// for each block ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ Sample MauntzKucherenkoSensitivityAlgorithm::computeIndices(const Sample & sampl

// Use reference samples
// Compute muA = mean(yA)
const Sample yA(sample, 0, size);
const Point muA(yA.computeMean());

// Compute crossMean
const Point yADotyB(computeSumDotSamples(sample, size_, 0, size_));
Expand Down
Loading

0 comments on commit 6005c95

Please sign in to comment.