7 #include <boost/math/special_functions/factorials.hpp>
20 int round(
double val);
25 T
min(
const T &A,
const T &B) {
32 T
max(
const T &A,
const T &B) {
39 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type * =
nullptr>
42 return std::abs(val) <
tol;
46 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type * =
nullptr>
49 return std::abs(val) <
tol;
53 template <typename T, typename std::enable_if<std::is_integral<T>::value, T>::type * =
nullptr>
60 template <
typename Derived>
62 return val.isZero(
tol);
68 template < typename T, typename std::enable_if < !std::is_integral<T>::value, T >::type * =
nullptr >
74 template <typename T, typename std::enable_if<std::is_integral<T>::value, T>::type * =
nullptr>
88 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type * =
nullptr>
110 template<
class InputIt1,
class InputIt2>
113 return std::lexicographical_compare(first1, last1, first2, last2, compare);
124 template <typename T, typename std::enable_if<std::is_integral<T>::value, T>::type * =
nullptr>
126 return (T(0) < val) - (val < T(0));
129 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type * =
nullptr>
132 if(
compare(zeroval, val, compare_tol)) {
136 else if(
compare(val, zeroval, compare_tol)) {
147 template <
typename IntType>
149 assert(k <= n && 0 <= k);
156 for(IntType i = 1; i < k + 1; i++) {
172 double ran0(
int &idum);
176 using boost::math::factorial;
180 int gcf(
int i1,
int i2);
184 int lcm(
int i1,
int i2);
190 double gaussian(
double a,
double x,
double b,
double c);
213 template<
typename IntType>
214 IntType
extended_gcf(IntType i1, IntType i2, IntType &p1, IntType &p2) {
215 IntType s1 =
sgn(i1);
216 IntType s2 =
sgn(i2);
218 IntType a = i1, b = i2;
221 IntType tp1(0), tp2(1), quotient;
231 p1 = p1 - quotient * tp1;
233 p2 = p2 - quotient * tp2;
239 return p1 * a + p2 * b;
244 int lcm(
int i1,
int i2);
270 int mod(
int a,
int b);
278 void poly_fit(Eigen::VectorXcd &xvec, Eigen::VectorXcd &yvec, Eigen::VectorXcd &coeffs,
int degree);
297 int lcm(
const Array<int> &series);
305 template <
typename IntType>
307 IntType tcoeff(1), tsum(0);
308 for(
Index i = 0; i < exponents.
size(); i++) {
309 tsum += exponents[i];
310 tcoeff *=
nchoosek(tsum, exponents[i]);
317 template <
typename IntType>
319 IntType tcoeff(1), tsum(0);
320 for(
Index i = 0; i < sublist.
size(); i++) {
321 tsum += exponents[sublist[i]];
322 tcoeff *=
nchoosek(tsum, exponents[sublist[i]]);
327 template <
typename T>
340 template <
typename T>
353 template<
typename Derived>
354 double length(
const Eigen::MatrixBase<Derived> &value) {
360 template<
typename Derived>
364 for(
Index i = 1; i < value.size(); i++) {
370 subspace_dims.
push_back(value.size() - last_i);
371 return subspace_dims;
377 namespace HungarianMethod_impl {
412 template <
typename Derived>
414 Derived::RowsAtCompileTime,
415 Derived::ColsAtCompileTime>
418 typedef Eigen::Matrix<int, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> int_mat_type;
419 typedef Eigen::Matrix<double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> dub_mat_type;
421 int_mat_type ints(int_mat_type::Zero(val.rows(), val.cols()));
423 dub_mat_type dubs(val);
426 double min_coeff = 2;
427 for(
Index i = 0; i < dubs.rows(); i++) {
428 for(
Index j = 0; j < dubs.cols(); j++) {
432 else if(std::abs(dubs(i, j)) < std::abs(min_coeff)) {
433 min_coeff = dubs(i, j);
439 dubs /= std::abs(min_coeff);
456 bool within_tol =
false;
459 for(
Index factor = 1; factor < 1000 && !within_tol; factor++) {
461 tdubs = double(factor) * dubs;
462 for(i = 0; i < dubs.rows(); i++) {
463 for(j = 0; j < dubs.cols(); j++) {
475 for(
Index i = 0; i < dubs.rows(); i++) {
476 for(
Index j = 0; j < dubs.cols(); j++) {
477 ints(i, j) =
round(tdubs(i, j));
489 template <
typename Derived1,
typename Derived2>
502 template <
typename Derived>
515 template <
typename Derived>
519 auto rev_mat = test_mat.colwise().reverse().eval().rowwise().reverse().eval();
530 template <
typename Derived>
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
ReturnArray< T > cum_sum(const Array< T > &arr)
IntType multinomial_coeff(const Array< IntType > &exponents)
Index which_unique_combination(const Array< Index > &input, const Array< Index >::X2 &unique, const Array< Index >::X2 &ind_equiv)
Eigen::VectorXd eigen_vector_from_string(const std::string &tstr, const int &size)
int gcf(int i1, int i2)
Find greatest common factor.
bool compare(const T &A, const T &B, double tol)
Floating point comparison with tol, return A < B.
void push_back(const T &toPush)
bool float_lexicographical_compare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, double tol)
Floating point lexicographical comparison with tol.
int lcm(int i1, int i2)
Find least common multiple.
IntType extended_gcf(IntType i1, IntType i2, IntType &p1, IntType &p2)
Calculate greatest common factor of two integers, and bezout coefficients.
double hungarian_method(const Eigen::MatrixXd &cost_matrix, std::vector< Index > &optimal_assignments, const double _tol)
bool is_bisymmetric(const Eigen::MatrixBase< Derived > &test_mat, double test_tol=CASM::TOL)
void poly_fit(Eigen::VectorXcd &xvec, Eigen::VectorXcd &yvec, Eigen::VectorXcd &coeffs, int degree)
double gaussian(double a, double x, double b, double c)
double cuberoot(double number)
int dl_string_dist(const std::string &a, const std::string &b)
Computes the Damerescau-Levenshtein distance – the number of edits (deletions, insertions, transpositions) to go from string 'a' to string 'b'.
void hungarian_method(const Eigen::MatrixXd &cost_matrix_arg, std::vector< Index > &optimal_assignments, const double _tol)
ReturnArray< Array< int > > get_prime_factors(int target)
void swap(ConfigDoF &A, ConfigDoF &B)
double gaussian_moment(int expon, double sigma)
EigenIndex Index
For long integer indexing:
int float_sgn(T val, double compare_tol=TOL)
IntType nchoosek(IntType n, IntType k)
Eigen::Matrix< int, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > scale_to_int(const Eigen::MatrixBase< Derived > &val, double _tol=TOL)
Take a vector of doubles, and multiply by some factor that turns it into a vector of integers (within...
bool is_persymmetric(const Eigen::MatrixBase< Derived > &test_mat, double test_tol=CASM::TOL)
std::string irrational_to_tex_string(double val, int lim, int max_pow=2)
T max(const T &A, const T &B)
T min(const T &A, const T &B)
bool is_symmetric(const Eigen::MatrixBase< Derived > &test_mat, double test_tol=CASM::TOL)
void nearest_rational_number(double val, long &numerator, long &denominator, double tol=TOL)
ReturnArray< Index > partition_distinct_values(const Eigen::MatrixBase< Derived > &value, double tol=TOL)
void reserve(Index new_max)
bool almost_equal(const Eigen::MatrixBase< Derived1 > &val1, const Eigen::MatrixBase< Derived2 > &val2, double tol=CASM::TOL)
FloatCompare(double _tol)
Basic std::vector like container (deprecated)
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
bool operator()(const T &A, const T &B) const
bool valid_index(Index i)
double length(const Eigen::MatrixBase< Derived > &value)