Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp_introduction
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cp1_ws19
cpp_introduction
Commits
bc6943ae
Commit
bc6943ae
authored
Oct 28, 2019
by
Kevin Höllring
Browse files
Options
Downloads
Patches
Plain Diff
Fix broken iteration in matrix class
parent
515e228a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/matrix.h
+50
-50
50 additions, 50 deletions
src/matrix.h
with
50 additions
and
50 deletions
src/matrix.h
+
50
−
50
View file @
bc6943ae
#ifndef __MATRIX_H__
#ifndef __MATRIX_H__
#define __MATRIX_H__
#define __MATRIX_H__
#include
<vector>
#include
<iostream>
#include
<iostream>
#include
<vector>
namespace
magic
{
namespace
magic
{
using
std
::
vector
;
using
std
::
vector
;
...
@@ -9,7 +9,7 @@ namespace magic {
...
@@ -9,7 +9,7 @@ namespace magic {
// This is a custom Matrix type to allow for matrix multiplication
// This is a custom Matrix type to allow for matrix multiplication
class
Matrix
{
class
Matrix
{
public:
public:
Matrix
(
uint
8
_t
rows
,
uint
8
_t
columns
)
{
Matrix
(
uint
32
_t
rows
,
uint
32
_t
columns
)
{
this
->
_rows
=
rows
;
this
->
_rows
=
rows
;
this
->
_columns
=
columns
;
this
->
_columns
=
columns
;
this
->
entries
.
assign
(
rows
,
vector
<
int32_t
>
(
columns
,
0
));
this
->
entries
.
assign
(
rows
,
vector
<
int32_t
>
(
columns
,
0
));
...
@@ -19,9 +19,7 @@ namespace magic {
...
@@ -19,9 +19,7 @@ namespace magic {
entries
[
i
][
j
]
=
value
;
entries
[
i
][
j
]
=
value
;
}
}
int32_t
getValue
(
uint8_t
i
,
uint8_t
j
)
{
int32_t
getValue
(
uint8_t
i
,
uint8_t
j
)
{
return
entries
[
i
][
j
];
}
return
entries
[
i
][
j
];
}
// Calculate the matrix product with another matrix
// Calculate the matrix product with another matrix
Matrix
multiply
(
Matrix
&
other
)
{
Matrix
multiply
(
Matrix
&
other
)
{
...
@@ -29,10 +27,12 @@ namespace magic {
...
@@ -29,10 +27,12 @@ namespace magic {
Matrix
result
(
this
->
_rows
,
other
.
_columns
);
Matrix
result
(
this
->
_rows
,
other
.
_columns
);
// Calculate all entries in the resulting matrix
// Calculate all entries in the resulting matrix
for
(
uint8_t
r
=
0
;
r
<
this
->
_rows
;
r
++
)
{
for
(
uint32_t
r
=
0
;
r
<
this
->
_rows
;
r
++
)
{
for
(
uint8_t
c
=
0
;
c
<
other
.
_columns
;
c
++
)
{
for
(
uint32_t
c
=
0
;
c
<
other
.
_columns
;
c
++
)
{
for
(
uint8_t
link
=
0
;
link
<
this
->
_columns
;
link
++
)
{
for
(
uint32_t
link
=
0
;
link
<
this
->
_columns
;
link
++
)
{
int32_t
res
=
result
.
getValue
(
r
,
c
)
+
this
->
getValue
(
r
,
link
)
*
other
.
getValue
(
link
,
c
);
int32_t
res
=
result
.
getValue
(
r
,
c
)
+
this
->
getValue
(
r
,
link
)
*
other
.
getValue
(
link
,
c
);
result
.
setValue
(
r
,
c
,
res
);
result
.
setValue
(
r
,
c
,
res
);
}
}
}
}
...
@@ -56,10 +56,10 @@ namespace magic {
...
@@ -56,10 +56,10 @@ namespace magic {
}
}
private
:
private
:
uint
8
_t
_rows
;
uint
32
_t
_rows
;
uint
8
_t
_columns
;
uint
32
_t
_columns
;
vector
<
vector
<
int32_t
>>
entries
;
vector
<
vector
<
int32_t
>>
entries
;
};
};
}
}
// namespace magic
#endif
#endif
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