cpp : Added documentation
This commit is contained in:
27
cpp/data.cpp
27
cpp/data.cpp
@ -16,14 +16,6 @@ int32_t print(const np::Shape& shape) noexcept {
|
||||
|
||||
template<typename T>
|
||||
int32_t print(const np::Array<T>& array, const char* const format) noexcept {
|
||||
//printf("[");
|
||||
//const size_t length = np::prod(array.shape);
|
||||
//for(size_t i = 0; i < length - 1; ++i)
|
||||
// //std::cout << array[i] << " ";
|
||||
// printf("%f ", array[i]);
|
||||
////std::cout << array[array.shape[0] - 1] << "]\n";
|
||||
//printf("%f]\n", array[length - 1]);
|
||||
|
||||
char format_space[BUFFER_SIZE] = { 0 };
|
||||
snprintf(format_space, BUFFER_SIZE,"%s ", format);
|
||||
char format_close[BUFFER_SIZE] = { 0 };
|
||||
@ -75,7 +67,7 @@ int32_t print_feat(const np::Array<uint8_t>& array, const np::Slice& slice) noex
|
||||
int32_t print(const np::Array<uint8_t>& array, const np::Slice& slice) noexcept {
|
||||
int32_t num_written = 0;
|
||||
if (array.shape.length == 1) {
|
||||
const size_t max = slice.y - 1; //std::min(slice.y, array.shape[0] - 1);
|
||||
const size_t max = slice.y - 1;
|
||||
num_written += printf("[");
|
||||
for (size_t i = slice.x; i < max; ++i)
|
||||
num_written += printf("%hu ", array[i]);
|
||||
@ -98,7 +90,7 @@ int32_t print(const np::Array<uint8_t>& array, const np::Slice& slice) noexcept
|
||||
int32_t print(const np::Array<uint32_t>& array, const np::Slice& slice) noexcept {
|
||||
int32_t num_written = 0;
|
||||
if (array.shape.length == 1) {
|
||||
const size_t max = slice.y - 1; //std::min(slice.y, array.shape[0] - 1);
|
||||
const size_t max = slice.y - 1;
|
||||
num_written += printf("[");
|
||||
for (size_t i = slice.x; i < max; ++i)
|
||||
num_written += printf("%iu ", array[i]);
|
||||
@ -121,7 +113,6 @@ int32_t print(const np::Array<uint32_t>& array, const np::Slice& slice) noexcept
|
||||
int32_t print(const np::Array<int32_t>& array, const np::Slice& slice) noexcept {
|
||||
int32_t num_written = 0;
|
||||
num_written += printf("[");
|
||||
//size_t k = slice.x * array.shape[1] * array.shape[2] + slice.y * array.shape[2] + slice.z;
|
||||
size_t k = slice.x * array.shape[1];
|
||||
for (size_t i = k; i < k + (slice.y - slice.x); ++i) {
|
||||
num_written += printf("%5i ", array[i]);
|
||||
@ -133,7 +124,6 @@ int32_t print(const np::Array<int32_t>& array, const np::Slice& slice) noexcept
|
||||
int32_t print(const np::Array<uint16_t>& array, const np::Slice& slice) noexcept {
|
||||
int32_t num_written = 0;
|
||||
num_written += printf("[");
|
||||
//size_t k = slice.x * array.shape[1] * array.shape[2] + slice.y * array.shape[2] + slice.z;
|
||||
size_t k = slice.x * array.shape[1];
|
||||
for (size_t i = k; i < k + (slice.y - slice.x); ++i) {
|
||||
num_written += printf("%5hu ", array[i]);
|
||||
@ -171,7 +161,6 @@ static inline np::Array<uint8_t> load_set(const char* const set_name) {
|
||||
if (c == ' ' || c == '\n') {
|
||||
buff[j] = '\0';
|
||||
a[i++] = static_cast<uint8_t>(atoi(buff));
|
||||
//memset(buff, 0, STRING_INT_SIZE);
|
||||
j = 0;
|
||||
}
|
||||
else
|
||||
@ -189,6 +178,11 @@ static inline np::Array<uint8_t> load_set(const char* const set_name) {
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load the datasets.
|
||||
*
|
||||
* @return Array containing X_train, y_trait, X_test, y_test
|
||||
*/
|
||||
std::array<np::Array<uint8_t>, 4> load_datasets(void) {
|
||||
return {
|
||||
load_set(DATA_DIR "/X_train.bin"), load_set(DATA_DIR "/y_train.bin"),
|
||||
@ -201,10 +195,3 @@ void print_error_file(const char* const file_dir) noexcept {
|
||||
fprintf(stderr, "Can't open %s, error code = %d : %s\n", file_dir, errno, buff);
|
||||
// delete buff;
|
||||
}
|
||||
|
||||
//size_t np::prod(const np::Shape& shape, const size_t& offset) noexcept {
|
||||
// size_t result = shape[offset];
|
||||
// for(size_t i = 1 + offset; i < shape.length; ++i)
|
||||
// result *= shape[i];
|
||||
// return result;
|
||||
//}
|
||||
|
Reference in New Issue
Block a user