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
5201518a
Commit
5201518a
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add matrix clone and destroy
parent
6a5aa9a8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.c
+7
-1
7 additions, 1 deletion
main.c
matrix.c
+28
-5
28 additions, 5 deletions
matrix.c
matrix.h
+0
-2
0 additions, 2 deletions
matrix.h
tests
+0
-0
0 additions, 0 deletions
tests
with
35 additions
and
8 deletions
main.c
+
7
−
1
View file @
5201518a
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include
"matrix.h"
#include
"matrix.h"
int
main
()
{
int
main
()
{
matrix
mat
;
matrix
mat
,
cloned
;
int32_t
m
=
3
;
int32_t
m
=
3
;
int32_t
n
=
4
;
int32_t
n
=
4
;
int32_t
s
=
m
*
n
;
int32_t
s
=
m
*
n
;
...
@@ -23,6 +23,12 @@ int main() {
...
@@ -23,6 +23,12 @@ int main() {
matrix_init_from_array
(
&
mat
,
m
,
n
,
data
,
s
);
matrix_init_from_array
(
&
mat
,
m
,
n
,
data
,
s
);
printf
(
"Matrix %dx%d from array
\n
"
,
m
,
n
);
printf
(
"Matrix %dx%d from array
\n
"
,
m
,
n
);
matrix_print
(
mat
);
matrix_print
(
mat
);
matrix_clone
(
&
cloned
,
mat
);
printf
(
"Cloned matrix :
\n
"
);
matrix_print
(
cloned
);
// Free the memory
matrix_destroy
(
&
mat
);
matrix_destroy
(
&
cloned
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
matrix.c
+
28
−
5
View file @
5201518a
...
@@ -77,9 +77,32 @@ error_code matrix_print(const matrix mat) {
...
@@ -77,9 +77,32 @@ error_code matrix_print(const matrix mat) {
return
ok
;
return
ok
;
}
}
void
swap
(
int
*
x
,
int
*
y
)
error_code
matrix_clone
(
matrix
*
cloned
,
const
matrix
mat
)
{
{
error_code
code
=
matrix_alloc
(
cloned
,
mat
.
m
,
mat
.
n
);
int
tmp
=
*
x
;
if
(
code
==
err
)
{
*
x
=
*
y
;
return
err
;
*
y
=
tmp
;
}
for
(
int
i
=
0
;
i
<
mat
.
m
;
i
++
)
{
for
(
int
k
=
0
;
k
<
mat
.
n
;
k
++
)
{
cloned
->
data
[
i
][
k
]
=
mat
.
data
[
i
][
k
];
}
}
return
ok
;
}
error_code
matrix_destroy
(
matrix
*
mat
)
{
// Free each row
for
(
int32_t
i
=
0
;
i
<
mat
->
m
;
i
++
)
{
free
(
mat
->
data
[
i
]);
}
// Free the data and reset the number of row and col
free
(
mat
->
data
);
mat
->
m
=
-
1
;
mat
->
n
=
-
1
;
mat
->
data
=
NULL
;
return
ok
;
}
}
This diff is collapsed.
Click to expand it.
matrix.h
+
0
−
2
View file @
5201518a
...
@@ -39,6 +39,4 @@ error_code matrix_get(int32_t *elem, const matrix mat, int32_t ix, int32_t iy);
...
@@ -39,6 +39,4 @@ error_code matrix_get(int32_t *elem, const matrix mat, int32_t ix, int32_t iy);
error_code
matrix_set
(
matrix
mat
,
int32_t
ix
,
int32_t
iy
,
int32_t
elem
);
error_code
matrix_set
(
matrix
mat
,
int32_t
ix
,
int32_t
iy
,
int32_t
elem
);
void
swap
(
int
*
x
,
int
*
y
);
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests
deleted
100755 → 0
+
0
−
0
View file @
6a5aa9a8
File deleted
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