Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-matrix
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-matrix
Commits
18a49919
Commit
18a49919
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add sub matrix
parent
51ab7843
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
main.c
+6
-1
6 additions, 1 deletion
main.c
matrix.c
+18
-0
18 additions, 0 deletions
matrix.c
with
24 additions
and
1 deletion
main.c
+
6
−
1
View file @
18a49919
...
...
@@ -11,7 +11,7 @@
#include
"matrix.h"
int
main
()
{
matrix
mat
,
cloned
,
transposed
;
matrix
mat
,
cloned
,
transposed
,
sub
;
int32_t
m
=
3
;
int32_t
n
=
4
;
int32_t
s
=
m
*
n
;
...
...
@@ -33,10 +33,15 @@ int main() {
matrix_transpose
(
&
transposed
,
mat
);
printf
(
"Transposed matrix :
\n
"
);
matrix_print
(
transposed
);
// Sub matrix
matrix_extract_submatrix
(
&
sub
,
transposed
,
1
,
4
,
1
,
3
);
printf
(
"Sub matrix :
\n
"
);
matrix_print
(
sub
);
// Free the memory
matrix_destroy
(
&
mat
);
matrix_destroy
(
&
cloned
);
matrix_destroy
(
&
transposed
);
matrix_destroy
(
&
sub
);
return
EXIT_SUCCESS
;
...
...
This diff is collapsed.
Click to expand it.
matrix.c
+
18
−
0
View file @
18a49919
...
...
@@ -122,3 +122,21 @@ error_code matrix_transpose(matrix *transposed, const matrix mat) {
return
ok
;
}
error_code
matrix_extract_submatrix
(
matrix
*
sub
,
const
matrix
mat
,
int32_t
m0
,
int32_t
m1
,
int32_t
n0
,
int32_t
n1
)
{
if
(
m0
<
0
||
m1
>
mat
.
m
||
n0
<
0
||
n1
>
mat
.
n
||
m0
>
m1
||
n0
>
n1
)
{
return
err
;
}
error_code
code
=
matrix_alloc
(
sub
,
m1
-
m0
,
n1
-
n0
);
if
(
code
==
err
)
{
return
err
;
}
for
(
int
i
=
m0
;
i
<
m1
;
i
++
)
{
for
(
int
k
=
n0
;
k
<
n1
;
k
++
)
{
sub
->
data
[
i
-
m0
][
k
-
n0
]
=
mat
.
data
[
i
][
k
];
}
}
return
ok
;
}
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