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
a5d90560
Commit
a5d90560
authored
7 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Added first version of TinyVector
parent
3bc84ec5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+4
-0
4 additions, 0 deletions
CMakeLists.txt
algebra/TinyVector.hpp
+151
-0
151 additions, 0 deletions
algebra/TinyVector.hpp
main.cpp
+16
-0
16 additions, 0 deletions
main.cpp
with
171 additions
and
0 deletions
CMakeLists.txt
+
4
−
0
View file @
a5d90560
...
@@ -39,6 +39,10 @@ include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
...
@@ -39,6 +39,10 @@ include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
add_subdirectory
(
utils
)
add_subdirectory
(
utils
)
include_directories
(
utils
)
include_directories
(
utils
)
# Pastis algebra
#add_subdirectory(algebra)
include_directories
(
algebra
)
# Pastis experimental
# Pastis experimental
add_subdirectory
(
experimental
)
add_subdirectory
(
experimental
)
include_directories
(
experimental
)
include_directories
(
experimental
)
...
...
This diff is collapsed.
Click to expand it.
algebra/TinyVector.hpp
0 → 100644
+
151
−
0
View file @
a5d90560
#ifndef TINY_VECTOR_HPP
#define TINY_VECTOR_HPP
#include
<cassert>
#include
<iostream>
template
<
size_t
N
,
typename
T
=
double
>
class
TinyVector
{
private:
T
m_values
[
N
];
static_assert
((
N
>
0
),
"TinyVector size must be strictly positive"
);
public:
KOKKOS_INLINE_FUNCTION
T
operator
,(
const
TinyVector
&
v
)
{
T
t
=
m_values
[
0
]
*
v
.
m_values
[
0
];
for
(
size_t
i
=
1
;
i
<
N
;
++
i
)
{
t
+=
m_values
[
i
]
*
v
.
m_values
[
i
];
}
return
std
::
move
(
t
);
}
KOKKOS_INLINE_FUNCTION
friend
TinyVector
operator
*
(
const
T
&
t
,
const
TinyVector
&
v
)
{
TinyVector
tv
;
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
tv
.
m_values
[
i
]
=
t
*
v
.
m_values
[
i
];
}
return
std
::
move
(
tv
);
}
KOKKOS_INLINE_FUNCTION
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
TinyVector
&
v
)
{
os
<<
'('
<<
v
.
m_values
[
0
];
for
(
size_t
i
=
1
;
i
<
N
;
++
i
)
{
os
<<
','
<<
v
.
m_values
[
i
];
}
os
<<
')'
;
return
os
;
}
KOKKOS_INLINE_FUNCTION
TinyVector
operator
+
(
const
TinyVector
&
v
)
const
{
TinyVector
sum
;
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
sum
[
i
]
=
m_values
[
i
]
+
v
.
m_values
[
i
];
}
return
std
::
move
(
sum
);
}
KOKKOS_INLINE_FUNCTION
TinyVector
operator
-
(
const
TinyVector
&
v
)
const
{
TinyVector
difference
;
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
difference
[
i
]
=
m_values
[
i
]
-
v
.
m_values
[
i
];
}
return
std
::
move
(
difference
);
}
KOKKOS_INLINE_FUNCTION
TinyVector
&
operator
+=
(
const
TinyVector
&
v
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
+=
v
.
m_values
[
i
];
}
return
*
this
;
}
KOKKOS_INLINE_FUNCTION
TinyVector
&
operator
-=
(
const
TinyVector
&
v
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
-=
v
.
m_values
[
i
];
}
return
*
this
;
}
KOKKOS_INLINE_FUNCTION
TinyVector
&
operator
=
(
const
T
&
t
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
=
t
;
}
return
*
this
;
}
KOKKOS_INLINE_FUNCTION
T
&
operator
[](
const
size_t
&
i
)
{
assert
(
i
<
N
);
return
m_values
[
i
];
}
KOKKOS_INLINE_FUNCTION
const
T
&
operator
[](
const
size_t
&
i
)
const
{
assert
(
i
<
N
);
return
m_values
[
i
];
}
KOKKOS_INLINE_FUNCTION
const
TinyVector
&
operator
=
(
const
TinyVector
&
v
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
=
v
.
m_values
[
i
];
}
return
*
this
;
}
KOKKOS_INLINE_FUNCTION
TinyVector
&
operator
=
(
TinyVector
&&
v
)
=
default
;
KOKKOS_INLINE_FUNCTION
TinyVector
()
{
;
}
KOKKOS_INLINE_FUNCTION
TinyVector
(
const
T
&
t
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
=
t
;
}
}
KOKKOS_INLINE_FUNCTION
TinyVector
(
const
TinyVector
&
v
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
m_values
[
i
]
=
v
.
m_values
[
i
];
}
}
KOKKOS_INLINE_FUNCTION
TinyVector
(
TinyVector
&&
v
)
=
default
;
KOKKOS_INLINE_FUNCTION
~
TinyVector
()
{
;
}
};
#endif // TINYVECTOR_HPP
This diff is collapsed.
Click to expand it.
main.cpp
+
16
−
0
View file @
a5d90560
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
#include
<AcousticSolver.hpp>
#include
<AcousticSolver.hpp>
#include
<AcousticSolverTest.hpp>
#include
<AcousticSolverTest.hpp>
#include
<TinyVector.hpp>
#include
<CLI/CLI.hpp>
#include
<CLI/CLI.hpp>
#include
<cassert>
#include
<cassert>
#include
<limits>
#include
<limits>
...
@@ -107,6 +109,12 @@ int main(int argc, char *argv[])
...
@@ -107,6 +109,12 @@ int main(int argc, char *argv[])
method_cost_map
[
"AcousticSolver"
]
=
timer
.
seconds
();
method_cost_map
[
"AcousticSolver"
]
=
timer
.
seconds
();
}
}
Kokkos
::
View
<
TinyVector
<
2
,
double
>*
[
2
]
>
test
(
"test"
,
10
);
constexpr
size_t
N
=
3
;
std
::
cout
<<
"sizeof(TinyVector<"
<<
N
<<
",double>)="
<<
sizeof
(
TinyVector
<
N
,
double
>
)
<<
std
::
endl
;
std
::
cout
<<
"sizeof(double)="
<<
sizeof
(
double
)
<<
std
::
endl
;
Kokkos
::
finalize
();
Kokkos
::
finalize
();
std
::
cout
<<
"----------------------
\n
"
;
std
::
cout
<<
"----------------------
\n
"
;
...
@@ -125,5 +133,13 @@ int main(int argc, char *argv[])
...
@@ -125,5 +133,13 @@ int main(int argc, char *argv[])
<<
rang
::
style
::
reset
<<
'\n'
;
<<
rang
::
style
::
reset
<<
'\n'
;
}
}
TinyVector
<
2
>
x
=
1
;
TinyVector
<
2
>
y
=
2
;
std
::
cout
<<
x
<<
"-"
<<
y
<<
"="
<<
x
-
y
<<
std
::
endl
;
std
::
cout
<<
x
<<
"+"
<<
y
<<
"="
<<
x
+
y
<<
std
::
endl
;
std
::
cout
<<
"3*"
<<
x
<<
'='
<<
3
*
x
<<
std
::
endl
;
x
[
1
]
=
3
;
y
[
1
]
=
0.1
;
std
::
cout
<<
"< "
<<
x
<<
" | "
<<
y
<<
" > = "
<<
(
x
,
y
)
<<
std
::
endl
;
return
0
;
return
0
;
}
}
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