bool run_tests() { std::vector<std::tuple<int, int, int, int, float>> problem_sizes = {std::make_tuple(20, 50, 15, 1, 1e-5), std::make_tuple(5, 10, 5, 65, 1e-4) }; std::mt19937 gen(2); bool status = true; for (auto problem : problem_sizes) { int alphabet_size, T, L, minibatch; float tol; std::tie(alphabet_size, T, L, minibatch, tol) = problem; std::vector<float> acts = genActs(alphabet_size * T * minibatch); std::vector<std::vector<int>> labels; std::vector<int> sizes; for (int mb = 0; mb < minibatch; ++mb) { int actual_length = L; labels.push_back(genLabels(alphabet_size, actual_length)); sizes.push_back(T); } float diff = grad_check(T, alphabet_size, acts, labels, sizes); status &= (diff < tol); } return status; }
bool inf_test() { const int alphabet_size = 15; const int T = 50; const int L = 10; const int minibatch = 1; std::vector<int> labels = genLabels(alphabet_size, L); labels[0] = 2; std::vector<int> label_lengths = {L}; std::vector<float> acts = genActs(alphabet_size * T * minibatch); for (int i = 0; i < T; ++i) acts[alphabet_size * i + 2] = -1e30; std::vector<int> sizes; sizes.push_back(T); std::vector<float> grads(alphabet_size * T); float cost; ctcComputeInfo info; info.loc = CTC_CPU; info.num_threads = 1; size_t cpu_alloc_bytes; throw_on_error(get_workspace_size(label_lengths.data(), sizes.data(), alphabet_size, sizes.size(), info, &cpu_alloc_bytes), "Error: get_workspace_size in inf_test"); void* ctc_cpu_workspace = malloc(cpu_alloc_bytes); throw_on_error(compute_ctc_loss(acts.data(), grads.data(), labels.data(), label_lengths.data(), sizes.data(), alphabet_size, sizes.size(), &cost, ctc_cpu_workspace, info), "Error: compute_ctc_loss in inf_test"); free(ctc_cpu_workspace); bool status = true; status &= std::isinf(cost); for (int i = 0; i < alphabet_size * T; ++i) status &= !std::isnan(grads[i]); return status; }
int main(){ char ch; char str[330][32]; int i=0; int j; FILE * f; f = fopen("progs/fucktorial.ternas", "r"); assert(f != NULL); while(fgets(str[i], 31, f)){ i++; } fclose(f); /* Holds one more than largest index being used */ max=i; /* Generate labels */ for(i=0;i<max;i++){ genLabels(str[i]); } /* modify to also do dec to tern conversions, use stdout */ for(i=0;i<max;i++){ opcode(str[i]); } printf("\n"); puts("Here are my labels"); for(i=0;i<nextlabel;i++){ for(j=0;j<LABELSIZE;j++){ putchar(labelNames[i][j]); } printf(" at address %d",labelTrytes[i][1]); putchar('\n'); } return 0; }