Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Samer Afach
Polymath
Commits
07043ecb
Commit
07043ecb
authored
Nov 08, 2016
by
Samer Afach
Browse files
Inplace operators use std::transform(); and fixed resize problem when
resizing from bigger to smaller matrix.
parent
d5638d0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/internal/Matrix.h
View file @
07043ecb
...
...
@@ -394,9 +394,9 @@ void Matrix<T,M>::resize(size_type rows, size_type columns, const T& initialValu
this
->
_matEls
.
resize
(
newSize
);
this
->
_rows
=
rows
;
this
->
_columns
=
columns
;
for
(
size_type
i
=
0
;
i
<
oldRows
;
i
++
)
for
(
size_type
i
=
0
;
i
<
(
oldRows
>
rows
?
rows
:
oldRows
)
;
i
++
)
{
for
(
size_type
j
=
0
;
j
<
oldColumns
;
j
++
)
for
(
size_type
j
=
0
;
j
<
(
oldColumns
>
columns
?
columns
:
oldColumns
)
;
j
++
)
{
this
->
at
(
i
,
j
)
=
oldMat
.
at
(
i
,
j
);
}
...
...
@@ -482,6 +482,7 @@ bool Matrix<T,M>::operator!=(const Matrix<T,M>& rhs)
return
!
(
*
this
==
rhs
);
}
//FIXME: Consider non-square matrices
template
<
typename
T
,
int
M
>
void
Matrix
<
T
,
M
>::
transpose_inplace
()
{
...
...
@@ -689,28 +690,32 @@ Matrix<std::complex<T>,M> operator-(const Matrix<T,M>& lhs, const Matrix<std::co
template
<
typename
T
,
int
M
>
Matrix
<
T
,
M
>&
Matrix
<
T
,
M
>::
operator
+=
(
const
Matrix
<
T
,
M
>&
rhs
)
{
(
*
this
)
=
(
*
this
)
+
rhs
;
std
::
transform
(
this
->
begin
(),
this
->
end
(),
rhs
.
begin
(),
this
->
begin
(),
std
::
plus
<
T
>
());
// (*this) = (*this) + rhs;
return
*
this
;
}
template
<
typename
T
,
int
M
>
Matrix
<
T
,
M
>&
Matrix
<
T
,
M
>::
operator
-=
(
const
Matrix
<
T
,
M
>&
rhs
)
{
(
*
this
)
=
(
*
this
)
-
rhs
;
std
::
transform
(
this
->
begin
(),
this
->
end
(),
rhs
.
begin
(),
this
->
begin
(),
std
::
minus
<
T
>
());
// (*this) = (*this) - rhs;
return
*
this
;
}
template
<
typename
T
,
int
M
>
Matrix
<
T
,
M
>&
Matrix
<
T
,
M
>::
operator
*=
(
const
Matrix
<
T
,
M
>&
rhs
)
{
(
*
this
)
=
(
*
this
)
*
rhs
;
std
::
transform
(
this
->
begin
(),
this
->
end
(),
rhs
.
begin
(),
this
->
begin
(),
std
::
multiplies
<
T
>
());
// (*this) = (*this) * rhs;
return
*
this
;
}
template
<
typename
T
,
int
M
>
Matrix
<
T
,
M
>&
Matrix
<
T
,
M
>::
operator
*=
(
const
T
&
rhs
)
{
(
*
this
)
=
(
*
this
)
*
rhs
;
std
::
transform
(
this
->
begin
(),
this
->
end
(),
this
->
begin
(),
std
::
bind2nd
(
std
::
multiplies
<
T
>
(),
rhs
));
// (*this) = (*this) * rhs;
return
*
this
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment