Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
6eedc659
Commit
6eedc659
authored
4 years ago
by
Emmanuel Labourasse
Browse files
Options
Downloads
Patches
Plain Diff
Add a class for the polynomial basis management
parent
44bc6f27
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/analysis/PolynomialBasis.hpp
+105
-0
105 additions, 0 deletions
src/analysis/PolynomialBasis.hpp
tests/test_PolynomialBasis.cpp
+42
-0
42 additions, 0 deletions
tests/test_PolynomialBasis.cpp
with
147 additions
and
0 deletions
src/analysis/PolynomialBasis.hpp
0 → 100644
+
105
−
0
View file @
6eedc659
#ifndef POLYNOMIALBASIS_HPP
#define POLYNOMIALBASIS_HPP
#include
<algebra/TinyVector.hpp>
#include
<analysis/Polynomial.hpp>
#include
<utils/Messenger.hpp>
enum
class
BasisType
{
canonical
};
template
<
size_t
N
>
class
PolynomialBasis
{
private:
static_assert
((
N
>=
0
),
"Number of elements in the basis must be non-negative"
);
TinyVector
<
N
+
1
,
Polynomial
<
N
>>
m_elements
;
BasisType
m_basis_type
;
PUGS_INLINE
constexpr
PolynomialBasis
<
N
>&
_buildCanonicalBasis
()
{
for
(
size_t
i
=
0
;
i
<=
N
;
i
++
)
{
TinyVector
<
N
+
1
>
coefficients
(
zero
);
coefficients
[
i
]
=
1
;
elements
()[
i
]
=
Polynomial
<
N
>
(
coefficients
);
}
return
*
this
;
}
public
:
PUGS_INLINE
constexpr
size_t
size
()
const
{
return
N
+
1
;
}
PUGS_INLINE
constexpr
size_t
degree
()
const
{
return
N
;
}
PUGS_INLINE
constexpr
BasisType
&
type
()
{
return
m_basis_type
;
}
PUGS_INLINE
std
::
string_view
displayType
()
{
switch
(
m_basis_type
)
{
case
BasisType
::
canonical
:
return
"canonical"
;
default:
return
"unknown basis type"
;
}
}
PUGS_INLINE
constexpr
const
TinyVector
<
N
+
1
,
Polynomial
<
N
>>&
elements
()
const
{
return
m_elements
;
}
PUGS_INLINE
constexpr
TinyVector
<
N
+
1
,
Polynomial
<
N
>>&
elements
()
{
return
m_elements
;
}
PUGS_INLINE
constexpr
PolynomialBasis
<
N
>&
build
(
BasisType
basis_type
)
{
type
()
=
basis_type
;
switch
(
basis_type
)
{
case
BasisType
::
canonical
:
{
return
_buildCanonicalBasis
();
break
;
}
default
:
throw
UnexpectedError
(
"unknown basis type"
);
}
}
PUGS_INLINE
constexpr
PolynomialBasis
(
const
TinyVector
<
N
+
1
,
Polynomial
<
N
>>&
elements
)
noexcept
:
m_elements
{
elements
}
{}
PUGS_INLINE
constexpr
PolynomialBasis
(
TinyVector
<
N
+
1
,
Polynomial
<
N
>>&&
elements
)
noexcept
:
m_elements
{
elements
}
{}
PUGS_INLINE
constexpr
PolynomialBasis
()
noexcept
=
default
;
~
PolynomialBasis
()
=
default
;
};
#endif // POLYNOMIAL_HPP
This diff is collapsed.
Click to expand it.
tests/test_PolynomialBasis.cpp
0 → 100644
+
42
−
0
View file @
6eedc659
#include
<catch2/catch.hpp>
#include
<Kokkos_Core.hpp>
#include
<utils/PugsAssert.hpp>
#include
<utils/Types.hpp>
#include
<algebra/TinyMatrix.hpp>
#include
<analysis/Polynomial.hpp>
#include
<analysis/PolynomialBasis.hpp>
// Instantiate to ensure full coverage is performed
template
class
Polynomial
<
0
>;
template
class
Polynomial
<
1
>;
template
class
Polynomial
<
2
>;
template
class
PolynomialBasis
<
2
>;
// clazy:excludeall=non-pod-global-static
TEST_CASE
(
"PolynomialBasis"
,
"[analysis]"
)
{
SECTION
(
"construction"
)
{
TinyVector
<
3
,
Polynomial
<
2
>>
elements
;
REQUIRE_NOTHROW
(
PolynomialBasis
<
2
>
(
elements
));
REQUIRE_NOTHROW
(
PolynomialBasis
<
2
>
());
}
SECTION
(
"size"
)
{
PolynomialBasis
<
2
>
B
;
REQUIRE
(
B
.
size
()
==
3
);
REQUIRE
(
B
.
degree
()
==
2
);
}
SECTION
(
"build"
)
{
PolynomialBasis
<
2
>
B
;
REQUIRE
(
B
.
displayType
()
==
"unknown basis type"
);
B
.
build
(
BasisType
::
canonical
);
REQUIRE
(
B
.
elements
()[
1
]
==
Polynomial
<
2
>
{{
0
,
1
,
0
}});
REQUIRE
(
B
.
elements
()[
2
]
==
Polynomial
<
2
>
{{
0
,
0
,
1
}});
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment