jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit e3b403e0fed7926fc886bfb1fb307ee8539cc875
parent e74103c3940e4fa789cfd3ec3d966bad0afb168c
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Mon, 10 Aug 2020 19:23:43 -0700

Continued frustrations with copy constructor

Diffstat:
MCMakeLists.txt | 13+++++++------
Mexample.cpp | 4++++
Msrc/bpnn.cpp | 26++++++++++++++++++++++++--
Msrc/bpnn.hpp | 1+
4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -5,11 +5,12 @@ set(CMAKE_CXX_COMPILER "g++") set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (DEBUG) - set(COMPILE_FLAGS, "-Wall") -else() - set(COMPILE_FLAGS, "-w") -endif() +set(COMPILE_FLAGS, "-w") +# if (DEBUG) +# set(COMPILE_FLAGS, "-Wall") +# else() +# set(COMPILE_FLAGS, "-w") +# endif() if (FAST) set(COMPILE_FLAGS "${COMPILE_FLAGS} -O3") @@ -26,7 +27,7 @@ if (AVX) set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -D AVX") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} -w") if (PYTHON) diff --git a/example.cpp b/example.cpp @@ -33,5 +33,9 @@ double bench(int batch_sz, int epochs) int main(int argc, char** argv) { + if (argc < 3) { + std::cout << "Invalid command! Pass two integers - batch_size and epochs (in that order)." << "\n"; + exit(1); + } std::cout << bench(strtol(argv[1], NULL, 10), strtol(argv[2], NULL, 10)) << "\n"; } diff --git a/src/bpnn.cpp b/src/bpnn.cpp @@ -41,9 +41,31 @@ Layer::Layer(int batch_sz, int nodes, float a) } Layer::Layer(const Layer& that) - :activation(that.activation), activation_deriv(that.activation_deriv), alpha(that.alpha) { - //strcpy(activation_str, that.activation_str); + contents = new Eigen::MatrixXf (that.contents->rows(), that.contents->cols()); + dZ = new Eigen::MatrixXf (that.dZ->rows(), that.dZ->cols()); + bias = new Eigen::MatrixXf (that.bias->rows(), that.bias->cols()); + v = new Eigen::MatrixXf (that.v->rows(), that.v->cols()); + m = new Eigen::MatrixXf (that.m->rows(), that.m->cols()); + weights = new Eigen::MatrixXf (that.weights->rows(), that.weights->cols()); + activation = that.activation; + activation_deriv = that.activation_deriv; + alpha = that.alpha; + strcpy(activation_str, that.activation_str); + *contents = *that.contents; + *v = *that.v; + *m = *that.m; + *weights = *that.weights; + *bias = *that.bias; + *dZ = *that.dZ; +} + +void Layer::operator=(const Layer& that) +{ + activation = that.activation; + activation_deriv = that.activation_deriv; + alpha = that.alpha; + strcpy(activation_str, that.activation_str); *contents = *that.contents; *v = *that.v; *m = *that.m; diff --git a/src/bpnn.hpp b/src/bpnn.hpp @@ -32,6 +32,7 @@ public: Layer(int rows, int columns, float a=0); Layer(float* vals, int rows, int columns); Layer(const Layer& that); + void operator=(const Layer& that); void init_weights(Layer next); };