diff --git a/adaboost/core/data_structures.hpp b/adaboost/core/data_structures.hpp index a7c67be..4e33051 100644 --- a/adaboost/core/data_structures.hpp +++ b/adaboost/core/data_structures.hpp @@ -184,43 +184,6 @@ namespace adaboost ~Matrix(); }; - /* @overload - * Used for taking dot product of two vectors. - * - * @param vec1 First vector in dot product. - * @param vec2 Second vector in dot product. - * @param result For storing the result. - */ - template - void product(const Vector& vec1, - const Vector& vec2, - data_type_vector& result); - - /* @overload - * Used for multiplying a vector - * and a matrix. - * - * @param vec The vector. - * @param mat The matrix. - * @param result A vector for storing the result. - */ - template - void multiply(const Vector& vec, - const Matrix& mat, - Vector& result); - - /* @overload - * Used for multiplyng two matrices. - * - * @param vec1 First matrix. - * @param vec2 Second matrix. - * @param result A matrix for storing the result. - */ - template - void multiply(const Matrix& mat1, - const Matrix& mat2, - Matrix& result); - } // namespace core } // namespace adaboost diff --git a/adaboost/core/data_structures_impl.cpp b/adaboost/core/data_structures_impl.cpp index 37bf6f5..7055850 100644 --- a/adaboost/core/data_structures_impl.cpp +++ b/adaboost/core/data_structures_impl.cpp @@ -51,16 +51,6 @@ namespace adaboost this->data[index] = value; } - template - void Vector:: - fill(data_type_vector value) - { - for(unsigned int i = 0; i < this->size; i++) - { - this->data[i] = value; - } - } - template unsigned int Vector::get_size() const { @@ -133,19 +123,6 @@ namespace adaboost this->data[x*this->cols + y] = value; } - template - void Matrix:: - fill(data_type_matrix value) - { - for(unsigned int i = 0; i < this->rows; i++) - { - for(unsigned int j = 0; j < this->cols; j++) - { - this->data[i*this->cols + j] = value; - } - } - } - template unsigned int Matrix:: get_rows() const @@ -176,60 +153,6 @@ namespace adaboost } } - template - void product(const Vector& vec1, - const Vector& vec2, - data_type_vector& result) - { - adaboost::utils::check(vec1.get_size() == vec2.get_size(), - "Size of vectors don't match."); - result = 0; - for(unsigned int i = 0; i < vec1.get_size(); i++) - { - result += (vec1.at(i)*vec2.at(i)); - } - } - - template - void multiply(const Vector& vec, - const Matrix& mat, - Vector& result) - { - adaboost::utils::check(vec.get_size() == mat.get_rows(), - "Orders mismatch in the inputs."); - for(unsigned int j = 0; j < mat.get_cols(); j++) - { - data_type_vector _result = 0; - for(unsigned int i = 0; i < mat.get_rows(); i++) - { - _result += (vec.at(i)*mat.at(i, j)); - } - result.set(j, _result); - } - } - - template - void multiply(const Matrix& mat1, - const Matrix& mat2, - Matrix& result) - { - adaboost::utils::check(mat1.get_cols() == mat2.get_rows(), - "Order of matrices don't match."); - unsigned int common_cols = mat1.get_cols(); - for(unsigned int i = 0; i < result.get_rows(); i++) - { - for(unsigned int j = 0; j < result.get_cols(); j++) - { - data_type_matrix _result = 0; - for(unsigned int k = 0; k < common_cols; k++) - { - _result += (mat1.at(i, k)*mat2.at(k, j)); - } - result.set(i, j, _result); - } - } - } - #include "instantiated_templates_data_structures.hpp" } // namespace core diff --git a/adaboost/core/operations.hpp b/adaboost/core/operations.hpp index 0438f71..0440abd 100644 --- a/adaboost/core/operations.hpp +++ b/adaboost/core/operations.hpp @@ -53,6 +53,44 @@ namespace adaboost const Vector& vec, data_type_1& result); + /* + * @overload + * Used for taking dot product of two vectors. + * + * @param vec1 First vector in dot product. + * @param vec2 Second vector in dot product. + * @param result For storing the result. + */ + template + void product(const Vector& vec1, + const Vector& vec2, + data_type_vector& result); + + /* @overload + * Used for multiplyng two matrices. + * + * @param vec1 First matrix. + * @param vec2 Second matrix. + * @param result A matrix for storing the result. + */ + template + void multiply(const Matrix& mat1, + const Matrix& mat2, + Matrix& result); + + /* @overload + * Used for multiplying a vector + * and a matrix. + * + * @param vec The vector. + * @param mat The matrix. + * @param result A vector for storing the result. + */ + template + void multiply(const Vector& vec, + const Matrix& mat, + Vector& result); + } // namespace core } // namespace adaboost diff --git a/adaboost/core/operations_impl.cpp b/adaboost/core/operations_impl.cpp index be93813..27db15f 100644 --- a/adaboost/core/operations_impl.cpp +++ b/adaboost/core/operations_impl.cpp @@ -47,6 +47,86 @@ namespace adaboost result = arg_max; } + template + void Vector:: + fill(data_type_vector value) + { + for(unsigned int i = 0; i < this->size; i++) + { + this->data[i] = value; + } + } + + + template + void Matrix:: + fill(data_type_matrix value) + { + for(unsigned int i = 0; i < this->rows; i++) + { + for(unsigned int j = 0; j < this->cols; j++) + { + this->data[i*this->cols + j] = value; + } + } + } + + + template + void multiply(const Vector& vec, + const Matrix& mat, + Vector& result) + { + adaboost::utils::check(vec.get_size() == mat.get_rows(), + "Orders mismatch in the inputs."); + for(unsigned int j = 0; j < mat.get_cols(); j++) + { + data_type_vector _result = 0; + for(unsigned int i = 0; i < mat.get_rows(); i++) + { + _result += (vec.at(i)*mat.at(i, j)); + } + result.set(j, _result); + } + } + + template + void multiply(const Matrix& mat1, + const Matrix& mat2, + Matrix& result) + { + adaboost::utils::check(mat1.get_cols() == mat2.get_rows(), + "Order of matrices don't match."); + unsigned int common_cols = mat1.get_cols(); + for(unsigned int i = 0; i < result.get_rows(); i++) + { + for(unsigned int j = 0; j < result.get_cols(); j++) + { + data_type_matrix _result = 0; + for(unsigned int k = 0; k < common_cols; k++) + { + _result += (mat1.at(i, k)*mat2.at(k, j)); + } + result.set(i, j, _result); + } + } + } + + template + void product(const Vector& vec1, + const Vector& vec2, + data_type_vector& result) + { + adaboost::utils::check(vec1.get_size() == vec2.get_size(), + "Size of vectors don't match."); + result = 0; + for(unsigned int i = 0; i < vec1.get_size(); i++) + { + result += (vec1.at(i)*vec2.at(i)); + } + } + + #include "instantiated_templates_operations.hpp" } // namespace core