Commit aecb99e3 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Add the option to disable the reduction and fix the problems it causes in the unit tests.

parent 7f5ae9d4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
              Sanitized
)

option (USE_REDUCE "Enable the graph reduction" ON)

#-------------------------------------------------------------------------------
#  Sanitizer options
#-------------------------------------------------------------------------------
+1 −0
Original line number Diff line number Diff line
@@ -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
+18 −14
Original line number Diff line number Diff line
@@ -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;
@@ -253,7 +254,7 @@ namespace graph {
                           lfma->get_middle(),
                           lfma->get_right() + this->right);
            }
            
#endif
            return this->shared_from_this();
        }

@@ -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);
@@ -539,7 +541,7 @@ namespace graph {
                               lfma->get_right() - rfma->get_right());
                }
            }

#endif
            return this->shared_from_this();
        }

@@ -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);

@@ -889,7 +892,7 @@ namespace graph {
                    return pow(this->right, constant<typename LN::backend> (1.5));
                }
            }

#endif
            return this->shared_from_this();
        }

@@ -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)) ||
@@ -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) *
@@ -1180,7 +1183,7 @@ namespace graph {
                    return constant<typename LN::backend> (1.0)/this->left;
                }
            }
            
#endif
            return this->shared_from_this();
        }

@@ -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);
@@ -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();
        }

+5 −0
Original line number Diff line number Diff line
@@ -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);
+17 −1
Original line number Diff line number Diff line
@@ -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();
@@ -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);
@@ -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