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
51ab7843
Commit
51ab7843
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add matrix transpose
parent
5201518a
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
+10
-1
10 additions, 1 deletion
main.c
matrix.c
+16
-0
16 additions, 0 deletions
matrix.c
with
26 additions
and
1 deletion
main.c
+
10
−
1
View file @
51ab7843
...
...
@@ -11,24 +11,33 @@
#include
"matrix.h"
int
main
()
{
matrix
mat
,
cloned
;
matrix
mat
,
cloned
,
transposed
;
int32_t
m
=
3
;
int32_t
n
=
4
;
int32_t
s
=
m
*
n
;
int32_t
val
=
0
;
int32_t
data
[
12
]
=
{
2
,
1
,
-
1
,
-
2
,
3
,
1
,
1
,
3
,
1
,
4
,
-
1
,
-
1
};
// Init
matrix_init
(
&
mat
,
m
,
n
,
val
);
printf
(
"Empty matrix %dx%d
\n
"
,
m
,
n
);
matrix_print
(
mat
);
// Init from array
matrix_init_from_array
(
&
mat
,
m
,
n
,
data
,
s
);
printf
(
"Matrix %dx%d from array
\n
"
,
m
,
n
);
matrix_print
(
mat
);
// Clone
matrix_clone
(
&
cloned
,
mat
);
printf
(
"Cloned matrix :
\n
"
);
matrix_print
(
cloned
);
// Transpose
matrix_transpose
(
&
transposed
,
mat
);
printf
(
"Transposed matrix :
\n
"
);
matrix_print
(
transposed
);
// Free the memory
matrix_destroy
(
&
mat
);
matrix_destroy
(
&
cloned
);
matrix_destroy
(
&
transposed
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
matrix.c
+
16
−
0
View file @
51ab7843
...
...
@@ -106,3 +106,19 @@ error_code matrix_destroy(matrix *mat) {
return
ok
;
}
error_code
matrix_transpose
(
matrix
*
transposed
,
const
matrix
mat
)
{
error_code
code
=
matrix_alloc
(
transposed
,
mat
.
n
,
mat
.
m
);
if
(
code
==
err
)
{
return
err
;
}
for
(
int
i
=
0
;
i
<
mat
.
m
;
i
++
)
{
for
(
int
k
=
0
;
k
<
mat
.
n
;
k
++
)
{
transposed
->
data
[
k
][
i
]
=
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