Commit 6d637df7 authored by Tobias WEBER's avatar Tobias WEBER

function to check if space groups operations are equal

parent 2fffa979
......@@ -419,6 +419,38 @@ requires is_mat<t_mat>
}
/**
* check if two collections of matrices or vectors are equal
*/
template<class t_obj, template<class...> class t_vec=std::vector>
bool equals_all(const t_vec<t_obj>& vec1, const t_vec<t_obj>& _vec2,
typename t_obj::value_type eps = std::numeric_limits<typename t_obj::value_type>::epsilon())
{
auto vec2 = _vec2;
if(vec1.size() != vec2.size())
return false;
for(const auto& obj1 : vec1)
{
// find obj1 in vec2
auto iter = std::find_if(vec2.crbegin(), vec2.crend(), [&obj1, eps](const t_obj& obj2) -> bool
{
return m::equals<t_obj>(obj1, obj2, eps);
});
// not found
if(iter == vec2.crend())
return false;
// remove already checked element
vec2.erase(iter.base()-1);
}
return true;
}
/**
* set submatrix to unit
*/
......@@ -3788,6 +3820,7 @@ requires is_vec<t_vec> && is_mat<t_mat>
return newatoms;
}
// ----------------------------------------------------------------------------
......
......@@ -62,6 +62,7 @@ std::vector<t_mat> get_cif_ops(gemmi::cif::Block& block)
/**
* gets the symmetry operations from the CIF's space group
* (use m::equals_all to check if space group operations are the same)
*/
template<class t_vec, class t_mat, class t_real = typename t_vec::value_type>
std::vector<t_mat> get_cif_sg_ops(gemmi::cif::Block& block)
......
......@@ -26,8 +26,6 @@ using t_mat_cplx = m::mat<t_cplx, std::vector>;
int main()
{
//std::cout << m::stoval<unsigned int>("123") << std::endl;
auto x = m::create<t_vec>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
auto y = m::create<t_vec>({5, 5, 7, 9, 9.5, 10.5, 10.5, 12, 13.5, 14});
......
/**
* math lib test
* @author Tobias Weber <tweber@ill.fr>
* @date mar-19
* @license GPLv3, see 'LICENSE' file
*
* g++-8 -std=c++17 -fconcepts -o mat1 mat1.cpp
* g++-8 -std=c++17 -fconcepts -DUSE_LAPACK -I/usr/include/lapacke -I/usr/local/opt/lapack/include -L/usr/local/opt/lapack/lib -o leastsq leastsq.cpp -llapacke
*/
#include <iostream>
#include <vector>
#include "../../libs/_cxx20/math_algos.h"
using namespace m_ops;
using t_real = double;
//using t_real = float;
using t_cplx = std::complex<t_real>;
using t_vec = std::vector<t_real>;
using t_mat = m::mat<t_real, std::vector>;
using t_vec_cplx = std::vector<t_cplx>;
using t_mat_cplx = m::mat<t_cplx, std::vector>;
int main()
{
std::cout << m::stoval<unsigned int>("123") << std::endl;
std::vector vec1{{
m::create<t_vec>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
m::create<t_vec>({5, 5, 7, 9, 9.5, 10.5, 10.5, 12, 13.5, 14})
}};
std::vector vec2{{
m::create<t_vec>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10.5}),
m::create<t_vec>({5, 5, 7, 9, 9.5, 10.5, 10.5, 12, 13.5, 14})
}};
std::vector vec3{{
m::create<t_vec>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10}),
m::create<t_vec>({5, 5, 7, 9, 9.5, 10.5, 10.5, 12, 13.5, 14, 14})
}};
std::cout << std::boolalpha << m::equals_all(vec1, vec1, 1e-5) << std::endl;
std::cout << std::boolalpha << m::equals_all(vec3, vec3, 1e-5) << std::endl;
std::cout << std::boolalpha << m::equals_all(vec1, vec2, 1e-5) << std::endl;
std::cout << std::boolalpha << m::equals_all(vec1, vec3, 1e-5) << std::endl;
return 0;
}
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