void test_expression(const E& expr, size_t size, Fn&& fn, const char* expression = nullptr) { using T = value_type_of<E>; ::testo::test_case* test = ::testo::active_test(); auto&& c = ::testo::make_comparison(); test->check(c <= expr.size() == size, expression); if (expr.size() != size) return; size = size_min(size, 200); constexpr size_t maxsize = 2 + ilog2(vector_width<T> * 2); for (size_t i = 0; i < size;) { const size_t next_size = std::min(prev_poweroftwo(size - i), static_cast<size_t>(1) << (std::rand() % maxsize)); cswitch(csize<1> << csizeseq<maxsize>, next_size, [&](auto x) { constexpr size_t nsize = val_of(decltype(x)()); ::testo::scope s(as_string("i = ", i)); test->check(c <= get_elements(expr, cinput, i, vec_shape<T, nsize>()) == internal::get_fn_value<T, nsize>(i, fn), expression); }); i += next_size; } }
/** * \brief Removes a resource element from the list. * \param resource_type A type of resource. * \param id Id of the element to remove. * \return \c true if the element was removed, \c false if such an element * did not exist. */ bool QuestResources::remove( ResourceType resource_type, const std::string& id ) { ResourceMap& resource = get_elements(resource_type); return resource.erase(id) > 0; }
static vector_t get_sorted_elements(const hash_t *hash){ vector_t elements = get_elements(hash); if(elements.num_elements>1) // fsanitize=undefined aborts the program if sending null pointer to qsort. qsort(elements.elements, elements.num_elements, sizeof(void*), compare_hash_elements); return elements; }
void NoGhostGameofLife::finish_construction() { m_numProcs = m_bulkData->parallel_size(); m_time = 0; get_elements(); create_element_connectivity_maps(); write_output_mesh(); }
/** * \brief Adds a resource element to the list. * \param resource_type A type of resource. * \param id Id of the element to add. * \param description Description the element to add. * \return \c true if the element was added, \c false if an element with * this id already exists. */ bool QuestResources::add( ResourceType resource_type, const std::string& id, const std::string& description ) { ResourceMap& resource = get_elements(resource_type); auto result = resource.insert(std::make_pair(id, description)); return result.second; }
//public GameofLife::GameofLife(GameofLifeMesh& Mesh, std::string meshName) :m_metaData(Mesh.meta_data()), m_bulkData(Mesh.bulk_data()), m_lifeField(Mesh.life_field()), m_stkIo(Mesh.comm()), m_meshName(meshName), m_time(0), m_elemType(Mesh.element_type()),m_activeNeighborField(Mesh.neighbor_field()) { get_elements(); write_output_mesh(); fill_neighbor_sets_of_elements(); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_flattop& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { const vec<T, N> n = get_elements(self.linspace, cinput, index, y) * c_pi<T, 2>; constexpr T a0 = 1; constexpr T a1 = 1.93; constexpr T a2 = 1.29; constexpr T a3 = 0.388; constexpr T a4 = 0.028; return a0 - a1 * cos(n) + a2 * cos(2 * n) - a3 * cos(3 * n) + a4 * cos(4 * n); }
/** * \brief Sets the description of a resource element. * \param resource_type A type of resource. * \param id Id of the element to modify. * \param description The new description. * \return \c true in case of success, \c false if such an element does not * exist. */ bool QuestResources::set_description( ResourceType resource_type, const std::string& id, const std::string& description ) { if (!exists(resource_type, id)) { return false; } ResourceMap& resource = get_elements(resource_type); resource[id] = description; return true; }
/** * \brief Returns the description of a resource element. * \param resource_type A type of resource. * \param id Id of the element to get. * \return description The element description. * Returns an empty string if the element does not exist. */ std::string QuestResources::get_description( ResourceType resource_type, const std::string& id ) const { const ResourceMap& resource = get_elements(resource_type); const auto& it = resource.find(id); if (it == resource.end()) { return ""; } return it->second; }
/** * \copydoc LuaData::export_to_lua */ bool QuestResources::export_to_lua(std::ostream& out) const { // Save each resource. for (const auto& kvp: resource_type_names) { const ResourceMap& resource = get_elements(kvp.first); for (const auto& element: resource) { const std::string& id = element.first; const std::string& description = element.second; out << kvp.second << "{ id = \"" << id << "\", description = \"" << description << "\" }\n"; } out << "\n"; } return true; }
/** * \copydoc LuaData::export_to_lua */ bool QuestResources::export_to_lua(std::ostream& out) const { // Save each resource. for (const auto& kvp: EnumInfoTraits<ResourceType>::names) { const ResourceMap& resource = get_elements(kvp.first); for (const auto& element: resource) { const std::string& id = element.first; const std::string& description = element.second; out << kvp.second << "{ id = \"" << escape_string(id) << "\", description = \"" << escape_string(description) << "\" }\n"; } out << "\n"; } return true; }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_bartlett& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return 1 - abs(get_elements(self.linspace, cinput, index, y)); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_cosine& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return sin(c_pi<T> * get_elements(self.linspace, cinput, index, y)); }
/** * \brief Returns whether there exists an element with the specified id. * \param resource_type A type of resource. * \param id The id to look for. * \return \c true if there exists an element with the specified id in this * resource type. */ bool QuestResources::exists(ResourceType resource_type, const std::string& id) const { const ResourceMap& resource = get_elements(resource_type); return resource.find(id) != resource.end(); }
double planet::compute_period() const { return 2* boost::math::constants::pi<double>() * std::sqrt(std::pow(get_elements()[0],3) / get_mu_central_body()); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_bohman& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { const vec<T, N> n = abs(get_elements(self.linspace, cinput, index, y)); return (T(1) - n) * cos(c_pi<T> * n) + (T(1) / c_pi<T>)*sin(c_pi<T> * n); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_hann& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return T(0.5) * (T(1) - cos(c_pi<T, 2> * get_elements(self.linspace, cinput, index, y))); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_lanczos& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return sinc(get_elements(self.linspace, cinput, index, y)); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_gaussian& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return exp(T(-0.5) * sqr(self.alpha * get_elements(self.linspace, cinput, index, y))); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_bartlett_hann& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { const vec<T, N> xx = get_elements(self.linspace, cinput, index, y); return T(0.62) - T(0.48) * abs(xx - T(0.5)) + T(0.38) * cos(c_pi<T, 2> * (xx - T(0.5))); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_kaiser& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return modzerobessel(self.beta * sqrt(1 - sqr(get_elements(self.linspace, cinput, index, y)))) * self.m; }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_blackman_harris& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { const vec<T, N> n = get_elements(self.linspace, cinput, index, y) * c_pi<T, 2>; return T(0.35875) - T(0.48829) * cos(n) + T(0.14128) * cos(2 * n) - T(0.01168) * cos(3 * n); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_blackman& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { const vec<T, N> n = get_elements(self.linspace, cinput, index, y); return self.a0 - self.a1 * cos(c_pi<T, 2> * n) + self.a2 * cos(c_pi<T, 4> * n); }
static void static_get(void* instance, size_t index, vec<T, N>& result) { result = get_elements(*static_cast<Expression*>(instance), cinput, index, vec_shape<T, N>()); }
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_hamming& self, cinput_t cinput, size_t index, vec_shape<T, N> y) { return self.alpha - (T(1.0) - self.alpha) * (cos(c_pi<T, 2> * get_elements(self.linspace, cinput, index, y))); }