-
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.
added subsetting functionality to c approach
- Loading branch information
1 parent
ef03633
commit a840642
Showing
21 changed files
with
711 additions
and
438 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "Colon.h" | ||
|
||
void colon_numeric(size_t vec_index, double start, double end, | ||
VectorManager *vm) { | ||
if (end == start) { | ||
free(vm->numerics[vec_index].data); | ||
vm->numerics[vec_index].data = NULL; | ||
vm->numerics[vec_index].size = 0; | ||
} else if (end > start) { | ||
int size = end - start + 1; | ||
alloc_numeric(vec_index, size, vm); | ||
for (int i = 0; i < vm->numerics[vec_index].size; i++) { | ||
vm->numerics[vec_index].data[i] = start + (double)(i); | ||
} | ||
} else if (start > end) { | ||
int size = start - end + 1; | ||
alloc_numeric(vec_index, size, vm); | ||
for (int i = end; i >= start; i--) { | ||
vm->numerics[vec_index].data[i] = (double)(i); | ||
} | ||
} | ||
} |
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,9 @@ | ||
#include "VectorManager.h" | ||
|
||
#ifndef COLON_H | ||
#define COLON_H | ||
|
||
void colon_numeric(size_t vec_index, double start, double end, | ||
VectorManager *vm); | ||
|
||
#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
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,33 @@ | ||
#include "DetermineSize.h" | ||
|
||
size_t determine_size(VectorManager *vm, int *num_vars, int *types_vars, | ||
int n) { | ||
if (n == 0) | ||
return 0; | ||
|
||
size_t size = 0; | ||
if (types_vars[0] == 0) { | ||
size = vm->logicals[num_vars[0]].size; | ||
} else if (types_vars[1] == 1) { | ||
size = vm->integers[num_vars[0]].size; | ||
} else if (types_vars[2] == 2) { | ||
size = vm->numerics[num_vars[0]].size; | ||
} | ||
|
||
for (int i = 0; i < n; i++) { | ||
if (types_vars[i] == 0) { | ||
if (vm->logicals[num_vars[i]].size > size) { | ||
size = vm->logicals[num_vars[i]].size; | ||
} | ||
} else if (types_vars[i] == 1) { | ||
if (vm->integers[num_vars[i]].size > size) { | ||
size = vm->integers[num_vars[i]].size; | ||
} | ||
} else if (types_vars[i] == 2) { | ||
if (vm->numerics[num_vars[i]].size > size) { | ||
size = vm->numerics[num_vars[i]].size; | ||
} | ||
} | ||
} | ||
return size; | ||
} |
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,8 @@ | ||
#include "VectorManager.h" | ||
|
||
#ifndef DETERMINE_SIZE_H | ||
#define DETERMINE_SIZE_H | ||
|
||
size_t determine_size(VectorManager *vm, int *num_vars, int *types_vars, int n); | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "GetAndSet.h" | ||
|
||
double get_num(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->numerics[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return vm->numerics[vec_index].data[index % vm->numerics[vec_index].size]; | ||
} | ||
|
||
double *set_num(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->numerics[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return &vm->numerics[vec_index].data[index % vm->numerics[vec_index].size]; | ||
} | ||
|
||
double get_scalar_num(size_t vec_index, VectorManager *vm) { | ||
return vm->scalarNums[vec_index]; | ||
} | ||
|
||
double *set_scalar_num(size_t vec_index, VectorManager *vm) { | ||
return &vm->scalarNums[vec_index]; | ||
} | ||
|
||
int get_int(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->integers[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return vm->integers[vec_index].data[index % vm->integers[vec_index].size]; | ||
} | ||
|
||
int *set_int(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->integers[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return &vm->integers[vec_index].data[index % vm->integers[vec_index].size]; | ||
} | ||
|
||
int get_scalar_int(size_t vec_index, VectorManager *vm) { | ||
return vm->scalarInts[vec_index]; | ||
} | ||
|
||
int *set_scalar_int(size_t vec_index, VectorManager *vm) { | ||
return &vm->scalarInts[vec_index]; | ||
} | ||
|
||
bool get_log(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->logicals[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return vm->logicals[vec_index].data[index % vm->logicals[vec_index].size]; | ||
} | ||
|
||
bool *set_log(size_t index, size_t vec_index, VectorManager *vm) { | ||
if (index >= vm->logicals[vec_index].size || index < 0) { | ||
free_and_exit(vm, "Index out of bounds"); | ||
} | ||
return &vm->logicals[vec_index].data[index % vm->logicals[vec_index].size]; | ||
} | ||
|
||
bool get_scalar_log(size_t vec_index, VectorManager *vm) { | ||
return vm->scalarLogs[vec_index]; | ||
} | ||
|
||
bool *set_scalar_log(size_t vec_index, VectorManager *vm) { | ||
return &vm->scalarLogs[vec_index]; | ||
} |
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,20 @@ | ||
#include "VectorManager.h" | ||
#include "header.h" | ||
|
||
#ifndef GET_SET_H | ||
#define GET_SET_H | ||
|
||
double get_num(size_t index, size_t vec_index, VectorManager *vm); | ||
double *set_num(size_t index, size_t vec_index, VectorManager *vm); | ||
double get_scalar_num(size_t vec_index, VectorManager *vm); | ||
double *set_scalar_num(size_t vec_index, VectorManager *vm); | ||
int get_int(size_t index, size_t vec_index, VectorManager *vm); | ||
int *set_int(size_t index, size_t vec_index, VectorManager *vm); | ||
int get_scalar_int(size_t vec_index, VectorManager *vm); | ||
int *set_scalar_int(size_t vec_index, VectorManager *vm); | ||
bool get_log(size_t index, size_t vec_index, VectorManager *vm); | ||
bool *set_log(size_t index, size_t vec_index, VectorManager *vm); | ||
bool get_scalar_log(size_t vec_index, VectorManager *vm); | ||
bool *set_scalar_log(size_t vec_index, VectorManager *vm); | ||
|
||
#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
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,31 @@ | ||
#include "Print.h" | ||
|
||
void print_numeric(size_t vec_idx, VectorManager *vm) { | ||
for (int i = 0; i < vm->numerics[vec_idx].size; i++) { | ||
printf("%f\n", vm->numerics[vec_idx].data[i]); | ||
} | ||
} | ||
|
||
void print_integer(size_t vec_idx, VectorManager *vm) { | ||
for (int i = 0; i < vm->integers[vec_idx].size; i++) { | ||
printf("%d\n", vm->integers[vec_idx].data[i]); | ||
} | ||
} | ||
|
||
void print_logical(size_t vec_idx, VectorManager *vm) { | ||
for (int i = 0; i < vm->logicals[vec_idx].size; i++) { | ||
printf("%i\n", vm->logicals[vec_idx].data[i]); | ||
} | ||
} | ||
|
||
void print_scalar_numeric(size_t vec_idx, VectorManager *vm) { | ||
printf("%f\n", vm->scalarNums[vec_idx]); | ||
} | ||
|
||
void print_scalar_integer(size_t vec_idx, VectorManager *vm) { | ||
printf("%d\n", vm->scalarInts[vec_idx]); | ||
} | ||
|
||
void print_scalar_logical(size_t vec_idx, VectorManager *vm) { | ||
printf("%d\n", vm->scalarLogs[vec_idx]); | ||
} |
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,14 @@ | ||
#include "VectorManager.h" | ||
#include "header.h" | ||
|
||
#ifndef PRINT_H | ||
#define PRINT_H | ||
|
||
void print_numeric(size_t vec_idx, VectorManager *vm); | ||
void print_integer(size_t vec_idx, VectorManager *vm); | ||
void print_logical(size_t vec_idx, VectorManager *vm); | ||
void print_scalar_numeric(size_t vec_idx, VectorManager *vm); | ||
void print_scalar_integer(size_t vec_idx, VectorManager *vm); | ||
void print_scalar_logical(size_t vec_idx, VectorManager *vm); | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.