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
ef43ccfd
Commit
ef43ccfd
authored
3 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Replace Array by std::vector -> this improves a lot performances!
parent
beb384d8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/analysis/Polynomial1D.hpp
+17
-10
17 additions, 10 deletions
src/analysis/Polynomial1D.hpp
with
17 additions
and
10 deletions
src/analysis/Polynomial1D.hpp
+
17
−
10
View file @
ef43ccfd
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
class
[[
nodiscard
]]
Polynomial1D
class
[[
nodiscard
]]
Polynomial1D
{
{
private:
private:
Array
<
double
>
m_coefficients
;
std
::
vector
<
double
>
m_coefficients
;
PUGS_INLINE
PUGS_INLINE
size_t
_getRealDegree
()
const
size_t
_getRealDegree
()
const
...
@@ -93,7 +93,7 @@ class [[nodiscard]] Polynomial1D
...
@@ -93,7 +93,7 @@ class [[nodiscard]] Polynomial1D
Polynomial1D
operator
*
(
const
Polynomial1D
&
p
)
const
Polynomial1D
operator
*
(
const
Polynomial1D
&
p
)
const
{
{
Polynomial1D
product
(
this
->
degree
()
+
p
.
degree
());
Polynomial1D
product
(
this
->
degree
()
+
p
.
degree
());
product
.
m_coefficients
.
fill
(
0
);
std
::
fill
(
begin
(
product
.
m_coefficients
),
end
(
product
.
m_coefficients
),
0
);
for
(
size_t
i
=
0
;
i
<
this
->
m_coefficients
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
this
->
m_coefficients
.
size
();
++
i
)
{
for
(
size_t
j
=
0
;
j
<
p
.
m_coefficients
.
size
();
++
j
)
{
for
(
size_t
j
=
0
;
j
<
p
.
m_coefficients
.
size
();
++
j
)
{
product
.
m_coefficients
[
i
+
j
]
+=
this
->
m_coefficients
[
i
]
*
p
.
m_coefficients
[
j
];
product
.
m_coefficients
[
i
+
j
]
+=
this
->
m_coefficients
[
i
]
*
p
.
m_coefficients
[
j
];
...
@@ -107,7 +107,10 @@ class [[nodiscard]] Polynomial1D
...
@@ -107,7 +107,10 @@ class [[nodiscard]] Polynomial1D
{
{
auto
sum_left_is_bigger
=
[](
const
Polynomial1D
&
greater
,
const
Polynomial1D
&
smaller
)
{
auto
sum_left_is_bigger
=
[](
const
Polynomial1D
&
greater
,
const
Polynomial1D
&
smaller
)
{
Polynomial1D
result
(
greater
.
degree
());
Polynomial1D
result
(
greater
.
degree
());
copy_to
(
greater
.
m_coefficients
,
result
.
m_coefficients
);
for
(
size_t
i
=
0
;
i
<
greater
.
m_coefficients
.
size
();
++
i
)
{
result
.
m_coefficients
[
i
]
=
greater
.
m_coefficients
[
i
];
}
for
(
size_t
i
=
0
;
i
<
smaller
.
m_coefficients
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
smaller
.
m_coefficients
.
size
();
++
i
)
{
result
.
m_coefficients
[
i
]
+=
smaller
.
m_coefficients
[
i
];
result
.
m_coefficients
[
i
]
+=
smaller
.
m_coefficients
[
i
];
}
}
...
@@ -150,9 +153,11 @@ class [[nodiscard]] Polynomial1D
...
@@ -150,9 +153,11 @@ class [[nodiscard]] Polynomial1D
{
{
const
Polynomial1D
&
p
=
*
this
;
const
Polynomial1D
&
p
=
*
this
;
Polynomial1D
ratio
(
this
->
degree
());
Polynomial1D
ratio
(
this
->
degree
());
ratio
.
m_coefficients
.
fill
(
0
);
std
::
fill
(
begin
(
ratio
.
m_coefficients
),
end
(
ratio
.
m_coefficients
),
0
);
Polynomial1D
remaining
(
this
->
degree
());
Polynomial1D
remaining
(
this
->
degree
());
copy_to
(
m_coefficients
,
remaining
.
m_coefficients
);
for
(
size_t
i
=
0
;
i
<
m_coefficients
.
size
();
++
i
)
{
remaining
.
m_coefficients
[
i
]
=
m_coefficients
[
i
];
}
const
size_t
p_degree
=
p
.
degree
();
const
size_t
p_degree
=
p
.
degree
();
const
size_t
q_degree
=
q
.
_getRealDegree
();
const
size_t
q_degree
=
q
.
_getRealDegree
();
...
@@ -176,9 +181,11 @@ class [[nodiscard]] Polynomial1D
...
@@ -176,9 +181,11 @@ class [[nodiscard]] Polynomial1D
{
{
const
Polynomial1D
&
p
=
*
this
;
const
Polynomial1D
&
p
=
*
this
;
Polynomial1D
ratio
(
this
->
degree
());
Polynomial1D
ratio
(
this
->
degree
());
ratio
.
m_coefficients
.
fill
(
0
);
std
::
fill
(
begin
(
ratio
.
m_coefficients
),
end
(
ratio
.
m_coefficients
),
0
);
Polynomial1D
remaining
(
this
->
degree
());
Polynomial1D
remaining
(
this
->
degree
());
copy_to
(
m_coefficients
,
remaining
.
m_coefficients
);
for
(
size_t
i
=
0
;
i
<
m_coefficients
.
size
();
++
i
)
{
remaining
.
m_coefficients
[
i
]
=
m_coefficients
[
i
];
}
const
size_t
p_degree
=
p
.
degree
();
const
size_t
p_degree
=
p
.
degree
();
const
size_t
q_degree
=
q
.
_getRealDegree
();
const
size_t
q_degree
=
q
.
_getRealDegree
();
...
@@ -266,18 +273,18 @@ class [[nodiscard]] Polynomial1D
...
@@ -266,18 +273,18 @@ class [[nodiscard]] Polynomial1D
size_t
real_degree
=
this
->
_getRealDegree
();
size_t
real_degree
=
this
->
_getRealDegree
();
if
(
real_degree
+
1
<
m_coefficients
.
size
())
{
if
(
real_degree
+
1
<
m_coefficients
.
size
())
{
Array
<
double
>
real_coefficients
(
real_degree
+
1
);
std
::
vector
<
double
>
real_coefficients
(
real_degree
+
1
);
for
(
size_t
i
=
0
;
i
<=
real_degree
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<=
real_degree
;
++
i
)
{
real_coefficients
[
i
]
=
m_coefficients
[
i
];
real_coefficients
[
i
]
=
m_coefficients
[
i
];
}
}
m_coefficients
=
real_coefficients
;
m_coefficients
=
std
::
move
(
real_coefficients
)
;
}
}
}
}
PUGS_INLINE
PUGS_INLINE
explicit
Polynomial1D
(
const
size_t
degree
)
:
m_coefficients
(
degree
+
1
)
explicit
Polynomial1D
(
const
size_t
degree
)
:
m_coefficients
(
degree
+
1
)
{
{
m_coefficients
.
fill
(
0
);
std
::
fill
(
m_coefficients
.
begin
(),
m_coefficients
.
end
(),
0
);
}
}
Polynomial1D
(
const
Polynomial1D
&
)
=
default
;
Polynomial1D
(
const
Polynomial1D
&
)
=
default
;
...
...
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