/usr/include/scilab/gvn/InferenceConstraint.hxx is in scilab-include 6.0.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | /*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
*
*/
#ifndef __INFERENCE_CONSTRAINT_HXX__
#define __INFERENCE_CONSTRAINT_HXX__
#include <cmath>
#include <iostream>
#include <unordered_set>
#include <vector>
#include "GVN.hxx"
#include "tools.hxx"
namespace analysis
{
struct MPolyConstraint;
struct MPolyConstraintSet;
struct InferenceConstraint
{
enum Result
{
RESULT_TRUE, RESULT_FALSE, RESULT_DUNNO
};
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const = 0;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const = 0;
virtual void applyConstraints(const std::vector<GVN::Value *> & /*values*/) const { }
inline static std::vector<const MultivariatePolynomial *> getArgs(const std::vector<GVN::Value *> & values)
{
std::vector<const MultivariatePolynomial *> args;
args.reserve(values.size());
for (const auto value : values)
{
args.emplace_back(value->poly);
}
return args;
}
inline static void applyEquality(GVN::Value & x, GVN::Value & y)
{
if (x != y)
{
if (x.poly->polynomial.size() < y.poly->polynomial.size())
{
y = x;
}
else
{
x = y;
}
}
}
};
struct SameDimsConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct EqualConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct PositiveConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct StrictPositiveConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct GreaterConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct StrictGreaterConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct ValidIndexConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct ValidRangeConstraint : public InferenceConstraint
{
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const /*override*/;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const /*override*/;
};
struct MPolyConstraint : public InferenceConstraint
{
enum Kind
{
EQ0, NEQ0, GT0, GEQ0
};
MultivariatePolynomial poly;
Kind kind;
MPolyConstraint(const MultivariatePolynomial & _poly, const Kind _kind) : poly(_poly), kind(_kind)
{
int64_t common;
if (poly.getCommonCoeff(common) && common != 1 && common != 0)
{
if (kind == EQ0)
{
poly /= common;
}
else
{
poly /= std::abs(common);
}
}
}
inline bool isConstant() const
{
return poly.isConstant();
}
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const override;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const override;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const override;
struct Hash
{
inline std::size_t operator()(const MPolyConstraint & mpc) const
{
return tools::hash_combine(mpc.kind, mpc.poly.hash());
}
};
inline bool operator==(const MPolyConstraint & R) const
{
return kind == R.kind && poly == R.poly;
}
struct Eq
{
inline bool operator()(const MPolyConstraint & L, const MPolyConstraint & R) const
{
return L == R;
}
};
friend std::wostream & operator<<(std::wostream & out, const MPolyConstraint & mpc);
};
struct MPolyConstraintSet : public InferenceConstraint
{
std::unordered_set<MPolyConstraint, MPolyConstraint::Hash, MPolyConstraint::Eq> constraints;
MPolyConstraintSet() { }
MPolyConstraintSet(const unsigned int size)
{
constraints.reserve(size);
}
inline void add(MPolyConstraint && mpc)
{
if (!mpc.isConstant())
{
constraints.emplace(std::move(mpc));
}
}
inline void add(MultivariatePolynomial && poly, MPolyConstraint::Kind kind)
{
if (!poly.isConstant())
{
constraints.emplace(std::move(poly), kind);
}
}
inline void add(const MultivariatePolynomial & poly, MPolyConstraint::Kind kind)
{
if (!poly.isConstant())
{
constraints.emplace(poly, kind);
}
}
inline void add(const MPolyConstraintSet & set)
{
constraints.insert(set.constraints.begin(), set.constraints.end());
}
inline bool empty() const
{
return constraints.empty();
}
inline std::size_t size() const
{
return constraints.size();
}
virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const override;
virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const override;
virtual void applyConstraints(const std::vector<GVN::Value *> & values) const override;
friend std::wostream & operator<<(std::wostream & out, const MPolyConstraintSet & mpcs);
struct Hash
{
inline std::size_t operator()(const MPolyConstraintSet & mpcs) const
{
std::size_t seed = 0;
for (const auto & c : mpcs.constraints)
{
seed = tools::hash_combine(seed, MPolyConstraint::Hash()(c));
}
return seed;
}
};
struct Eq
{
inline bool operator()(const MPolyConstraintSet & L, const MPolyConstraintSet & R) const
{
return L.constraints == R.constraints;
}
};
};
} // namespace analysis
#endif // __INFERENCE_CONSTRAINT_HXX__
|