Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewldesousa committed Jul 3, 2024
1 parent 76e2e31 commit 923c27f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,22 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install compiler
id: install_cc
uses: rlalik/setup-cpp-compiler@master
with:
compiler: latest

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgtest-dev
sudo apt-get install -y cmake
# Install Google Test
sudo apt-get install -y libgtest-dev
# - name: Build and run tests
# run: |
# mkdir build
# cd build
# cmake ..
# make
# ./tests/test_main
- name: Build and run tests
run: |
mkdir build
cd build
cmake ..
make
./tests/test_main
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
"future": "cpp",
"regex": "cpp",
"typeindex": "cpp",
"valarray": "cpp"
"valarray": "cpp",
"numeric": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"__nullptr": "cpp"
}
}
18 changes: 8 additions & 10 deletions apps/and.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
// move operator
#include <utility>

// include exp
#include <cmath>


int main(int argc, char** argv) {
if (argc > 1 && std::string(argv[1]) == "debug") Logger::get_instance().set_debug_mode(true);
else if (argc > 1) throw std::runtime_error("Invalid argument in main function. Use 'debug' to enable debug mode.");

int num_epochs = 50000, num_samples = 4;
int num_epochs = 5000000, num_samples = 4;
float learning_rate = 0.001;

// weights shared pointer
Expand Down Expand Up @@ -41,18 +44,13 @@ int main(int argc, char** argv) {
for (int i = 0; i < num_epochs; i++) {
std::shared_ptr<Scalar<double>> loss = Scalar<double>::make(0);
for (int j = 0; j < num_samples; j++) {
auto z = Scalar<double>::make(0);

for (int k = 0; k < weights.size(); k++) {
if (k == weights.size() - 1) z = z + weights[k];
else z = z + weights[k] * X[j][k];
}
auto z = weights[0] * X[j][0] + weights[1] * X[j][1] + weights[2];
auto a = sigmoid(z);
loss = cross_entropy(Y[j], a) + loss;
// loss = cross_entropy(Y[j], a) + loss;
}

loss = loss / Scalar<double>::make(num_samples);
loss->backward();
// loss = loss / Scalar<double>::make(num_samples);
// loss->backward();

// update weights
for (int j = 0; j < weights.size(); j++) {
Expand Down
3 changes: 2 additions & 1 deletion scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <filesystem>
#include "utils.h"
#include <cmath>

static int id_counter;

Expand Down Expand Up @@ -146,7 +147,7 @@ class Scalar: public std::enable_shared_from_this<Scalar<T>> {

// log
friend std::shared_ptr<Scalar<T>> log(std::shared_ptr<Scalar<T>> rhs) {
auto result = Scalar<T>::make(std::log(rhs->value));
auto result = Scalar<T>::make(log(rhs->value));

result->children.insert(rhs);
rhs->in_degrees++;
Expand Down

0 comments on commit 923c27f

Please sign in to comment.