Loading CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Sanitized ) option (USE_REDUCE "Enable the graph reduction" ON) #------------------------------------------------------------------------------- # Sanitizer options #------------------------------------------------------------------------------- Loading graph_framework/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ target_compile_features (rays target_compile_definitions (rays INTERFACE $<$<CONFIG:Release>:NDEBUG> $<$<BOOL:${USE_REDUCE}>:USE_REDUCE> ) target_include_directories (rays INTERFACE Loading graph_framework/arithmetic.hpp +18 −14 Original line number Diff line number Diff line Loading @@ -103,6 +103,7 @@ namespace graph { /// @returns A reduced addition node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Idenity reductions. if (this->left->is_match(this->right)) { return constant<typename LN::backend> (2)*this->left; Loading Loading @@ -253,7 +254,7 @@ namespace graph { lfma->get_middle(), lfma->get_right() + this->right); } #endif return this->shared_from_this(); } Loading Loading @@ -405,6 +406,7 @@ namespace graph { /// @returns A reduced subtraction node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Idenity reductions. if (this->left->is_match(this->right)) { auto l = constant_cast(this->left); Loading Loading @@ -539,7 +541,7 @@ namespace graph { lfma->get_right() - rfma->get_right()); } } #endif return this->shared_from_this(); } Loading Loading @@ -697,6 +699,7 @@ namespace graph { /// @returns A reduced multiplcation node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE auto l = constant_cast(this->left); auto r = constant_cast(this->right); Loading Loading @@ -889,7 +892,7 @@ namespace graph { return pow(this->right, constant<typename LN::backend> (1.5)); } } #endif return this->shared_from_this(); } Loading Loading @@ -1034,17 +1037,9 @@ namespace graph { /// @returns A reduced division node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Constant Reductions. auto l = constant_cast(this->left); if (this->left->is_match(this->right)) { if (l.get() && l->is(1)) { return this->left; } return constant<typename LN::backend> (1); } auto r = constant_cast(this->right); if ((l.get() && l->is(0)) || Loading @@ -1054,6 +1049,14 @@ namespace graph { return constant(this->evaluate()); } if (this->left->is_match(this->right)) { if (l.get() && l->is(1)) { return this->left; } return constant<typename LN::backend> (1); } // Reduce cases of a/c1 -> c2*a if (r.get()) { return (constant<typename LN::backend> (1)/this->right) * Loading Loading @@ -1180,7 +1183,7 @@ namespace graph { return constant<typename LN::backend> (1.0)/this->left; } } #endif return this->shared_from_this(); } Loading Loading @@ -1323,6 +1326,7 @@ namespace graph { /// @returns A reduced addition node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE auto l = constant_cast(this->left); auto m = constant_cast(this->middle); auto r = constant_cast(this->right); Loading Loading @@ -1398,7 +1402,7 @@ namespace graph { if (l.get() && r.get()) { return this->left*(this->middle + this->right/this->left); } #endif return this->shared_from_this(); } Loading graph_framework/cpu_backend.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -502,6 +502,11 @@ namespace backend { } } return base; } else if (right_int == 0) { for (size_t i = 0, ie = base.size(); i < ie; i++) { base[i] = 1.0; } return base; } else { for (size_t i = 0, ie = base.size(); i < ie; i++) { const BASE left = static_cast<BASE> (1.0)/base.at(i); Loading graph_framework/dispersion.hpp +17 −1 Original line number Diff line number Diff line Loading @@ -469,7 +469,12 @@ namespace dispersion { auto k = graph::vector(kx, ky, kz); graph::shared_leaf<BACKEND> kpara2; auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE if (b_vec->length()->is_match(zero)) { #else if (b_vec->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0)) { #endif kpara2 = k->dot(k); } else { auto b_hat = b_vec->unit(); Loading Loading @@ -530,8 +535,14 @@ namespace dispersion { // Wave numbers should be parallel to B if there is a magnetic field. Otherwise // B should be zero. auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE assert(eq->get_magnetic_field(x, y, z)->length()->is_match(zero) && "Expected equilibrium with no magnetic field."); #else assert(eq->get_magnetic_field(x, y, z)->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0) && "Expected equilibrium with no magnetic field."); #endif auto k = graph::vector(kx, ky, kz); auto k2 = k->dot(k); Loading Loading @@ -592,7 +603,12 @@ namespace dispersion { auto k = graph::vector(kx, ky, kz); graph::shared_leaf<BACKEND> kpara2; auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE if (b_vec->length()->is_match(zero)) { #else if (b_vec->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0)) { #endif kpara2 = k->dot(k); } else { auto b_hat = b_vec->unit(); Loading Loading
CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Sanitized ) option (USE_REDUCE "Enable the graph reduction" ON) #------------------------------------------------------------------------------- # Sanitizer options #------------------------------------------------------------------------------- Loading
graph_framework/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ target_compile_features (rays target_compile_definitions (rays INTERFACE $<$<CONFIG:Release>:NDEBUG> $<$<BOOL:${USE_REDUCE}>:USE_REDUCE> ) target_include_directories (rays INTERFACE Loading
graph_framework/arithmetic.hpp +18 −14 Original line number Diff line number Diff line Loading @@ -103,6 +103,7 @@ namespace graph { /// @returns A reduced addition node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Idenity reductions. if (this->left->is_match(this->right)) { return constant<typename LN::backend> (2)*this->left; Loading Loading @@ -253,7 +254,7 @@ namespace graph { lfma->get_middle(), lfma->get_right() + this->right); } #endif return this->shared_from_this(); } Loading Loading @@ -405,6 +406,7 @@ namespace graph { /// @returns A reduced subtraction node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Idenity reductions. if (this->left->is_match(this->right)) { auto l = constant_cast(this->left); Loading Loading @@ -539,7 +541,7 @@ namespace graph { lfma->get_right() - rfma->get_right()); } } #endif return this->shared_from_this(); } Loading Loading @@ -697,6 +699,7 @@ namespace graph { /// @returns A reduced multiplcation node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE auto l = constant_cast(this->left); auto r = constant_cast(this->right); Loading Loading @@ -889,7 +892,7 @@ namespace graph { return pow(this->right, constant<typename LN::backend> (1.5)); } } #endif return this->shared_from_this(); } Loading Loading @@ -1034,17 +1037,9 @@ namespace graph { /// @returns A reduced division node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE // Constant Reductions. auto l = constant_cast(this->left); if (this->left->is_match(this->right)) { if (l.get() && l->is(1)) { return this->left; } return constant<typename LN::backend> (1); } auto r = constant_cast(this->right); if ((l.get() && l->is(0)) || Loading @@ -1054,6 +1049,14 @@ namespace graph { return constant(this->evaluate()); } if (this->left->is_match(this->right)) { if (l.get() && l->is(1)) { return this->left; } return constant<typename LN::backend> (1); } // Reduce cases of a/c1 -> c2*a if (r.get()) { return (constant<typename LN::backend> (1)/this->right) * Loading Loading @@ -1180,7 +1183,7 @@ namespace graph { return constant<typename LN::backend> (1.0)/this->left; } } #endif return this->shared_from_this(); } Loading Loading @@ -1323,6 +1326,7 @@ namespace graph { /// @returns A reduced addition node. //------------------------------------------------------------------------------ virtual shared_leaf<typename LN::backend> reduce() final { #ifdef USE_REDUCE auto l = constant_cast(this->left); auto m = constant_cast(this->middle); auto r = constant_cast(this->right); Loading Loading @@ -1398,7 +1402,7 @@ namespace graph { if (l.get() && r.get()) { return this->left*(this->middle + this->right/this->left); } #endif return this->shared_from_this(); } Loading
graph_framework/cpu_backend.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -502,6 +502,11 @@ namespace backend { } } return base; } else if (right_int == 0) { for (size_t i = 0, ie = base.size(); i < ie; i++) { base[i] = 1.0; } return base; } else { for (size_t i = 0, ie = base.size(); i < ie; i++) { const BASE left = static_cast<BASE> (1.0)/base.at(i); Loading
graph_framework/dispersion.hpp +17 −1 Original line number Diff line number Diff line Loading @@ -469,7 +469,12 @@ namespace dispersion { auto k = graph::vector(kx, ky, kz); graph::shared_leaf<BACKEND> kpara2; auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE if (b_vec->length()->is_match(zero)) { #else if (b_vec->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0)) { #endif kpara2 = k->dot(k); } else { auto b_hat = b_vec->unit(); Loading Loading @@ -530,8 +535,14 @@ namespace dispersion { // Wave numbers should be parallel to B if there is a magnetic field. Otherwise // B should be zero. auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE assert(eq->get_magnetic_field(x, y, z)->length()->is_match(zero) && "Expected equilibrium with no magnetic field."); #else assert(eq->get_magnetic_field(x, y, z)->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0) && "Expected equilibrium with no magnetic field."); #endif auto k = graph::vector(kx, ky, kz); auto k2 = k->dot(k); Loading Loading @@ -592,7 +603,12 @@ namespace dispersion { auto k = graph::vector(kx, ky, kz); graph::shared_leaf<BACKEND> kpara2; auto zero = graph::constant<BACKEND> (0.0); #ifdef USE_REDUCE if (b_vec->length()->is_match(zero)) { #else if (b_vec->length()->evaluate()[0] == backend::base_cast<BACKEND> (0.0)) { #endif kpara2 = k->dot(k); } else { auto b_hat = b_vec->unit(); Loading