Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_142 - Travail Pratique 007
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
florian.burgener
ISC_142 - Travail Pratique 007
Commits
d0b60da6
Commit
d0b60da6
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
70851c3c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
matrix.c
+28
-11
28 additions, 11 deletions
matrix.c
matrix.h
+2
-2
2 additions, 2 deletions
matrix.h
matrix_compute.c
+2
-4
2 additions, 4 deletions
matrix_compute.c
matrix_test.c
+1
-1
1 addition, 1 deletion
matrix_test.c
with
33 additions
and
18 deletions
matrix.c
+
28
−
11
View file @
d0b60da6
/**
* @file matrix.c
* @author Florian Burgener
* @author Florian Burgener
(florian.burgener@etu.hesge.ch)
* @brief Implémentation de librairie matrix.
* @version 1.0
* @date 2021-11-16
...
...
@@ -11,7 +11,6 @@
#include
"matrix.h"
#include
<math.h>
#include
<stdbool.h>
#include
<stdint.h>
#include
<stdio.h>
...
...
@@ -22,15 +21,19 @@ error_code matrix_alloc(matrix *mat, int32_t m, int32_t n) {
mat
->
n
=
n
;
int32_t
**
data
=
(
int32_t
**
)
malloc
(
sizeof
(
int32_t
*
)
*
mat
->
m
);
if
(
data
==
NULL
)
if
(
data
==
NULL
)
{
return
err
;
}
mat
->
data
=
data
;
for
(
int32_t
i
=
0
;
i
<
m
;
i
+=
1
)
{
int32_t
*
row
=
(
int32_t
*
)
malloc
(
sizeof
(
int32_t
)
*
n
);
if
(
row
==
NULL
)
if
(
row
==
NULL
)
{
return
err
;
}
mat
->
data
[
i
]
=
row
;
}
...
...
@@ -38,7 +41,9 @@ error_code matrix_alloc(matrix *mat, int32_t m, int32_t n) {
}
error_code
matrix_init
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
,
int32_t
val
)
{
matrix_alloc
(
mat
,
m
,
n
);
if
(
matrix_alloc
(
mat
,
m
,
n
)
==
err
)
{
return
err
;
}
for
(
int32_t
y
=
0
;
y
<
m
;
y
+=
1
)
{
for
(
int32_t
x
=
0
;
x
<
n
;
x
+=
1
)
{
...
...
@@ -75,9 +80,13 @@ error_code matrix_destroy(matrix *mat) {
}
error_code
matrix_init_from_array
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
,
int32_t
data
[],
int32_t
s
)
{
if
(
m
*
n
!=
s
)
if
(
m
*
n
!=
s
)
{
return
err
;
}
if
(
matrix_alloc
(
mat
,
m
,
n
)
==
err
)
{
return
err
;
matrix_alloc
(
mat
,
m
,
n
);
}
for
(
int32_t
y
=
0
;
y
<
mat
->
m
;
y
+=
1
)
{
for
(
int32_t
x
=
0
;
x
<
mat
->
n
;
x
+=
1
)
{
...
...
@@ -89,7 +98,9 @@ error_code matrix_init_from_array(matrix *mat, int32_t m, int32_t n, int32_t dat
}
error_code
matrix_clone
(
matrix
*
cloned
,
const
matrix
mat
)
{
matrix_alloc
(
cloned
,
mat
.
m
,
mat
.
n
);
if
(
matrix_alloc
(
cloned
,
mat
.
m
,
mat
.
n
)
==
err
)
{
return
err
;
}
for
(
int32_t
y
=
0
;
y
<
mat
.
m
;
y
+=
1
)
{
for
(
int32_t
x
=
0
;
x
<
mat
.
n
;
x
+=
1
)
{
...
...
@@ -101,7 +112,9 @@ error_code matrix_clone(matrix *cloned, const matrix mat) {
}
error_code
matrix_transpose
(
matrix
*
transposed
,
const
matrix
mat
)
{
matrix_alloc
(
transposed
,
mat
.
n
,
mat
.
m
);
if
(
matrix_alloc
(
transposed
,
mat
.
n
,
mat
.
m
)
==
err
)
{
return
err
;
}
for
(
int32_t
y
=
0
;
y
<
mat
.
m
;
y
+=
1
)
{
for
(
int32_t
x
=
0
;
x
<
mat
.
n
;
x
+=
1
)
{
...
...
@@ -113,9 +126,13 @@ error_code matrix_transpose(matrix *transposed, const matrix mat) {
}
error_code
matrix_extract_submatrix
(
matrix
*
sub
,
const
matrix
mat
,
int32_t
m0
,
int32_t
m1
,
int32_t
n0
,
int32_t
n1
)
{
if
(
m1
<
m0
||
n1
<
n0
||
m0
<
0
||
n0
<
0
||
m1
>
mat
.
m
||
n1
>
mat
.
n
)
if
(
m1
<
=
m0
||
n1
<
=
n0
||
m0
<
0
||
n0
<
0
||
m1
>
mat
.
m
||
n1
>
mat
.
n
)
{
return
err
;
matrix_alloc
(
sub
,
m1
-
m0
,
n1
-
n0
);
}
if
(
matrix_alloc
(
sub
,
m1
-
m0
,
n1
-
n0
)
==
err
)
{
return
err
;
}
for
(
int32_t
y
=
m0
;
y
<
m1
;
y
+=
1
)
{
for
(
int32_t
x
=
n0
;
x
<
n1
;
x
+=
1
)
{
...
...
This diff is collapsed.
Click to expand it.
matrix.h
+
2
−
2
View file @
d0b60da6
/**
* @file matrix.h
* @author Florian Burgener
* @author Florian Burgener
(florian.burgener@etu.hesge.ch)
* @brief Header de librairie matrix.
* @version 1.0
* @date 2021-11-16
...
...
@@ -11,7 +11,7 @@
#ifndef MATRIX_HEADER
#define MATRIX_HEADER
#include
<math.h>
#include
<stdbool.h>
#include
<stdint.h>
...
...
This diff is collapsed.
Click to expand it.
matrix_compute.c
+
2
−
4
View file @
d0b60da6
/**
* @file matrix_compute.c
* @author Florian Burgener
* @author Florian Burgener
(florian.burgener@etu.hesge.ch)
* @brief Démonstration de libraire matrix.
* @version 1.0
* @date 2021-11-16
...
...
@@ -9,11 +9,9 @@
*
*/
#include
<math.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
"matrix.h"
...
...
@@ -42,7 +40,7 @@ int main() {
printf
(
"******
\n
"
);
matrix
mat7
;
matrix_extract_submatrix
(
&
mat7
,
mat4
,
1
,
3
,
1
,
2
);
matrix_extract_submatrix
(
&
mat7
,
mat4
,
1
,
4
,
1
,
3
);
matrix_print
(
mat7
);
printf
(
"*******
\n
"
);
...
...
This diff is collapsed.
Click to expand it.
matrix_test.c
+
1
−
1
View file @
d0b60da6
/**
* @file matrix_test.c
* @author Florian Burgener et Quentin Fasler
* @author Florian Burgener
(florian.burgener@etu.hesge.ch)
et Quentin Fasler
* @brief Seul les tests ont été fait en commun pour gagner du temps.
* @version 1.0
* @date 2021-11-16
...
...
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