Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66866340
types.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jun 18, 13:54
Size
3 KB
Mime Type
text/x-c++
Expires
Thu, Jun 20, 13:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18307801
Attached To
rTAMAAS tamaas
types.cpp
View Options
/**
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "types.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
/* VectorProxy definitions */
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
VectorProxy
<
T
>::
VectorProxy
(
T
*
mem
,
UInt
n
)
:
Proxy
<
T
,
1
>
()
{
this
->
data
.
wrapMemory
(
mem
,
n
);
this
->
n
[
0
]
=
n
;
this
->
computeStrides
();
}
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
void
VectorProxy
<
T
>::
mul
(
const
MatrixProxy
<
T
>
&
mat
,
const
VectorProxy
<
T
>
&
vec
)
{
auto
n_mat
=
mat
.
sizes
();
auto
n_vec
=
vec
.
sizes
();
TAMAAS_ASSERT
(
n_mat
[
1
]
==
n_vec
[
0
],
"matrix and vector sizes do not match"
);
TAMAAS_ASSERT
(
n_mat
[
0
]
==
this
->
n
[
0
],
"matrix and result vector sizes do not match"
);
// No parallelism here
for
(
UInt
i
=
0
;
i
<
n_mat
[
0
]
;
++
i
)
{
for
(
UInt
j
=
0
;
j
<
n_vec
[
0
]
;
++
j
)
{
(
*
this
)(
i
)
+=
mat
(
i
,
j
)
*
vec
(
j
);
}
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
T
VectorProxy
<
T
>::
dot
(
const
VectorProxy
<
T
>
&
vec
)
{
TAMAAS_ASSERT
(
this
->
n
[
0
]
==
vec
.
sizes
()[
0
],
"vector sizes do not match"
);
T
res
=
0
;
// No parallelism here
for
(
UInt
i
=
0
;
i
<
this
->
n
[
0
]
;
i
++
)
res
+=
(
*
this
)(
i
)
*
vec
(
i
);
return
res
;
}
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
T
VectorProxy
<
T
>::
l2norm
()
const
{
T
res
=
0
;
// No parallelism here
for
(
UInt
i
=
0
;
i
<
this
->
n
[
0
]
;
i
++
)
res
+=
(
*
this
)(
i
)
*
(
*
this
)(
i
);
return
std
::
sqrt
(
res
);
}
/* -------------------------------------------------------------------------- */
/* MatrixProxy definitions */
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
MatrixProxy
<
T
>::
MatrixProxy
(
T
*
mem
,
UInt
n
,
UInt
m
)
:
Proxy
<
T
,
2
>
()
{
this
->
data
.
wrapMemory
(
mem
,
n
*
m
);
this
->
n
[
0
]
=
n
;
this
->
n
[
1
]
=
m
;
this
->
computeStrides
();
}
/* -------------------------------------------------------------------------- */
#define TYPE_INSTANCIATE(type) template class VectorProxy<type>; \
template class MatrixProxy<type>
TYPE_INSTANCIATE
(
Real
);
TYPE_INSTANCIATE
(
UInt
);
TYPE_INSTANCIATE
(
Complex
);
TYPE_INSTANCIATE
(
int
);
TYPE_INSTANCIATE
(
unsigned
long
);
#undef TYPE_INSTANCIATE
__END_TAMAAS__
Event Timeline
Log In to Comment