Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
72fc00b7
There was an error fetching the commit references. Please try again later.
Commit
72fc00b7
authored
5 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Fixed assignments operators for StaticVector: +=, -=, *=, /=
parent
f9bb987c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TNL/Containers/StaticVector.h
+10
-34
10 additions, 34 deletions
src/TNL/Containers/StaticVector.h
src/TNL/Containers/StaticVector.hpp
+15
-45
15 additions, 45 deletions
src/TNL/Containers/StaticVector.hpp
with
25 additions
and
79 deletions
src/TNL/Containers/StaticVector.h
+
10
−
34
View file @
72fc00b7
...
...
@@ -73,48 +73,24 @@ public:
*/
static
String
getType
();
template
<
typename
StaticVectorOperationType
>
StaticVector
&
operator
=
(
const
StaticVectorOperationType
&
vo
);
template
<
typename
VectorExpression
>
StaticVector
&
operator
=
(
const
VectorExpression
&
expression
);
/**
* \brief Adding operator.
*
* This function adds \e vector from this static vector and returns the resulting static vector.
* The addition is applied to all the vector elements separately.
* \param vector Reference to another vector.
*/
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
&
operator
+=
(
const
StaticVector
&
v
);
StaticVector
&
operator
+=
(
const
VectorExpression
&
expression
);
/**
* \brief Subtracting operator.
*
* This function subtracts \e vector from this static vector and returns the resulting static vector.
* The subtraction is applied to all the vector elements separately.
* \param vector Reference to another vector.
*/
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
&
operator
-=
(
const
StaticVector
&
v
);
StaticVector
&
operator
-=
(
const
VectorExpression
&
expression
);
/**
* \brief Multiplication by number.
*
* This function multiplies this static vector by \e c and returns the resulting static vector.
* The multiplication is applied to all the vector elements separately.
* \param c Multiplicator.
*/
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
&
operator
*=
(
const
Real
&
c
);
StaticVector
&
operator
*=
(
const
VectorExpression
&
expression
);
/**
* \brief Division by number
*
* This function divides this static veSize of static array. Number of its elements.ctor by \e c and returns the resulting static vector.
* The division is applied to all the vector elements separately.
* \param c Divisor.
*/
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
&
operator
/=
(
const
Real
&
c
);
StaticVector
&
operator
/=
(
const
VectorExpression
&
expression
);
/**
* \brief Changes the type of static vector to \e OtherReal while the size remains the same.
...
...
This diff is collapsed.
Click to expand it.
src/TNL/Containers/StaticVector.hpp
+
15
−
45
View file @
72fc00b7
...
...
@@ -17,40 +17,6 @@
namespace
TNL
{
namespace
Containers
{
namespace
detail
{
////
// Functors used together with StaticFor for static loop unrolling in the
// implementation of the StaticVector
template
<
typename
LeftReal
,
typename
RightReal
=
LeftReal
>
struct
addVectorFunctor
{
void
__cuda_callable__
operator
()(
int
i
,
LeftReal
*
data
,
const
RightReal
*
v
)
const
{
data
[
i
]
+=
v
[
i
];
}
};
template
<
typename
LeftReal
,
typename
RightReal
=
LeftReal
>
struct
subtractVectorFunctor
{
void
__cuda_callable__
operator
()(
int
i
,
LeftReal
*
data
,
const
RightReal
*
v
)
const
{
data
[
i
]
-=
v
[
i
];
}
};
template
<
typename
LeftReal
,
typename
RightReal
=
LeftReal
>
struct
scalarMultiplicationFunctor
{
void
__cuda_callable__
operator
()(
int
i
,
LeftReal
*
data
,
const
RightReal
v
)
const
{
data
[
i
]
*=
v
;
}
};
}
// namespace detail
template
<
int
Size
,
typename
Real
>
template
<
typename
T1
,
typename
T2
,
...
...
@@ -96,43 +62,47 @@ String StaticVector< Size, Real >::getType()
}
template
<
int
Size
,
typename
Real
>
template
<
typename
RHS
>
template
<
typename
VectorExpression
>
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
=
(
const
RHS
&
rhs
)
StaticVector
<
Size
,
Real
>::
operator
=
(
const
VectorExpression
&
expression
)
{
Algorithms
::
VectorAssignment
<
StaticVector
<
Size
,
Real
>
,
RHS
>::
assignStatic
(
*
this
,
rhs
);
Algorithms
::
VectorAssignment
<
StaticVector
<
Size
,
Real
>
,
VectorExpression
>::
assignStatic
(
*
this
,
expression
);
return
*
this
;
}
template
<
int
Size
,
typename
Real
>
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
+=
(
const
StaticVector
&
v
)
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
+=
(
const
VectorExpression
&
expression
)
{
StaticFor
<
0
,
Size
>::
exec
(
detail
::
addVectorFunctor
<
Real
>
{},
this
->
getData
(),
v
.
getData
()
);
Algorithms
::
VectorAssignmentWithOperation
<
StaticVector
,
VectorExpression
>::
additionStatic
(
*
this
,
expression
);
return
*
this
;
}
template
<
int
Size
,
typename
Real
>
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
-=
(
const
StaticVector
&
v
)
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
-=
(
const
VectorExpression
&
expression
)
{
StaticFor
<
0
,
Size
>::
exec
(
detail
::
subtractVectorFunctor
<
Real
>
{},
this
->
getData
(),
v
.
getData
()
);
Algorithms
::
VectorAssignmentWithOperation
<
StaticVector
,
VectorExpression
>::
subtractionStatic
(
*
this
,
expression
);
return
*
this
;
}
template
<
int
Size
,
typename
Real
>
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
*=
(
const
Real
&
c
)
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
*=
(
const
VectorExpression
&
expression
)
{
StaticFor
<
0
,
Size
>::
exec
(
detail
::
scalarMultiplicationFunctor
<
Real
>
{},
this
->
getData
(),
c
);
Algorithms
::
VectorAssignmentWithOperation
<
StaticVector
,
VectorExpression
>::
multiplicationStatic
(
*
this
,
expression
);
return
*
this
;
}
template
<
int
Size
,
typename
Real
>
template
<
typename
VectorExpression
>
__cuda_callable__
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
/=
(
const
Real
&
c
)
StaticVector
<
Size
,
Real
>&
StaticVector
<
Size
,
Real
>::
operator
/=
(
const
VectorExpression
&
expression
)
{
StaticFor
<
0
,
Size
>::
exec
(
detail
::
scalarMultiplicationFunctor
<
Real
>
{},
this
->
getData
(),
1.0
/
c
);
Algorithms
::
VectorAssignmentWithOperation
<
StaticVector
,
VectorExpression
>::
divisionStatic
(
*
this
,
expression
);
return
*
this
;
}
...
...
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