[pyAgrum] methods pyAgrum.DiscreteVariable.toDiscretized/toLabelized/toRange…

[pyAgrum] methods pyAgrum.DiscreteVariable.toDiscretized/toLabelized/toRange copy the variable instead of giving a (not readonly) reference
parent cd82bee1
......@@ -30,7 +30,6 @@ CHANGE_THEN_RETURN_SELF(sq)
CHANGE_THEN_RETURN_SELF(scale)
CHANGE_THEN_RETURN_SELF(translate)
CHANGE_THEN_RETURN_SELF(normalizeAsCPT)
CHANGE_THEN_RETURN_SELF(set)
%rename ("$ignore", fullname=1) gum::Potential<double>::margSumOut(const Set<const DiscreteVariable*>& del_vars) const;
%rename ("$ignore", fullname=1) gum::Potential<double>::margProdOut(const Set<const DiscreteVariable*>& del_vars) const;
......
......@@ -74,7 +74,6 @@ interface generator."
%pythoncode %{
Potential = Potential_double
Potential = Potential_double
randomDistribution = randomDistribution_double
......
......@@ -156,6 +156,8 @@ class TestFeatures(BayesNetTestCase):
self.assertEqual(str(bn.variable(0)), "HISTORY<TRUE,FALSE>")
bn.variable(0).toLabelizedVar().changeLabel(0, "toto")
self.assertNotEqual(str(bn.variable(0)), "HISTORY<toto,FALSE>")
bn.changeVariableLabel(0, "TRUE", "toto")
self.assertEqual(str(bn.variable(0)), "HISTORY<toto,FALSE>")
def testStringAccessors(self):
......
......@@ -133,98 +133,19 @@ namespace std {
/* CLASS EXTENSIONS */
%extend gum::DiscreteVariable {
gum::LabelizedVariable & toLabelizedVar() {
return dynamic_cast<gum::LabelizedVariable&> ( * ( self ) );
gum::LabelizedVariable toLabelizedVar() {
return gum::LabelizedVariable(* dynamic_cast<gum::LabelizedVariable*>(self ));
}
gum::RangeVariable & toRangeVar() {
return dynamic_cast<gum::RangeVariable&> ( * ( self ) );
gum::RangeVariable toRangeVar() {
return gum::RangeVariable(* dynamic_cast<gum::RangeVariable*>(self ));
}
gum::DiscretizedVariable<double>& toDiscretizedVar() {
return dynamic_cast<gum::DiscretizedVariable<double> &> ( * ( self ) );
gum::DiscretizedVariable<double> toDiscretizedVar() {
return gum::DiscretizedVariable<double>(* dynamic_cast<gum::DiscretizedVariable<double> *> (self ));
}
}
%define ADD_APPROXIMATIONSCHEME_API(parent,classname...)
%extend classname {
using parent::setVerbosity;
using parent::setEpsilon;
using parent::setMinEpsilonRate;
using parent::setMaxIter;
using parent::setMaxTime;
using parent::setPeriodSize;
using parent::verbosity;
using parent::epsilon;
using parent::minEpsilonRate;
using parent::maxIter;
using parent::maxTime;
using parent::periodSize;
using parent::nbrIterations;
using parent::currentTime;
using parent::messageApproximationScheme;
using parent::history;
const gum::IApproximationSchemeConfiguration& asIApproximationSchemeConfiguration() const {
return *(dynamic_cast<const gum::IApproximationSchemeConfiguration *>(self));
}
}
%enddef
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::GibbsSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::ImportanceSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::WeightedSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::MonteCarloSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::ImportanceSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::WeightedSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::GibbsSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::MonteCarloSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopyBeliefPropagation<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::GibbsKL<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::credal::CNMonteCarloSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::credal::CNLoopyPropagation<double>)
ADD_APPROXIMATIONSCHEME_API(gum::learning::genericBNLearner,gum::learning::BNLearner<double>)
%extend gum::learning::BNLearner<double> {
using gum::learning::genericBNLearner::setMaxTime;
using gum::learning::genericBNLearner::maxTime;
using gum::learning::genericBNLearner::currentTime;
using gum::learning::genericBNLearner::learnDAG;
using gum::learning::genericBNLearner::names;
using gum::learning::genericBNLearner::modalities;
using gum::learning::genericBNLearner::idFromName;
using gum::learning::genericBNLearner::nameFromId;
using gum::learning::genericBNLearner::useScoreAIC;
using gum::learning::genericBNLearner::useScoreBD;
using gum::learning::genericBNLearner::useScoreBDeu;
using gum::learning::genericBNLearner::useScoreBIC;
using gum::learning::genericBNLearner::useScoreK2;
using gum::learning::genericBNLearner::useScoreLog2Likelihood;
using gum::learning::genericBNLearner::setAprioriWeight;
using gum::learning::genericBNLearner::useNoApriori;
using gum::learning::genericBNLearner::useAprioriSmoothing;
using gum::learning::genericBNLearner::useAprioriDirichlet;
using gum::learning::genericBNLearner::useGreedyHillClimbing;
using gum::learning::genericBNLearner::useLocalSearchWithTabuList;
using gum::learning::genericBNLearner::useK2;
using gum::learning::genericBNLearner::setMaxIndegree;
using gum::learning::genericBNLearner::setSliceOrder;
using gum::learning::genericBNLearner::addForbiddenArc;
using gum::learning::genericBNLearner::eraseForbiddenArc;
using gum::learning::genericBNLearner::addMandatoryArc;
using gum::learning::genericBNLearner::addMandatoryArc;
using gum::learning::genericBNLearner::eraseMandatoryArc;
}
%include "forUsing.i"
......
// this file is for giving access to methods defined in ancestor.
%define ADD_APPROXIMATIONSCHEME_API(parent,classname...)
%extend classname {
using parent::setVerbosity;
using parent::setEpsilon;
using parent::setMinEpsilonRate;
using parent::setMaxIter;
using parent::setMaxTime;
using parent::setPeriodSize;
using parent::verbosity;
using parent::epsilon;
using parent::minEpsilonRate;
using parent::maxIter;
using parent::maxTime;
using parent::periodSize;
using parent::nbrIterations;
using parent::currentTime;
using parent::messageApproximationScheme;
using parent::history;
const gum::IApproximationSchemeConfiguration& asIApproximationSchemeConfiguration() const {
return *(dynamic_cast<const gum::IApproximationSchemeConfiguration *>(self));
}
}
%enddef
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::GibbsSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::ImportanceSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::WeightedSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::MonteCarloSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::ImportanceSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::WeightedSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::GibbsSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopySamplingInference<double,gum::MonteCarloSampling>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::LoopyBeliefPropagation<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::GibbsKL<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::credal::CNMonteCarloSampling<double>)
ADD_APPROXIMATIONSCHEME_API(gum::ApproximationScheme,gum::credal::CNLoopyPropagation<double>)
ADD_APPROXIMATIONSCHEME_API(gum::learning::genericBNLearner,gum::learning::BNLearner<double>)
%extend gum::learning::BNLearner<double> {
using gum::learning::genericBNLearner::setMaxTime;
using gum::learning::genericBNLearner::maxTime;
using gum::learning::genericBNLearner::currentTime;
using gum::learning::genericBNLearner::learnDAG;
using gum::learning::genericBNLearner::names;
using gum::learning::genericBNLearner::modalities;
using gum::learning::genericBNLearner::idFromName;
using gum::learning::genericBNLearner::nameFromId;
using gum::learning::genericBNLearner::useScoreAIC;
using gum::learning::genericBNLearner::useScoreBD;
using gum::learning::genericBNLearner::useScoreBDeu;
using gum::learning::genericBNLearner::useScoreBIC;
using gum::learning::genericBNLearner::useScoreK2;
using gum::learning::genericBNLearner::useScoreLog2Likelihood;
using gum::learning::genericBNLearner::setAprioriWeight;
using gum::learning::genericBNLearner::useNoApriori;
using gum::learning::genericBNLearner::useAprioriSmoothing;
using gum::learning::genericBNLearner::useAprioriDirichlet;
using gum::learning::genericBNLearner::useGreedyHillClimbing;
using gum::learning::genericBNLearner::useLocalSearchWithTabuList;
using gum::learning::genericBNLearner::useK2;
using gum::learning::genericBNLearner::setMaxIndegree;
using gum::learning::genericBNLearner::setSliceOrder;
using gum::learning::genericBNLearner::addForbiddenArc;
using gum::learning::genericBNLearner::eraseForbiddenArc;
using gum::learning::genericBNLearner::addMandatoryArc;
using gum::learning::genericBNLearner::addMandatoryArc;
using gum::learning::genericBNLearner::eraseMandatoryArc;
}
#####################################
%define ADD_NODEGRAPHPART_API(classname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment