Skip to content

Commit

Permalink
Make Expression type default to constant (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Dec 8, 2023
1 parent 41f9674 commit 172c324
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
17 changes: 3 additions & 14 deletions include/sleipnir/autodiff/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct SLEIPNIR_DLLEXPORT Expression {
IntrusiveSharedPtr<Expression> adjointExpr;

/// Expression argument type.
ExpressionType type = ExpressionType::kLinear;
ExpressionType type = ExpressionType::kConstant;

/// Either nullary operator with no arguments, unary operator with one
/// argument, or binary operator with two arguments. This operator is
Expand Down Expand Up @@ -104,20 +104,9 @@ struct SLEIPNIR_DLLEXPORT Expression {
uint32_t refCount = 0;

/**
* Type tag used for constructing the "zero" expression.
* Default constructor.
*/
struct ZeroSingleton_t {};

/**
* Type tag used for constructing the "zero" expression.
*/
static inline ZeroSingleton_t ZeroSingleton;

/**
* Constructs an instance of "zero", which has special meaning in expression
* operations. This should only be constructed once via Zero().
*/
explicit Expression(ZeroSingleton_t);
Expression() = default;

/**
* Copy constructor.
Expand Down
4 changes: 1 addition & 3 deletions src/autodiff/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
namespace sleipnir {

IntrusiveSharedPtr<Expression>& Zero() {
static auto expr = MakeExpression(Expression::ZeroSingleton);
static auto expr = MakeExpression();
return expr;
}

Expression::Expression(ZeroSingleton_t) : type{ExpressionType::kConstant} {}

Expression::Expression(double value, ExpressionType type)
: value{value}, adjointExpr{Zero()}, type{type}, args{Zero(), Zero()} {}

Expand Down

0 comments on commit 172c324

Please sign in to comment.