Skip to content

Commit

Permalink
Merge pull request #23 from oberbichler/fix/constructor
Browse files Browse the repository at this point in the history
Fix constructor
  • Loading branch information
oberbichler authored Jun 9, 2020
2 parents 5390fce + e16b6bf commit 6e4a6c7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/hyperjet/detail/jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Jet {
HYPERJET_INLINE static Type empty()
{
assert(TSize != -1);
return Type(Scalar(), Vector(TSize), Matrix(TSize, TSize));
return Type(Scalar(), Vector(TSize));
}

HYPERJET_INLINE static Type empty(const index size)
Expand Down
63 changes: 63 additions & 0 deletions include/hyperjet/detail/space.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ struct Space<0, TScalar, TSize> {
template <index TRows, index TCols>
using Matrix = Eigen::Matrix<Scalar, TRows, TCols>;

static Scalar empty()
{
static_assert(-1 <= TSize);

return Scalar();
}

static Scalar constant(TScalar value)
{
static_assert(-1 <= TSize);
Expand All @@ -40,6 +47,20 @@ struct Space<0, TScalar, TSize> {
return value;
}

template <index TOffset, index TDerivedSize>
HYPERJET_INLINE static Eigen::Matrix<Scalar, 1, TDerivedSize> variables(Eigen::Matrix<TScalar, 1, TDerivedSize> value)
{
static_assert(-1 <= TSize);

Eigen::Matrix<Scalar, 1, TDerivedSize> result;

for (index i = 0; i < TDerivedSize; i++) {
result(i) = variable(TOffset + i, value(i));
}

return result;
}

static TScalar f(const Scalar& variable)
{
return variable;
Expand Down Expand Up @@ -84,6 +105,13 @@ struct Space<1, TScalar, TSize> {
template <index TRows, index TCols>
using Matrix = Eigen::Matrix<Scalar, TRows, TCols>;

static Scalar empty()
{
static_assert(-1 <= TSize);

return Scalar::empty();
}

static Scalar constant(TScalar value)
{
static_assert(-1 <= TSize);
Expand All @@ -100,6 +128,20 @@ struct Space<1, TScalar, TSize> {
return result;
}

template <index TOffset, index TDerivedSize>
HYPERJET_INLINE static Eigen::Matrix<Scalar, 1, TDerivedSize> variables(Eigen::Matrix<TScalar, 1, TDerivedSize> value)
{
static_assert(-1 <= TSize);

Eigen::Matrix<Scalar, 1, TDerivedSize> result;

for (index i = 0; i < TDerivedSize; i++) {
result(i) = variable(TOffset + i, value(i));
}

return result;
}

static TScalar f(const Scalar& variable)
{
return variable.f();
Expand Down Expand Up @@ -150,6 +192,13 @@ struct Space<2, TScalar, TSize> {
template <index TRows, index TCols>
using Matrix = Eigen::Matrix<Scalar, TRows, TCols>;

static Scalar empty()
{
static_assert(-1 <= TSize);

return Scalar::empty();
}

static Scalar constant(TScalar value)
{
static_assert(-1 <= TSize);
Expand All @@ -166,6 +215,20 @@ struct Space<2, TScalar, TSize> {
return result;
}

template <index TOffset, index TDerivedSize>
HYPERJET_INLINE static Eigen::Matrix<Scalar, 1, TDerivedSize> variables(Eigen::Matrix<TScalar, 1, TDerivedSize> value)
{
static_assert(-1 <= TSize);

Eigen::Matrix<Scalar, 1, TDerivedSize> result;

for (index i = 0; i < TDerivedSize; i++) {
result(i) = variable(TOffset + i, value(i));
}

return result;
}

static TScalar f(const Scalar& variable)
{
return variable.f();
Expand Down

0 comments on commit 6e4a6c7

Please sign in to comment.