Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prog_kmeans
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
boris.stefanov
prog_kmeans
Commits
e1804f98
Commit
e1804f98
authored
2 years ago
by
Boris Stefanovic
Browse files
Options
Downloads
Patches
Plain Diff
EDIT: main cleanup
parent
b440d343
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/io.c
+8
-8
8 additions, 8 deletions
src/io.c
src/io.h
+6
-6
6 additions, 6 deletions
src/io.h
src/main.c
+17
-11
17 additions, 11 deletions
src/main.c
with
31 additions
and
25 deletions
src/io.c
+
8
−
8
View file @
e1804f98
...
...
@@ -5,14 +5,14 @@
#include
"vector.h"
int_t
read_int
(
FILE
*
file
)
{
int_t
io_
read_int
(
FILE
*
file
)
{
char
*
line
;
size_t
len
;
getline
(
&
line
,
&
len
,
file
);
return
strtol
(
line
,
NULL
,
10
);
}
fpt_t
read_fpt
(
FILE
*
file
)
{
fpt_t
io_
read_fpt
(
FILE
*
file
)
{
char
*
line
;
size_t
len
;
getline
(
&
line
,
&
len
,
file
);
...
...
@@ -20,7 +20,7 @@ fpt_t read_fpt(FILE* file) {
}
vector_int_t
*
line_to_vector_int
(
char
*
line
,
const
size_t
dim
)
{
vector_int_t
*
io_
line_to_vector_int
(
char
*
line
,
const
size_t
dim
)
{
vector_int_t
*
vector
=
vector_create_int
(
dim
);
char
*
tgt
=
line
;
char
*
token
=
NULL
;
...
...
@@ -32,7 +32,7 @@ vector_int_t* line_to_vector_int(char* line, const size_t dim) {
return
vector
;
}
vector_fpt_t
*
line_to_vector_fpt
(
char
*
line
,
const
size_t
dim
)
{
vector_fpt_t
*
io_
line_to_vector_fpt
(
char
*
line
,
const
size_t
dim
)
{
vector_fpt_t
*
vector
=
vector_create_fpt
(
dim
);
char
*
tgt
=
line
;
char
*
token
=
NULL
;
...
...
@@ -45,13 +45,13 @@ vector_fpt_t* line_to_vector_fpt(char* line, const size_t dim) {
}
list_points_int_t
*
get_vector_list_int
(
FILE
*
ifile
,
const
size_t
dim
)
{
list_points_int_t
*
io_
get_vector_list_int
(
FILE
*
ifile
,
const
size_t
dim
)
{
list_points_int_t
*
list
=
list_points_create_int
();
char
*
line
=
NULL
;
size_t
len
=
0
;
while
(
getline
(
&
line
,
&
len
,
ifile
)
!=
-
1
)
{
if
(
len
!=
0
)
{
vector_int_t
*
vector
=
line_to_vector_int
(
line
,
dim
);
vector_int_t
*
vector
=
io_
line_to_vector_int
(
line
,
dim
);
list_points_append_int
(
list
,
vector
);
free
(
line
);
}
...
...
@@ -59,13 +59,13 @@ list_points_int_t* get_vector_list_int(FILE* ifile, const size_t dim) {
return
list
;
}
list_points_fpt_t
*
get_vector_list_fpt
(
FILE
*
ifile
,
const
size_t
dim
)
{
list_points_fpt_t
*
io_
get_vector_list_fpt
(
FILE
*
ifile
,
const
size_t
dim
)
{
list_points_fpt_t
*
list
=
list_points_create_fpt
();
char
*
line
=
NULL
;
size_t
len
=
0
;
while
(
getline
(
&
line
,
&
len
,
ifile
)
!=
-
1
)
{
if
(
len
!=
0
)
{
vector_fpt_t
*
vector
=
line_to_vector_fpt
(
line
,
dim
);
vector_fpt_t
*
vector
=
io_
line_to_vector_fpt
(
line
,
dim
);
list_points_append_fpt
(
list
,
vector
);
free
(
line
);
}
...
...
This diff is collapsed.
Click to expand it.
src/io.h
+
6
−
6
View file @
e1804f98
...
...
@@ -8,19 +8,19 @@
#include
"vector.h"
int_t
read_int
(
FILE
*
file
);
int_t
io_
read_int
(
FILE
*
file
);
fpt_t
read_fpt
(
FILE
*
file
);
fpt_t
io_
read_fpt
(
FILE
*
file
);
vector_int_t
*
line_to_vector_int
(
char
*
line
,
const
size_t
dim
);
vector_int_t
*
io_
line_to_vector_int
(
char
*
line
,
const
size_t
dim
);
vector_fpt_t
*
line_to_vector_fpt
(
char
*
line
,
const
size_t
dim
);
vector_fpt_t
*
io_
line_to_vector_fpt
(
char
*
line
,
const
size_t
dim
);
list_points_int_t
*
get_vector_list_int
(
FILE
*
ifile
,
const
size_t
dim
);
list_points_int_t
*
io_
get_vector_list_int
(
FILE
*
ifile
,
const
size_t
dim
);
list_points_fpt_t
*
get_vector_list_fpt
(
FILE
*
ifile
,
const
size_t
dim
);
list_points_fpt_t
*
io_
get_vector_list_fpt
(
FILE
*
ifile
,
const
size_t
dim
);
void
io_write_clusters_to_file_int
(
FILE
*
file
,
cluster_int_t
**
clusters
,
const
size_t
cluster_count
);
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
17
−
11
View file @
e1804f98
...
...
@@ -28,21 +28,27 @@ bool init(int argc, char** argv, char** ipath, char** opath) {
fprintf
(
stderr
,
"IFILE: [ %s ] file does not exist !"
,
*
ipath
);
return
false
;
}
}
else
{
*
ipath
=
NULL
;
}
if
(
argc
>
2
)
*
opath
=
argv
[
2
];
*
opath
=
argc
>
2
?
argv
[
2
]
:
NULL
;
return
true
;
}
void
read_points_int
(
const
char
*
ipath
)
{
}
int
main
(
int
argc
,
char
**
argv
)
{
// INIT
char
*
ipath
=
NULL
;
char
*
opath
=
NULL
;
if
(
!
init
(
argc
,
argv
,
&
ipath
,
&
opath
))
return
EXIT_FAILURE
;
char
(
*
ipath
),
(
*
opath
);
if
(
!
init
(
argc
,
argv
,
&
ipath
,
&
opath
))
return
EXIT_FAILURE
;
// READ
FILE
*
ifile
=
ipath
!=
NULL
?
fopen
(
ipath
,
"r"
)
:
stdin
;
const
size_t
dim
=
read_int
(
ifile
);
const
size_t
nb_clusters
=
read_int
(
ifile
);
const
size_t
dim
=
io_
read_int
(
ifile
);
const
size_t
nb_clusters
=
io_
read_int
(
ifile
);
if
(
0
<=
dim
)
{
printf
(
"DIMENSION MUST BE STRICTLY POSITIVE !
\n
"
);
return
EXIT_FAILURE
;
...
...
@@ -51,20 +57,20 @@ int main(int argc, char** argv) {
printf
(
"NUMBER OF CLUSTERS MUST BE STRICTLY POSITIVE !
\n
"
);
return
EXIT_FAILURE
;
}
list_points_int_t
*
list
=
get_vector_list_int
(
ifile
,
dim
);
list_points_int_t
*
list
=
io_
get_vector_list_int
(
ifile
,
dim
);
fclose
(
ifile
);
ifile
=
NULL
;
const
size_t
point_count
=
list
->
size
;
point
_int_t
**
points
=
list_points_to_array_int
(
list
);
vector
_int_t
**
points
=
list_points_to_array_int
(
list
);
list_points_destroy_int
(
list
,
false
);
list
=
NULL
;
// ALGORITHM
vecto
r_int_t
**
clusters
=
kmeans_init_clusters_int
((
const
point
_int_t
**
)
points
,
point_count
,
nb_clusters
);
cluste
r_int_t
**
clusters
=
kmeans_init_clusters_int
((
const
vector
_int_t
**
)
points
,
point_count
,
nb_clusters
);
kmeans_int
(
points
,
point_count
,
clusters
,
nb_clusters
,
distance_euclid_int
);
//TODO: choose dist func with command line
// WRITE
FILE
*
ofile
=
opath
!=
NULL
?
fopen
(
opath
,
"w"
)
:
stdout
;
fprintf
(
ofile
,
"%lud
\n
%lud
\n
"
,
dim
,
nb_clusters
);
io_write_clusters_to_file_int
(
ofile
,
point
s
,
point_count
);
io_write_clusters_to_file_int
(
ofile
,
cluster
s
,
point_count
);
fclose
(
ofile
);
return
EXIT_SUCCESS
;
}
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