-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cff7f62
commit 61a5570
Showing
6 changed files
with
210 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include "SubsetManager.h" | ||
#include "VectorManager.h" | ||
|
||
SubsetManager create_sm() { | ||
SubsetManager sm; | ||
sm.logicals_subsets = NULL; | ||
sm.integers_subsets = NULL; | ||
sm.numerics_subsets = NULL; | ||
sm.i_vectors = 0; | ||
sm.l_vectors = 0; | ||
sm.n_vectors = 0; | ||
return sm; | ||
} | ||
|
||
void free_sm(SubsetManager *sm) { | ||
if (sm->numerics_subsets) | ||
free(sm->numerics_subsets); | ||
if (sm->integers_subsets) | ||
free(sm->integers_subsets); | ||
if (sm->logicals_subsets) | ||
free(sm->logicals_subsets); | ||
} | ||
|
||
// TODO: pass size_t** indices as this is individual for each vector | ||
void add_numerics_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm) { | ||
if (n == 0) | ||
return; | ||
|
||
SubsetNumeric *vectors = (SubsetNumeric *)malloc(n * sizeof(SubsetNumeric)); | ||
if (!vectors) { | ||
fprintf(stderr, "Memory allocation failed\n"); | ||
exit(1); | ||
} | ||
sm->numerics_subsets = vectors; | ||
sm->n_vectors = n; | ||
|
||
for (size_t i = 0; i < n; i++) { | ||
sm->numerics_subsets[i].vec = vm->numerics[vec_indices[i]]; | ||
sm->numerics_subsets[i].indices = indices; | ||
sm->numerics_subsets[i].size_indices = size_indices; | ||
} | ||
} | ||
|
||
void add_integers_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm) { | ||
if (n == 0) | ||
return; | ||
|
||
SubsetInteger *vectors = (SubsetInteger *)malloc(n * sizeof(SubsetInteger)); | ||
if (!vectors) { | ||
fprintf(stderr, "Memory allocation failed\n"); | ||
exit(1); | ||
} | ||
sm->integers_subsets = vectors; | ||
sm->n_vectors = n; | ||
|
||
for (size_t i = 0; i < n; i++) { | ||
sm->integers_subsets[i].vec = vm->integers[vec_indices[i]]; | ||
sm->integers_subsets[i].indices = indices; | ||
sm->integers_subsets[i].size_indices = size_indices; | ||
} | ||
} | ||
|
||
void add_logicals_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm) { | ||
if (n == 0) | ||
return; | ||
|
||
SubsetLogical *vectors = (SubsetLogical *)malloc(n * sizeof(SubsetLogical)); | ||
if (!vectors) { | ||
fprintf(stderr, "Memory allocation failed\n"); | ||
exit(1); | ||
} | ||
sm->logicals_subsets = vectors; | ||
sm->n_vectors = n; | ||
|
||
for (size_t i = 0; i < n; i++) { | ||
sm->logicals_subsets[i].vec = vm->logicals[vec_indices[i]]; | ||
sm->logicals_subsets[i].indices = indices; | ||
sm->logicals_subsets[i].size_indices = size_indices; | ||
} | ||
} | ||
|
||
double get_num_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
// TODO: check that index is within indices | ||
return sm->numerics_subsets[vec_index] | ||
.vec | ||
->data[sm->numerics_subsets[vec_index] | ||
.indices[index % sm->numerics_subsets[vec_index].vec->size]]; | ||
} | ||
|
||
double *set_num_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
return &( | ||
sm->numerics_subsets[vec_index] | ||
.vec->data[sm->numerics_subsets[vec_index].indices | ||
[index % sm->numerics_subsets[vec_index].vec->size] % | ||
sm->numerics_subsets[vec_index].size_indices]); | ||
} | ||
|
||
int get_int_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
return sm->integers_subsets[vec_index] | ||
.vec | ||
->data[sm->integers_subsets[vec_index] | ||
.indices[index % sm->integers_subsets[vec_index].vec->size] % | ||
sm->integers_subsets[vec_index].size_indices]; | ||
} | ||
|
||
int *set_int_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
return &( | ||
sm->integers_subsets[vec_index] | ||
.vec->data[sm->integers_subsets[vec_index].indices | ||
[index % sm->integers_subsets[vec_index].vec->size] % | ||
sm->integers_subsets[vec_index].size_indices]); | ||
} | ||
|
||
bool get_log_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
return sm->logicals_subsets[vec_index] | ||
.vec | ||
->data[sm->logicals_subsets[vec_index] | ||
.indices[index % sm->logicals_subsets[vec_index].vec->size] % | ||
sm->logicals_subsets[vec_index].size_indices]; | ||
} | ||
|
||
bool *set_log_subset(size_t index, size_t vec_index, SubsetManager *sm) { | ||
return &( | ||
sm->logicals_subsets[vec_index] | ||
.vec->data[sm->logicals_subsets[vec_index].indices | ||
[index % sm->logicals_subsets[vec_index].vec->size] % | ||
sm->logicals_subsets[vec_index].size_indices]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef SUBSET_MANAGER_H | ||
#define SUBSET_MANAGER_H | ||
|
||
#include "VectorManager.h" | ||
|
||
typedef struct { | ||
Numeric *vec; | ||
size_t *indices; | ||
size_t size_indices; | ||
} SubsetNumeric; | ||
|
||
typedef struct { | ||
Integer *vec; | ||
size_t *indices; | ||
size_t size_indices; | ||
} SubsetInteger; | ||
|
||
typedef struct { | ||
Logical *vec; | ||
size_t *indices; | ||
size_t size_indices; | ||
} SubsetLogical; | ||
|
||
typedef struct { | ||
SubsetLogical *logicals_subsets; | ||
SubsetInteger *integers_subsets; | ||
SubsetNumeric *numerics_subsets; | ||
size_t l_vectors; | ||
size_t i_vectors; | ||
size_t n_vectors; | ||
} SubsetManager; | ||
|
||
SubsetManager create_sm(); | ||
void free_sm(SubsetManager *sm); | ||
void add_numerics_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm); | ||
|
||
void add_integers_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm); | ||
void add_logicals_subsets(size_t *vec_indices, size_t n, VectorManager *vm, | ||
size_t *indices, size_t size_indices, | ||
SubsetManager *sm); | ||
|
||
double get_num_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
double *set_num_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
int get_int_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
int *set_int_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
bool get_log_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
bool *set_log_subset(size_t index, size_t vec_index, SubsetManager *sm); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters