Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CplusplusCourse - outdated
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Sebastien Ponce
CplusplusCourse - outdated
Commits
f27c74e3
Commit
f27c74e3
authored
4 years ago
by
Sebastien Ponce
Browse files
Options
Downloads
Plain Diff
Merge branch 'nvector' into 'master'
A few NVector improvements See merge request
!18
parents
3673bfcf
d326f756
No related branches found
No related tags found
1 merge request
!18
A few NVector improvements
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
code/move/NVector.hpp
+2
-4
2 additions, 4 deletions
code/move/NVector.hpp
code/move/solution/NVector.sol.hpp
+11
-13
11 additions, 13 deletions
code/move/solution/NVector.sol.hpp
code/move/solution/trymove.sol.cpp
+1
-2
1 addition, 2 deletions
code/move/solution/trymove.sol.cpp
with
14 additions
and
19 deletions
code/move/NVector.hpp
+
2
−
4
View file @
f27c74e3
#include
<ostream>
#include
<assert.h>
#include
<algorithm>
#include
<numeric>
template
<
int
N
,
class
T
=
float
>
class
NVector
{
...
...
@@ -114,10 +115,7 @@ NVector<N,T>& NVector<N,T>::operator+=(const NVector<N,T> other) {
template
<
int
N
,
class
T
>
T
NVector
<
N
,
T
>::
sqnorm
()
const
{
T
norm
;
std
::
for_each
(
m_data
,
m_data
+
N
,
[
&
norm
](
T
a
)
{
norm
+=
a
*
a
;
});
return
norm
;
return
std
::
inner_product
(
m_data
,
m_data
+
N
,
m_data
,
T
());
}
template
<
int
N
,
class
T
>
...
...
This diff is collapsed.
Click to expand it.
code/move/solution/NVector.sol.hpp
+
11
−
13
View file @
f27c74e3
#include
<ostream>
#include
<assert.h>
#include
<algorithm>
#include
<numeric>
template
<
int
N
,
class
T
=
float
>
class
NVector
{
...
...
@@ -14,15 +15,15 @@ public:
~
NVector
();
NVector
&
operator
-
()
const
;
NVector
&
operator
+
(
const
NVector
other
)
const
;
NVector
&
operator
-
(
const
NVector
other
)
const
;
NVector
&
operator
*
(
const
NVector
other
)
const
;
NVector
&
operator
+
(
const
NVector
&
other
)
const
;
NVector
&
operator
-
(
const
NVector
&
other
)
const
;
NVector
&
operator
*
(
const
NVector
&
other
)
const
;
NVector
&
operator
*
(
const
T
factor
)
const
;
NVector
&
operator
/
(
const
T
dividend
)
const
;
NVector
&
operator
=
(
NVector
other
);
NVector
&
operator
+=
(
const
NVector
other
);
NVector
&
operator
+=
(
const
NVector
&
other
);
T
sqnorm
()
const
;
bool
operator
<
(
const
NVector
a
)
const
;
bool
operator
<
(
const
NVector
&
a
)
const
;
void
print
(
std
::
ostream
&
os
)
const
;
template
<
int
M
,
class
R
>
friend
void
swap
(
NVector
<
M
,
R
>
&
a
,
NVector
<
M
,
R
>
&
b
);
...
...
@@ -71,7 +72,7 @@ NVector<N,T>& NVector<N,T>::operator-() const {
}
template
<
int
N
,
class
T
>
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
+
(
const
NVector
<
N
,
T
>
other
)
const
{
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
+
(
const
NVector
<
N
,
T
>
&
other
)
const
{
NVector
res
;
std
::
transform
(
m_data
,
m_data
+
N
,
other
.
m_data
,
res
.
m_data
,
...
...
@@ -80,7 +81,7 @@ NVector<N,T>& NVector<N,T>::operator+(const NVector<N,T> other) const {
}
template
<
int
N
,
class
T
>
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
-
(
const
NVector
<
N
,
T
>
other
)
const
{
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
-
(
const
NVector
<
N
,
T
>
&
other
)
const
{
NVector
res
;
std
::
transform
(
m_data
,
m_data
+
N
,
other
.
m_data
,
res
.
m_data
,
...
...
@@ -111,7 +112,7 @@ NVector<N,T>& NVector<N,T>::operator=(NVector<N,T> other) {
}
template
<
int
N
,
class
T
>
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
+=
(
const
NVector
<
N
,
T
>
other
)
{
NVector
<
N
,
T
>&
NVector
<
N
,
T
>::
operator
+=
(
const
NVector
<
N
,
T
>
&
other
)
{
std
::
transform
(
m_data
,
m_data
+
N
,
other
.
m_data
,
m_data
,
[](
T
a
,
T
b
)
{
return
a
+
b
;});
...
...
@@ -120,14 +121,11 @@ NVector<N,T>& NVector<N,T>::operator+=(const NVector<N,T> other) {
template
<
int
N
,
class
T
>
T
NVector
<
N
,
T
>::
sqnorm
()
const
{
T
norm
;
std
::
for_each
(
m_data
,
m_data
+
N
,
[
&
norm
](
T
a
)
{
norm
+=
a
*
a
;
});
return
norm
;
return
std
::
inner_product
(
m_data
,
m_data
+
N
,
m_data
,
T
());
}
template
<
int
N
,
class
T
>
bool
NVector
<
N
,
T
>::
operator
<
(
const
NVector
<
N
,
T
>
other
)
const
{
bool
NVector
<
N
,
T
>::
operator
<
(
const
NVector
<
N
,
T
>
&
other
)
const
{
return
this
->
sqnorm
()
<
other
.
sqnorm
();
}
...
...
This diff is collapsed.
Click to expand it.
code/move/solution/trymove.sol.cpp
+
1
−
2
View file @
f27c74e3
...
...
@@ -26,8 +26,7 @@ template<class T>
std
::
vector
<
T
>
getRandomVector
(
int
len
)
{
// allocate vectors
std
::
vector
<
T
>
v
(
len
);
// fill and randomize v
for
(
int
i
=
0
;
i
<
len
;
i
++
)
v
[
i
]
=
T
();
// randomize v
randomize
(
v
);
return
v
;
}
...
...
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