Include sfw if it's an sfw build.

This commit is contained in:
Relintai 2024-01-25 13:42:45 +01:00
parent 5218d2296a
commit 3f9c7a2db3
72 changed files with 2872 additions and 2359 deletions

View File

@ -267,6 +267,10 @@ Help(opts.GenerateHelpText(env_base))
# add default include paths # add default include paths
env_base.Prepend(CPPPATH=["#"]) env_base.Prepend(CPPPATH=["#"])
env_base.Prepend(CPPPATH=["#platform"])
# USE SFWL
env_base.Prepend(CPPDEFINES=["USING_SFW"])
# configure ENV for platform # configure ENV for platform
env_base.platform_exporters = platform_exporters env_base.platform_exporters = platform_exporters

View File

@ -31,8 +31,6 @@
#include "activation.h" #include "activation.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#include "core/math/math_defs.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>

View File

@ -31,11 +31,17 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/func_ref.h" #include "core/object/func_ref.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -35,7 +35,12 @@
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#include "../regularization/reg.h" #include "../regularization/reg.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include <random> #include <random>

View File

@ -31,10 +31,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_tensor3.h" #include "../lin_alg/mlpp_tensor3.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -34,7 +34,11 @@
#include "../cost/cost.h" #include "../cost/cost.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include <random> #include <random>

View File

@ -31,9 +31,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,11 +31,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/hash_map.h" #include "core/containers/hash_map.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,10 +31,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../regularization/reg.h" #include "../regularization/reg.h"
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"

View File

@ -31,7 +31,12 @@
#include "convolutions.h" #include "convolutions.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#include "../stat/stat.h" #include "../stat/stat.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#endif
#include <cmath> #include <cmath>

View File

@ -31,16 +31,22 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_tensor3.h" #include "../lin_alg/mlpp_tensor3.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"
#include "core/object/reference.h"
class MLPPConvolutions : public Reference { class MLPPConvolutions : public Reference {
GDCLASS(MLPPConvolutions, Reference); GDCLASS(MLPPConvolutions, Reference);

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include <vector> #include <vector>

View File

@ -30,7 +30,11 @@
#include "data.h" #include "data.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/os/file_access.h" #include "core/os/file_access.h"
#endif
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#include "../stat/stat.h" #include "../stat/stat.h"

View File

@ -31,12 +31,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -35,9 +35,13 @@
// http://ciml.info/dl/v0_99/ciml-v0_99-ch11.pdf // http://ciml.info/dl/v0_99/ciml-v0_99-ch11.pdf
// Were excellent for the practical intution behind the dual formulation. // Were excellent for the practical intution behind the dual formulation.
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../regularization/reg.h" #include "../regularization/reg.h"

View File

@ -34,7 +34,11 @@
#include "../regularization/reg.h" #include "../regularization/reg.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../hidden_layer/hidden_layer.h" #include "../hidden_layer/hidden_layer.h"
#include "../output_layer/output_layer.h" #include "../output_layer/output_layer.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -30,7 +30,11 @@
#include "gaussian_nb.h" #include "gaussian_nb.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#endif
#include "../stat/stat.h" #include "../stat/stat.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,10 +31,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../regularization/reg.h" #include "../regularization/reg.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include <tuple> #include <tuple>
#include <vector> #include <vector>

View File

@ -31,7 +31,11 @@
#include "kmeans.h" #include "kmeans.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/random_pcg.h" #include "core/math/random_pcg.h"
#endif
#include <climits> #include <climits>
#include <iostream> #include <iostream>

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,8 +31,12 @@
#include "knn.h" #include "knn.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/hash_map.h" #include "core/containers/hash_map.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
#endif
Ref<MLPPMatrix> MLPPKNN::get_input_set() { Ref<MLPPMatrix> MLPPKNN::get_input_set() {
return _input_set; return _input_set;

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,7 +30,11 @@
#include "lin_alg.h" #include "lin_alg.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#endif
#include "../stat/stat.h" #include "../stat/stat.h"
#include <cmath> #include <cmath>

View File

@ -33,19 +33,12 @@
//TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds //TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds
#ifndef GDNATIVE #ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#else
#include "core/defs.h"
#include "core/math_funcs.h"
#include "gen/resource.h"
#endif #endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"

View File

@ -30,7 +30,11 @@
#include "mlpp_matrix.h" #include "mlpp_matrix.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/io/image.h" #include "core/io/image.h"
#endif
#include "../stat/stat.h" #include "../stat/stat.h"
#include <random> #include <random>

View File

@ -1,6 +1,5 @@
#ifndef MLPP_MATRIX_H #ifndef MLPP_MATRIX_H
#define MLPP_MATRIX_H #define MLPP_MATRIX_H
#ifndef GDNATIVE
/*************************************************************************/ /*************************************************************************/
/* mlpp_matrix.h */ /* mlpp_matrix.h */
@ -32,6 +31,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/containers/pool_vector.h" #include "core/containers/pool_vector.h"
@ -42,17 +44,6 @@
#include "core/os/memory.h" #include "core/os/memory.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#else
#include "core/containers/vector.h"
#include "core/defs.h"
#include "core/math_funcs.h"
#include "core/os/memory.h"
#include "core/pool_arrays.h"
#include "gen/resource.h"
#endif #endif
#include "mlpp_vector.h" #include "mlpp_vector.h"
@ -66,13 +57,9 @@ public:
Array get_data(); Array get_data();
void set_data(const Array &p_from); void set_data(const Array &p_from);
_FORCE_INLINE_ real_t *ptrw() { _FORCE_INLINE_ real_t *ptrw() { return _data; }
return _data;
}
_FORCE_INLINE_ const real_t *ptr() const { _FORCE_INLINE_ const real_t *ptr() const { return _data; }
return _data;
}
void row_add(const Vector<real_t> &p_row); void row_add(const Vector<real_t> &p_row);
void row_add_pool_vector(const PoolRealArray &p_row); void row_add_pool_vector(const PoolRealArray &p_row);
@ -164,10 +151,12 @@ public:
void set_from_mlpp_vectors_array(const Array &p_from); void set_from_mlpp_vectors_array(const Array &p_from);
void set_from_vectors(const Vector<Vector<real_t>> &p_from); void set_from_vectors(const Vector<Vector<real_t>> &p_from);
void set_from_arrays(const Array &p_from); void set_from_arrays(const Array &p_from);
void set_from_ptr(const real_t *p_from, const int p_size_y, const int p_size_x); void set_from_ptr(const real_t *p_from, const int p_size_y,
const int p_size_x);
//std::vector<std::vector<real_t>> gramMatrix(std::vector<std::vector<real_t>> A); // std::vector<std::vector<real_t>>
//bool linearIndependenceChecker(std::vector<std::vector<real_t>> A); // gramMatrix(std::vector<std::vector<real_t>> A); bool
// linearIndependenceChecker(std::vector<std::vector<real_t>> A);
Ref<MLPPMatrix> gaussian_noise(int n, int m) const; Ref<MLPPMatrix> gaussian_noise(int n, int m) const;
void gaussian_noise_fill(); void gaussian_noise_fill();
@ -196,7 +185,8 @@ public:
void division_element_wise(const Ref<MLPPMatrix> &B); void division_element_wise(const Ref<MLPPMatrix> &B);
Ref<MLPPMatrix> division_element_wisen(const Ref<MLPPMatrix> &B) const; Ref<MLPPMatrix> division_element_wisen(const Ref<MLPPMatrix> &B) const;
void division_element_wiseb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B); void division_element_wiseb(const Ref<MLPPMatrix> &A,
const Ref<MLPPMatrix> &B);
void transpose(); void transpose();
Ref<MLPPMatrix> transposen() const; Ref<MLPPMatrix> transposen() const;
@ -287,12 +277,12 @@ public:
Ref<MLPPMatrix> minn(const Ref<MLPPMatrix> &B) const; Ref<MLPPMatrix> minn(const Ref<MLPPMatrix> &B) const;
void minb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B); void minb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
//real_t max(std::vector<std::vector<real_t>> A); // real_t max(std::vector<std::vector<real_t>> A);
//real_t min(std::vector<std::vector<real_t>> A); // real_t min(std::vector<std::vector<real_t>> A);
//std::vector<std::vector<real_t>> round(std::vector<std::vector<real_t>> A); // std::vector<std::vector<real_t>> round(std::vector<std::vector<real_t>> A);
//real_t norm_2(std::vector<std::vector<real_t>> A); // real_t norm_2(std::vector<std::vector<real_t>> A);
void identity(); void identity();
Ref<MLPPMatrix> identityn() const; Ref<MLPPMatrix> identityn() const;
@ -324,9 +314,11 @@ public:
Array svd_bind(); Array svd_bind();
Array svdb_bind(const Ref<MLPPMatrix> &A); Array svdb_bind(const Ref<MLPPMatrix> &A);
//std::vector<real_t> vectorProjection(std::vector<real_t> a, std::vector<real_t> b); // std::vector<real_t> vectorProjection(std::vector<real_t> a,
// std::vector<real_t> b);
//std::vector<std::vector<real_t>> gramSchmidtProcess(std::vector<std::vector<real_t>> A); // std::vector<std::vector<real_t>>
// gramSchmidtProcess(std::vector<std::vector<real_t>> A);
/* /*
struct QRDResult { struct QRDResult {
@ -335,7 +327,7 @@ public:
}; };
*/ */
//QRDResult qrd(std::vector<std::vector<real_t>> A); // QRDResult qrd(std::vector<std::vector<real_t>> A);
/* /*
struct CholeskyResult { struct CholeskyResult {
@ -346,7 +338,7 @@ public:
CholeskyResult cholesky(std::vector<std::vector<real_t>> A); CholeskyResult cholesky(std::vector<std::vector<real_t>> A);
*/ */
//real_t sum_elements(std::vector<std::vector<real_t>> A); // real_t sum_elements(std::vector<std::vector<real_t>> A);
Ref<MLPPVector> flatten() const; Ref<MLPPVector> flatten() const;
void flatteno(Ref<MLPPVector> out) const; void flatteno(Ref<MLPPVector> out) const;
@ -370,7 +362,8 @@ public:
// This multiplies a, bT // This multiplies a, bT
void outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b); void outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) const; Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a,
const Ref<MLPPVector> &b) const;
// Just sets the diagonal // Just sets the diagonal
void diagonal_set(const Ref<MLPPVector> &a); void diagonal_set(const Ref<MLPPVector> &a);
@ -380,7 +373,9 @@ public:
void diagonal_zeroed(const Ref<MLPPVector> &a); void diagonal_zeroed(const Ref<MLPPVector> &a);
Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a) const; Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a) const;
bool is_equal_approx(const Ref<MLPPMatrix> &p_with, real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const; bool
is_equal_approx(const Ref<MLPPMatrix> &p_with,
real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
Ref<Image> get_as_image() const; Ref<Image> get_as_image() const;
void get_into_image(Ref<Image> out) const; void get_into_image(Ref<Image> out) const;

View File

@ -30,7 +30,11 @@
#include "mlpp_tensor3.h" #include "mlpp_tensor3.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/io/image.h" #include "core/io/image.h"
#endif
Array MLPPTensor3::get_data() { Array MLPPTensor3::get_data() {
PoolRealArray pl; PoolRealArray pl;
@ -264,7 +268,9 @@ void MLPPTensor3::shape_set(const Size3i &p_size) {
int ds = data_size(); int ds = data_size();
int new_data_size = p_size.x * p_size.y * p_size.z; int new_data_size = p_size.x * p_size.y * p_size.z;
ERR_FAIL_COND_MSG(ds != new_data_size, "The new size has a different volume than the old. If this is intended use resize()!"); ERR_FAIL_COND_MSG(ds != new_data_size,
"The new size has a different volume than the old. If this "
"is intended use resize()!");
_size = p_size; _size = p_size;
} }
@ -292,7 +298,8 @@ Vector<real_t> MLPPTensor3::row_get_vector(int p_index_z, int p_index_y) const {
return ret; return ret;
} }
PoolRealArray MLPPTensor3::row_get_pool_vector(int p_index_z, int p_index_y) const { PoolRealArray MLPPTensor3::row_get_pool_vector(int p_index_z,
int p_index_y) const {
ERR_FAIL_INDEX_V(p_index_y, _size.y, PoolRealArray()); ERR_FAIL_INDEX_V(p_index_y, _size.y, PoolRealArray());
ERR_FAIL_INDEX_V(p_index_z, _size.z, PoolRealArray()); ERR_FAIL_INDEX_V(p_index_z, _size.z, PoolRealArray());
@ -316,7 +323,8 @@ PoolRealArray MLPPTensor3::row_get_pool_vector(int p_index_z, int p_index_y) con
return ret; return ret;
} }
Ref<MLPPVector> MLPPTensor3::row_get_mlpp_vector(int p_index_z, int p_index_y) const { Ref<MLPPVector> MLPPTensor3::row_get_mlpp_vector(int p_index_z,
int p_index_y) const {
ERR_FAIL_INDEX_V(p_index_y, _size.y, Ref<MLPPVector>()); ERR_FAIL_INDEX_V(p_index_y, _size.y, Ref<MLPPVector>());
ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<MLPPVector>()); ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<MLPPVector>());
@ -340,7 +348,8 @@ Ref<MLPPVector> MLPPTensor3::row_get_mlpp_vector(int p_index_z, int p_index_y) c
return ret; return ret;
} }
void MLPPTensor3::row_get_into_mlpp_vector(int p_index_z, int p_index_y, Ref<MLPPVector> target) const { void MLPPTensor3::row_get_into_mlpp_vector(int p_index_z, int p_index_y,
Ref<MLPPVector> target) const {
ERR_FAIL_COND(!target.is_valid()); ERR_FAIL_COND(!target.is_valid());
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
@ -358,7 +367,8 @@ void MLPPTensor3::row_get_into_mlpp_vector(int p_index_z, int p_index_y, Ref<MLP
} }
} }
void MLPPTensor3::row_set_vector(int p_index_z, int p_index_y, const Vector<real_t> &p_row) { void MLPPTensor3::row_set_vector(int p_index_z, int p_index_y,
const Vector<real_t> &p_row) {
ERR_FAIL_COND(p_row.size() != _size.x); ERR_FAIL_COND(p_row.size() != _size.x);
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
@ -372,7 +382,8 @@ void MLPPTensor3::row_set_vector(int p_index_z, int p_index_y, const Vector<real
} }
} }
void MLPPTensor3::row_set_pool_vector(int p_index_z, int p_index_y, const PoolRealArray &p_row) { void MLPPTensor3::row_set_pool_vector(int p_index_z, int p_index_y,
const PoolRealArray &p_row) {
ERR_FAIL_COND(p_row.size() != _size.x); ERR_FAIL_COND(p_row.size() != _size.x);
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
@ -387,7 +398,8 @@ void MLPPTensor3::row_set_pool_vector(int p_index_z, int p_index_y, const PoolRe
} }
} }
void MLPPTensor3::row_set_mlpp_vector(int p_index_z, int p_index_y, const Ref<MLPPVector> &p_row) { void MLPPTensor3::row_set_mlpp_vector(int p_index_z, int p_index_y,
const Ref<MLPPVector> &p_row) {
ERR_FAIL_COND(!p_row.is_valid()); ERR_FAIL_COND(!p_row.is_valid());
ERR_FAIL_COND(p_row->size() != _size.x); ERR_FAIL_COND(p_row->size() != _size.x);
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
@ -476,7 +488,8 @@ Ref<MLPPVector> MLPPTensor3::z_slice_get_mlpp_vector(int p_index_z) const {
return ret; return ret;
} }
void MLPPTensor3::z_slice_get_into_mlpp_vector(int p_index_z, Ref<MLPPVector> target) const { void MLPPTensor3::z_slice_get_into_mlpp_vector(int p_index_z,
Ref<MLPPVector> target) const {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
int fmds = z_slice_data_size(); int fmds = z_slice_data_size();
@ -519,7 +532,8 @@ Ref<MLPPMatrix> MLPPTensor3::z_slice_get_mlpp_matrix(int p_index_z) const {
return ret; return ret;
} }
void MLPPTensor3::z_slice_get_into_mlpp_matrix(int p_index_z, Ref<MLPPMatrix> target) const { void MLPPTensor3::z_slice_get_into_mlpp_matrix(int p_index_z,
Ref<MLPPMatrix> target) const {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
int fmds = z_slice_data_size(); int fmds = z_slice_data_size();
@ -538,7 +552,8 @@ void MLPPTensor3::z_slice_get_into_mlpp_matrix(int p_index_z, Ref<MLPPMatrix> ta
} }
} }
void MLPPTensor3::z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row) { void MLPPTensor3::z_slice_set_vector(int p_index_z,
const Vector<real_t> &p_row) {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
int fmds = z_slice_data_size(); int fmds = z_slice_data_size();
@ -554,7 +569,8 @@ void MLPPTensor3::z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row)
} }
} }
void MLPPTensor3::z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_row) { void MLPPTensor3::z_slice_set_pool_vector(int p_index_z,
const PoolRealArray &p_row) {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
int fmds = z_slice_data_size(); int fmds = z_slice_data_size();
@ -571,7 +587,8 @@ void MLPPTensor3::z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_
} }
} }
void MLPPTensor3::z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &p_row) { void MLPPTensor3::z_slice_set_mlpp_vector(int p_index_z,
const Ref<MLPPVector> &p_row) {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
ERR_FAIL_COND(!p_row.is_valid()); ERR_FAIL_COND(!p_row.is_valid());
@ -588,7 +605,8 @@ void MLPPTensor3::z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &
} }
} }
void MLPPTensor3::z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &p_mat) { void MLPPTensor3::z_slice_set_mlpp_matrix(int p_index_z,
const Ref<MLPPMatrix> &p_mat) {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
ERR_FAIL_COND(!p_mat.is_valid()); ERR_FAIL_COND(!p_mat.is_valid());
@ -605,7 +623,8 @@ void MLPPTensor3::z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &
} }
} }
void MLPPTensor3::x_slice_get_into(int p_index_x, Ref<MLPPMatrix> target) const { void MLPPTensor3::x_slice_get_into(int p_index_x,
Ref<MLPPMatrix> target) const {
ERR_FAIL_INDEX(p_index_x, _size.x); ERR_FAIL_INDEX(p_index_x, _size.x);
ERR_FAIL_COND(!target.is_valid()); ERR_FAIL_COND(!target.is_valid());
@ -641,7 +660,8 @@ void MLPPTensor3::x_slice_set(int p_index_x, const Ref<MLPPMatrix> &p_mat) {
} }
} }
void MLPPTensor3::y_slice_get_into(int p_index_y, Ref<MLPPMatrix> target) const { void MLPPTensor3::y_slice_get_into(int p_index_y,
Ref<MLPPMatrix> target) const {
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_COND(!target.is_valid()); ERR_FAIL_COND(!target.is_valid());
@ -677,7 +697,8 @@ void MLPPTensor3::y_slice_set(int p_index_y, const Ref<MLPPMatrix> &p_mat) {
} }
} }
void MLPPTensor3::z_slices_add_image(const Ref<Image> &p_img, const int p_channels) { void MLPPTensor3::z_slices_add_image(const Ref<Image> &p_img,
const int p_channels) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
Size2i img_size = Size2i(p_img->get_width(), p_img->get_height()); Size2i img_size = Size2i(p_img->get_width(), p_img->get_height());
@ -766,7 +787,10 @@ Ref<Image> MLPPTensor3::z_slice_get_image(const int p_index_z) const {
return image; return image;
} }
Ref<Image> MLPPTensor3::z_slices_get_image(const int p_index_r, const int p_index_g, const int p_index_b, const int p_index_a) const { Ref<Image> MLPPTensor3::z_slices_get_image(const int p_index_r,
const int p_index_g,
const int p_index_b,
const int p_index_a) const {
if (p_index_r != -1) { if (p_index_r != -1) {
ERR_FAIL_INDEX_V(p_index_r, _size.z, Ref<Image>()); ERR_FAIL_INDEX_V(p_index_r, _size.z, Ref<Image>());
} }
@ -825,7 +849,9 @@ Ref<Image> MLPPTensor3::z_slices_get_image(const int p_index_r, const int p_inde
return image; return image;
} }
void MLPPTensor3::z_slice_get_into_image(Ref<Image> p_target, const int p_index_z, const int p_target_channels) const { void MLPPTensor3::z_slice_get_into_image(Ref<Image> p_target,
const int p_index_z,
const int p_target_channels) const {
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
ERR_FAIL_COND(!p_target.is_valid()); ERR_FAIL_COND(!p_target.is_valid());
@ -892,7 +918,11 @@ void MLPPTensor3::z_slice_get_into_image(Ref<Image> p_target, const int p_index_
p_target->unlock(); p_target->unlock();
} }
void MLPPTensor3::z_slices_get_into_image(Ref<Image> p_target, const int p_index_r, const int p_index_g, const int p_index_b, const int p_index_a) const { void MLPPTensor3::z_slices_get_into_image(Ref<Image> p_target,
const int p_index_r,
const int p_index_g,
const int p_index_b,
const int p_index_a) const {
ERR_FAIL_COND(!p_target.is_valid()); ERR_FAIL_COND(!p_target.is_valid());
if (p_index_r != -1) { if (p_index_r != -1) {
@ -960,7 +990,9 @@ void MLPPTensor3::z_slices_get_into_image(Ref<Image> p_target, const int p_index
p_target->unlock(); p_target->unlock();
} }
void MLPPTensor3::z_slice_set_image(const Ref<Image> &p_img, const int p_index_z, const int p_image_channel_flag) { void MLPPTensor3::z_slice_set_image(const Ref<Image> &p_img,
const int p_index_z,
const int p_image_channel_flag) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
@ -994,7 +1026,9 @@ void MLPPTensor3::z_slice_set_image(const Ref<Image> &p_img, const int p_index_z
img->unlock(); img->unlock();
} }
void MLPPTensor3::z_slices_set_image(const Ref<Image> &p_img, const int p_index_r, const int p_index_g, const int p_index_b, const int p_index_a) { void MLPPTensor3::z_slices_set_image(const Ref<Image> &p_img,
const int p_index_r, const int p_index_g,
const int p_index_b, const int p_index_a) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
if (p_index_r != -1) { if (p_index_r != -1) {
@ -1047,7 +1081,8 @@ void MLPPTensor3::z_slices_set_image(const Ref<Image> &p_img, const int p_index_
img->unlock(); img->unlock();
} }
void MLPPTensor3::set_from_image(const Ref<Image> &p_img, const int p_channels) { void MLPPTensor3::set_from_image(const Ref<Image> &p_img,
const int p_channels) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
int channel_count = 0; int channel_count = 0;
@ -1127,7 +1162,9 @@ Ref<Image> MLPPTensor3::x_slice_get_image(const int p_index_x) const {
return image; return image;
} }
void MLPPTensor3::x_slice_get_into_image(Ref<Image> p_target, const int p_index_x, const int p_target_channels) const { void MLPPTensor3::x_slice_get_into_image(Ref<Image> p_target,
const int p_index_x,
const int p_target_channels) const {
ERR_FAIL_INDEX(p_index_x, _size.x); ERR_FAIL_INDEX(p_index_x, _size.x);
ERR_FAIL_COND(!p_target.is_valid()); ERR_FAIL_COND(!p_target.is_valid());
@ -1194,7 +1231,9 @@ void MLPPTensor3::x_slice_get_into_image(Ref<Image> p_target, const int p_index_
p_target->unlock(); p_target->unlock();
} }
void MLPPTensor3::x_slice_set_image(const Ref<Image> &p_img, const int p_index_x, const int p_image_channel_flag) { void MLPPTensor3::x_slice_set_image(const Ref<Image> &p_img,
const int p_index_x,
const int p_image_channel_flag) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
ERR_FAIL_INDEX(p_index_x, _size.x); ERR_FAIL_INDEX(p_index_x, _size.x);
@ -1258,7 +1297,9 @@ Ref<Image> MLPPTensor3::y_slice_get_image(const int p_index_y) const {
return image; return image;
} }
void MLPPTensor3::y_slice_get_into_image(Ref<Image> p_target, const int p_index_y, const int p_target_channels) const { void MLPPTensor3::y_slice_get_into_image(Ref<Image> p_target,
const int p_index_y,
const int p_target_channels) const {
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_COND(!p_target.is_valid()); ERR_FAIL_COND(!p_target.is_valid());
@ -1325,7 +1366,9 @@ void MLPPTensor3::y_slice_get_into_image(Ref<Image> p_target, const int p_index_
p_target->unlock(); p_target->unlock();
} }
void MLPPTensor3::y_slice_set_image(const Ref<Image> &p_img, const int p_index_y, const int p_image_channel_flag) { void MLPPTensor3::y_slice_set_image(const Ref<Image> &p_img,
const int p_index_y,
const int p_image_channel_flag) {
ERR_FAIL_COND(!p_img.is_valid()); ERR_FAIL_COND(!p_img.is_valid());
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
@ -1479,7 +1522,8 @@ void MLPPTensor3::division_element_wise(const Ref<MLPPTensor3> &B) {
c_ptr[i] /= b_ptr[i]; c_ptr[i] /= b_ptr[i];
} }
} }
Ref<MLPPTensor3> MLPPTensor3::division_element_wisen(const Ref<MLPPTensor3> &B) const { Ref<MLPPTensor3>
MLPPTensor3::division_element_wisen(const Ref<MLPPTensor3> &B) const {
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>()); ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>());
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>()); ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>());
@ -1499,7 +1543,8 @@ Ref<MLPPTensor3> MLPPTensor3::division_element_wisen(const Ref<MLPPTensor3> &B)
return C; return C;
} }
void MLPPTensor3::division_element_wiseb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B) { void MLPPTensor3::division_element_wiseb(const Ref<MLPPTensor3> &A,
const Ref<MLPPTensor3> &B) {
ERR_FAIL_COND(!A.is_valid() || !B.is_valid()); ERR_FAIL_COND(!A.is_valid() || !B.is_valid());
Size3i a_size = A->size(); Size3i a_size = A->size();
ERR_FAIL_COND(a_size != B->size()); ERR_FAIL_COND(a_size != B->size());
@ -1625,7 +1670,8 @@ Ref<MLPPTensor3> MLPPTensor3::scalar_multiplyn(const real_t scalar) const {
return AN; return AN;
} }
void MLPPTensor3::scalar_multiplyb(const real_t scalar, const Ref<MLPPTensor3> &A) { void MLPPTensor3::scalar_multiplyb(const real_t scalar,
const Ref<MLPPTensor3> &A) {
ERR_FAIL_COND(!A.is_valid()); ERR_FAIL_COND(!A.is_valid());
if (A->size() != _size) { if (A->size() != _size) {
@ -1686,7 +1732,8 @@ void MLPPTensor3::hadamard_product(const Ref<MLPPTensor3> &B) {
c_ptr[i] = c_ptr[i] * b_ptr[i]; c_ptr[i] = c_ptr[i] * b_ptr[i];
} }
} }
Ref<MLPPTensor3> MLPPTensor3::hadamard_productn(const Ref<MLPPTensor3> &B) const { Ref<MLPPTensor3>
MLPPTensor3::hadamard_productn(const Ref<MLPPTensor3> &B) const {
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>()); ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>());
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>()); ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>());
@ -1706,7 +1753,8 @@ Ref<MLPPTensor3> MLPPTensor3::hadamard_productn(const Ref<MLPPTensor3> &B) const
return C; return C;
} }
void MLPPTensor3::hadamard_productb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B) { void MLPPTensor3::hadamard_productb(const Ref<MLPPTensor3> &A,
const Ref<MLPPTensor3> &B) {
ERR_FAIL_COND(!A.is_valid() || !B.is_valid()); ERR_FAIL_COND(!A.is_valid() || !B.is_valid());
Size3i a_size = A->size(); Size3i a_size = A->size();
ERR_FAIL_COND(a_size != B->size()); ERR_FAIL_COND(a_size != B->size());
@ -1892,7 +1940,9 @@ Ref<MLPPMatrix> MLPPTensor3::tensor_vec_mult(const Ref<MLPPVector> &b) {
/* /*
// Bad implementation. Change this later. // Bad implementation. Change this later.
std::vector<std::vector<std::vector<real_t>>> MLPPTensor3::vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>> A, std::vector<std::vector<real_t>> B) { std::vector<std::vector<std::vector<real_t>>>
MLPPTensor3::vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>>
A, std::vector<std::vector<real_t>> B) {
std::vector<std::vector<std::vector<real_t>>> C; std::vector<std::vector<std::vector<real_t>>> C;
C = resize(C, A); C = resize(C, A);
for (uint32_t i = 0; i < A[0].size(); i++) { for (uint32_t i = 0; i < A[0].size(); i++) {
@ -2048,7 +2098,8 @@ void MLPPTensor3::set_from_mlpp_vectors(const Vector<Ref<MLPPVector>> &p_from) {
} }
} }
void MLPPTensor3::set_from_mlpp_matricess(const Vector<Ref<MLPPMatrix>> &p_from) { void MLPPTensor3::set_from_mlpp_matricess(
const Vector<Ref<MLPPMatrix>> &p_from) {
if (p_from.size() == 0) { if (p_from.size() == 0) {
reset(); reset();
return; return;
@ -2157,7 +2208,8 @@ void MLPPTensor3::set_from_mlpp_matrices_array(const Array &p_from) {
} }
} }
bool MLPPTensor3::is_equal_approx(const Ref<MLPPTensor3> &p_with, real_t tolerance) const { bool MLPPTensor3::is_equal_approx(const Ref<MLPPTensor3> &p_with,
real_t tolerance) const {
ERR_FAIL_COND_V(!p_with.is_valid(), false); ERR_FAIL_COND_V(!p_with.is_valid(), false);
if (unlikely(this == p_with.ptr())) { if (unlikely(this == p_with.ptr())) {
@ -2208,9 +2260,7 @@ String MLPPTensor3::to_string() {
return str; return str;
} }
MLPPTensor3::MLPPTensor3() { MLPPTensor3::MLPPTensor3() { _data = NULL; }
_data = NULL;
}
MLPPTensor3::MLPPTensor3(const MLPPMatrix &p_from) { MLPPTensor3::MLPPTensor3(const MLPPMatrix &p_from) {
_data = NULL; _data = NULL;
@ -2246,7 +2296,8 @@ std::vector<real_t> MLPPTensor3::to_flat_std_vector() const {
return ret; return ret;
} }
void MLPPTensor3::set_from_std_vectors(const std::vector<std::vector<std::vector<real_t>>> &p_from) { void MLPPTensor3::set_from_std_vectors(
const std::vector<std::vector<std::vector<real_t>>> &p_from) {
if (p_from.size() == 0) { if (p_from.size() == 0) {
reset(); reset();
return; return;
@ -2298,7 +2349,8 @@ std::vector<std::vector<std::vector<real_t>>> MLPPTensor3::to_std_vector() {
return ret; return ret;
} }
MLPPTensor3::MLPPTensor3(const std::vector<std::vector<std::vector<real_t>>> &p_from) { MLPPTensor3::MLPPTensor3(
const std::vector<std::vector<std::vector<real_t>>> &p_from) {
_data = NULL; _data = NULL;
set_from_std_vectors(p_from); set_from_std_vectors(p_from);
@ -2309,20 +2361,27 @@ void MLPPTensor3::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_data", "data"), &MLPPTensor3::set_data); ClassDB::bind_method(D_METHOD("set_data", "data"), &MLPPTensor3::set_data);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data"), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data"), "set_data", "get_data");
ClassDB::bind_method(D_METHOD("z_slice_add_pool_vector", "row"), &MLPPTensor3::z_slice_add_pool_vector); ClassDB::bind_method(D_METHOD("z_slice_add_pool_vector", "row"),
ClassDB::bind_method(D_METHOD("z_slice_add_mlpp_vector", "row"), &MLPPTensor3::z_slice_add_mlpp_vector); &MLPPTensor3::z_slice_add_pool_vector);
ClassDB::bind_method(D_METHOD("z_slice_add_mlpp_matrix", "matrix"), &MLPPTensor3::z_slice_add_mlpp_matrix); ClassDB::bind_method(D_METHOD("z_slice_add_mlpp_vector", "row"),
&MLPPTensor3::z_slice_add_mlpp_vector);
ClassDB::bind_method(D_METHOD("z_slice_add_mlpp_matrix", "matrix"),
&MLPPTensor3::z_slice_add_mlpp_matrix);
ClassDB::bind_method(D_METHOD("z_slice_remove", "index"), &MLPPTensor3::z_slice_remove); ClassDB::bind_method(D_METHOD("z_slice_remove", "index"),
ClassDB::bind_method(D_METHOD("z_slice_remove_unordered", "index"), &MLPPTensor3::z_slice_remove_unordered); &MLPPTensor3::z_slice_remove);
ClassDB::bind_method(D_METHOD("z_slice_remove_unordered", "index"),
&MLPPTensor3::z_slice_remove_unordered);
ClassDB::bind_method(D_METHOD("z_slice_swap", "index_1", "index_2"), &MLPPTensor3::z_slice_swap); ClassDB::bind_method(D_METHOD("z_slice_swap", "index_1", "index_2"),
&MLPPTensor3::z_slice_swap);
ClassDB::bind_method(D_METHOD("clear"), &MLPPTensor3::clear); ClassDB::bind_method(D_METHOD("clear"), &MLPPTensor3::clear);
ClassDB::bind_method(D_METHOD("reset"), &MLPPTensor3::reset); ClassDB::bind_method(D_METHOD("reset"), &MLPPTensor3::reset);
ClassDB::bind_method(D_METHOD("empty"), &MLPPTensor3::empty); ClassDB::bind_method(D_METHOD("empty"), &MLPPTensor3::empty);
ClassDB::bind_method(D_METHOD("z_slice_data_size"), &MLPPTensor3::z_slice_data_size); ClassDB::bind_method(D_METHOD("z_slice_data_size"),
&MLPPTensor3::z_slice_data_size);
ClassDB::bind_method(D_METHOD("z_slice_size"), &MLPPTensor3::z_slice_size); ClassDB::bind_method(D_METHOD("z_slice_size"), &MLPPTensor3::z_slice_size);
ClassDB::bind_method(D_METHOD("data_size"), &MLPPTensor3::data_size); ClassDB::bind_method(D_METHOD("data_size"), &MLPPTensor3::data_size);
@ -2331,75 +2390,142 @@ void MLPPTensor3::_bind_methods() {
ClassDB::bind_method(D_METHOD("resize", "size"), &MLPPTensor3::resize); ClassDB::bind_method(D_METHOD("resize", "size"), &MLPPTensor3::resize);
ClassDB::bind_method(D_METHOD("shape_set", "size"), &MLPPTensor3::shape_set); ClassDB::bind_method(D_METHOD("shape_set", "size"), &MLPPTensor3::shape_set);
ClassDB::bind_method(D_METHOD("calculate_index", "index_y", "index_x", "index_z"), &MLPPTensor3::calculate_index); ClassDB::bind_method(
ClassDB::bind_method(D_METHOD("calculate_z_slice_index", "index_z"), &MLPPTensor3::calculate_z_slice_index); D_METHOD("calculate_index", "index_y", "index_x", "index_z"),
&MLPPTensor3::calculate_index);
ClassDB::bind_method(D_METHOD("calculate_z_slice_index", "index_z"),
&MLPPTensor3::calculate_z_slice_index);
ClassDB::bind_method(D_METHOD("element_get_index", "index"), &MLPPTensor3::element_get_index); ClassDB::bind_method(D_METHOD("element_get_index", "index"),
ClassDB::bind_method(D_METHOD("element_set_index", "index", "val"), &MLPPTensor3::element_set_index); &MLPPTensor3::element_get_index);
ClassDB::bind_method(D_METHOD("element_set_index", "index", "val"),
&MLPPTensor3::element_set_index);
ClassDB::bind_method(D_METHOD("element_get", "index_y", "index_x", "index_z"), &MLPPTensor3::element_get); ClassDB::bind_method(D_METHOD("element_get", "index_y", "index_x", "index_z"),
ClassDB::bind_method(D_METHOD("element_set", "index_y", "index_x", "index_z", "val"), &MLPPTensor3::element_set); &MLPPTensor3::element_get);
ClassDB::bind_method(
D_METHOD("element_set", "index_y", "index_x", "index_z", "val"),
&MLPPTensor3::element_set);
ClassDB::bind_method(D_METHOD("row_get_pool_vector", "index_y", "index_z"), &MLPPTensor3::row_get_pool_vector); ClassDB::bind_method(D_METHOD("row_get_pool_vector", "index_y", "index_z"),
ClassDB::bind_method(D_METHOD("row_get_mlpp_vector", "index_y", "index_z"), &MLPPTensor3::row_get_mlpp_vector); &MLPPTensor3::row_get_pool_vector);
ClassDB::bind_method(D_METHOD("row_get_into_mlpp_vector", "index_y", "index_z", "target"), &MLPPTensor3::row_get_into_mlpp_vector); ClassDB::bind_method(D_METHOD("row_get_mlpp_vector", "index_y", "index_z"),
&MLPPTensor3::row_get_mlpp_vector);
ClassDB::bind_method(
D_METHOD("row_get_into_mlpp_vector", "index_y", "index_z", "target"),
&MLPPTensor3::row_get_into_mlpp_vector);
ClassDB::bind_method(D_METHOD("row_set_pool_vector", "index_y", "index_z", "row"), &MLPPTensor3::row_set_pool_vector); ClassDB::bind_method(
ClassDB::bind_method(D_METHOD("row_set_mlpp_vector", "index_y", "index_z", "row"), &MLPPTensor3::row_set_mlpp_vector); D_METHOD("row_set_pool_vector", "index_y", "index_z", "row"),
&MLPPTensor3::row_set_pool_vector);
ClassDB::bind_method(
D_METHOD("row_set_mlpp_vector", "index_y", "index_z", "row"),
&MLPPTensor3::row_set_mlpp_vector);
ClassDB::bind_method(D_METHOD("z_slice_get_pool_vector", "index_z"), &MLPPTensor3::z_slice_get_pool_vector); ClassDB::bind_method(D_METHOD("z_slice_get_pool_vector", "index_z"),
ClassDB::bind_method(D_METHOD("z_slice_get_mlpp_vector", "index_z"), &MLPPTensor3::z_slice_get_mlpp_vector); &MLPPTensor3::z_slice_get_pool_vector);
ClassDB::bind_method(D_METHOD("z_slice_get_into_mlpp_vector", "index_z", "target"), &MLPPTensor3::z_slice_get_into_mlpp_vector); ClassDB::bind_method(D_METHOD("z_slice_get_mlpp_vector", "index_z"),
&MLPPTensor3::z_slice_get_mlpp_vector);
ClassDB::bind_method(
D_METHOD("z_slice_get_into_mlpp_vector", "index_z", "target"),
&MLPPTensor3::z_slice_get_into_mlpp_vector);
ClassDB::bind_method(D_METHOD("z_slice_get_mlpp_matrix", "index_z"), &MLPPTensor3::z_slice_get_mlpp_matrix); ClassDB::bind_method(D_METHOD("z_slice_get_mlpp_matrix", "index_z"),
ClassDB::bind_method(D_METHOD("z_slice_get_into_mlpp_matrix", "index_z", "target"), &MLPPTensor3::z_slice_get_into_mlpp_matrix); &MLPPTensor3::z_slice_get_mlpp_matrix);
ClassDB::bind_method(
D_METHOD("z_slice_get_into_mlpp_matrix", "index_z", "target"),
&MLPPTensor3::z_slice_get_into_mlpp_matrix);
ClassDB::bind_method(D_METHOD("z_slice_set_pool_vector", "index_z", "row"), &MLPPTensor3::z_slice_set_pool_vector); ClassDB::bind_method(D_METHOD("z_slice_set_pool_vector", "index_z", "row"),
ClassDB::bind_method(D_METHOD("z_slice_set_mlpp_vector", "index_z", "row"), &MLPPTensor3::z_slice_set_mlpp_vector); &MLPPTensor3::z_slice_set_pool_vector);
ClassDB::bind_method(D_METHOD("z_slice_set_mlpp_matrix", "index_z", "mat"), &MLPPTensor3::z_slice_set_mlpp_matrix); ClassDB::bind_method(D_METHOD("z_slice_set_mlpp_vector", "index_z", "row"),
&MLPPTensor3::z_slice_set_mlpp_vector);
ClassDB::bind_method(D_METHOD("z_slice_set_mlpp_matrix", "index_z", "mat"),
&MLPPTensor3::z_slice_set_mlpp_matrix);
ClassDB::bind_method(D_METHOD("x_slice_get_into", "index_x", "target"), &MLPPTensor3::x_slice_get_into); ClassDB::bind_method(D_METHOD("x_slice_get_into", "index_x", "target"),
ClassDB::bind_method(D_METHOD("x_slice_get", "index_x"), &MLPPTensor3::x_slice_get); &MLPPTensor3::x_slice_get_into);
ClassDB::bind_method(D_METHOD("x_slice_set", "index_x", "mat"), &MLPPTensor3::x_slice_set); ClassDB::bind_method(D_METHOD("x_slice_get", "index_x"),
&MLPPTensor3::x_slice_get);
ClassDB::bind_method(D_METHOD("x_slice_set", "index_x", "mat"),
&MLPPTensor3::x_slice_set);
ClassDB::bind_method(D_METHOD("y_slice_get_into", "index_y", "target"), &MLPPTensor3::y_slice_get_into); ClassDB::bind_method(D_METHOD("y_slice_get_into", "index_y", "target"),
ClassDB::bind_method(D_METHOD("y_slice_get", "index_y"), &MLPPTensor3::y_slice_get); &MLPPTensor3::y_slice_get_into);
ClassDB::bind_method(D_METHOD("y_slice_set", "index_y", "mat"), &MLPPTensor3::y_slice_set); ClassDB::bind_method(D_METHOD("y_slice_get", "index_y"),
&MLPPTensor3::y_slice_get);
ClassDB::bind_method(D_METHOD("y_slice_set", "index_y", "mat"),
&MLPPTensor3::y_slice_set);
ClassDB::bind_method(D_METHOD("z_slices_add_image", "img", "channels"), &MLPPTensor3::z_slices_add_image, IMAGE_CHANNEL_FLAG_RGBA); ClassDB::bind_method(D_METHOD("z_slices_add_image", "img", "channels"),
&MLPPTensor3::z_slices_add_image,
IMAGE_CHANNEL_FLAG_RGBA);
ClassDB::bind_method(D_METHOD("z_slice_get_image", "index_z"), &MLPPTensor3::z_slice_get_image); ClassDB::bind_method(D_METHOD("z_slice_get_image", "index_z"),
ClassDB::bind_method(D_METHOD("z_slices_get_image", "index_r", "index_g", "index_b", "index_a"), &MLPPTensor3::z_slices_get_image, -1, -1, -1, -1); &MLPPTensor3::z_slice_get_image);
ClassDB::bind_method(D_METHOD("z_slices_get_image", "index_r", "index_g",
"index_b", "index_a"),
&MLPPTensor3::z_slices_get_image, -1, -1, -1, -1);
ClassDB::bind_method(D_METHOD("z_slice_get_into_image", "target", "index_z", "target_channels"), &MLPPTensor3::z_slice_get_into_image, IMAGE_CHANNEL_FLAG_RGB); ClassDB::bind_method(D_METHOD("z_slice_get_into_image", "target", "index_z",
ClassDB::bind_method(D_METHOD("z_slices_get_into_image", "target", "index_r", "index_g", "index_b", "index_a"), &MLPPTensor3::z_slices_get_into_image, -1, -1, -1, -1); "target_channels"),
&MLPPTensor3::z_slice_get_into_image,
IMAGE_CHANNEL_FLAG_RGB);
ClassDB::bind_method(D_METHOD("z_slices_get_into_image", "target", "index_r",
"index_g", "index_b", "index_a"),
&MLPPTensor3::z_slices_get_into_image, -1, -1, -1, -1);
ClassDB::bind_method(D_METHOD("z_slice_set_image", "img", "index_z", "image_channel_flag"), &MLPPTensor3::z_slice_set_image, IMAGE_CHANNEL_FLAG_R); ClassDB::bind_method(
ClassDB::bind_method(D_METHOD("z_slices_set_image", "img", "index_r", "index_g", "index_b", "index_a"), &MLPPTensor3::z_slices_set_image); D_METHOD("z_slice_set_image", "img", "index_z", "image_channel_flag"),
&MLPPTensor3::z_slice_set_image, IMAGE_CHANNEL_FLAG_R);
ClassDB::bind_method(D_METHOD("z_slices_set_image", "img", "index_r",
"index_g", "index_b", "index_a"),
&MLPPTensor3::z_slices_set_image);
ClassDB::bind_method(D_METHOD("set_from_image", "img", "channels"), &MLPPTensor3::set_from_image, IMAGE_CHANNEL_FLAG_RGBA); ClassDB::bind_method(D_METHOD("set_from_image", "img", "channels"),
&MLPPTensor3::set_from_image, IMAGE_CHANNEL_FLAG_RGBA);
ClassDB::bind_method(D_METHOD("x_slice_get_image", "index_x"), &MLPPTensor3::x_slice_get_image); ClassDB::bind_method(D_METHOD("x_slice_get_image", "index_x"),
ClassDB::bind_method(D_METHOD("x_slice_get_into_image", "target", "index_x", "target_channels"), &MLPPTensor3::x_slice_get_into_image, IMAGE_CHANNEL_FLAG_RGB); &MLPPTensor3::x_slice_get_image);
ClassDB::bind_method(D_METHOD("x_slice_set_image", "img", "index_x", "image_channel_flag"), &MLPPTensor3::x_slice_set_image, IMAGE_CHANNEL_FLAG_R); ClassDB::bind_method(D_METHOD("x_slice_get_into_image", "target", "index_x",
"target_channels"),
&MLPPTensor3::x_slice_get_into_image,
IMAGE_CHANNEL_FLAG_RGB);
ClassDB::bind_method(
D_METHOD("x_slice_set_image", "img", "index_x", "image_channel_flag"),
&MLPPTensor3::x_slice_set_image, IMAGE_CHANNEL_FLAG_R);
ClassDB::bind_method(D_METHOD("y_slice_get_image", "index_x"), &MLPPTensor3::y_slice_get_image); ClassDB::bind_method(D_METHOD("y_slice_get_image", "index_x"),
ClassDB::bind_method(D_METHOD("y_slice_get_into_image", "target", "index_x", "target_channels"), &MLPPTensor3::y_slice_get_into_image, IMAGE_CHANNEL_FLAG_RGB); &MLPPTensor3::y_slice_get_image);
ClassDB::bind_method(D_METHOD("y_slice_set_image", "img", "index_x", "image_channel_flag"), &MLPPTensor3::y_slice_set_image, IMAGE_CHANNEL_FLAG_R); ClassDB::bind_method(D_METHOD("y_slice_get_into_image", "target", "index_x",
"target_channels"),
&MLPPTensor3::y_slice_get_into_image,
IMAGE_CHANNEL_FLAG_RGB);
ClassDB::bind_method(
D_METHOD("y_slice_set_image", "img", "index_x", "image_channel_flag"),
&MLPPTensor3::y_slice_set_image, IMAGE_CHANNEL_FLAG_R);
ClassDB::bind_method(D_METHOD("fill", "val"), &MLPPTensor3::fill); ClassDB::bind_method(D_METHOD("fill", "val"), &MLPPTensor3::fill);
ClassDB::bind_method(D_METHOD("to_flat_pool_vector"), &MLPPTensor3::to_flat_pool_vector); ClassDB::bind_method(D_METHOD("to_flat_pool_vector"),
ClassDB::bind_method(D_METHOD("to_flat_byte_array"), &MLPPTensor3::to_flat_byte_array); &MLPPTensor3::to_flat_pool_vector);
ClassDB::bind_method(D_METHOD("to_flat_byte_array"),
&MLPPTensor3::to_flat_byte_array);
ClassDB::bind_method(D_METHOD("duplicate_fast"), &MLPPTensor3::duplicate_fast); ClassDB::bind_method(D_METHOD("duplicate_fast"),
&MLPPTensor3::duplicate_fast);
ClassDB::bind_method(D_METHOD("set_from_mlpp_tensor3", "from"), &MLPPTensor3::set_from_mlpp_tensor3); ClassDB::bind_method(D_METHOD("set_from_mlpp_tensor3", "from"),
ClassDB::bind_method(D_METHOD("set_from_mlpp_matrix", "from"), &MLPPTensor3::set_from_mlpp_matrix); &MLPPTensor3::set_from_mlpp_tensor3);
ClassDB::bind_method(D_METHOD("set_from_mlpp_vectors_array", "from"), &MLPPTensor3::set_from_mlpp_vectors_array); ClassDB::bind_method(D_METHOD("set_from_mlpp_matrix", "from"),
ClassDB::bind_method(D_METHOD("set_from_mlpp_matrices_array", "from"), &MLPPTensor3::set_from_mlpp_matrices_array); &MLPPTensor3::set_from_mlpp_matrix);
ClassDB::bind_method(D_METHOD("set_from_mlpp_vectors_array", "from"),
&MLPPTensor3::set_from_mlpp_vectors_array);
ClassDB::bind_method(D_METHOD("set_from_mlpp_matrices_array", "from"),
&MLPPTensor3::set_from_mlpp_matrices_array);
ClassDB::bind_method(D_METHOD("is_equal_approx", "with", "tolerance"), &MLPPTensor3::is_equal_approx, CMP_EPSILON); ClassDB::bind_method(D_METHOD("is_equal_approx", "with", "tolerance"),
&MLPPTensor3::is_equal_approx, CMP_EPSILON);
ClassDB::bind_method(D_METHOD("add", "B"), &MLPPTensor3::add); ClassDB::bind_method(D_METHOD("add", "B"), &MLPPTensor3::add);
ClassDB::bind_method(D_METHOD("addn", "B"), &MLPPTensor3::addn); ClassDB::bind_method(D_METHOD("addn", "B"), &MLPPTensor3::addn);
@ -2409,25 +2535,40 @@ void MLPPTensor3::_bind_methods() {
ClassDB::bind_method(D_METHOD("subn", "B"), &MLPPTensor3::subn); ClassDB::bind_method(D_METHOD("subn", "B"), &MLPPTensor3::subn);
ClassDB::bind_method(D_METHOD("subb", "A", "B"), &MLPPTensor3::subb); ClassDB::bind_method(D_METHOD("subb", "A", "B"), &MLPPTensor3::subb);
ClassDB::bind_method(D_METHOD("hadamard_product", "B"), &MLPPTensor3::hadamard_product); ClassDB::bind_method(D_METHOD("hadamard_product", "B"),
ClassDB::bind_method(D_METHOD("hadamard_productn", "B"), &MLPPTensor3::hadamard_productn); &MLPPTensor3::hadamard_product);
ClassDB::bind_method(D_METHOD("hadamard_productb", "A", "B"), &MLPPTensor3::hadamard_productb); ClassDB::bind_method(D_METHOD("hadamard_productn", "B"),
&MLPPTensor3::hadamard_productn);
ClassDB::bind_method(D_METHOD("hadamard_productb", "A", "B"),
&MLPPTensor3::hadamard_productb);
ClassDB::bind_method(D_METHOD("division_element_wise", "B"), &MLPPTensor3::division_element_wise); ClassDB::bind_method(D_METHOD("division_element_wise", "B"),
ClassDB::bind_method(D_METHOD("division_element_wisen", "B"), &MLPPTensor3::division_element_wisen); &MLPPTensor3::division_element_wise);
ClassDB::bind_method(D_METHOD("division_element_wiseb", "A", "B"), &MLPPTensor3::division_element_wiseb); ClassDB::bind_method(D_METHOD("division_element_wisen", "B"),
&MLPPTensor3::division_element_wisen);
ClassDB::bind_method(D_METHOD("division_element_wiseb", "A", "B"),
&MLPPTensor3::division_element_wiseb);
ClassDB::bind_method(D_METHOD("scalar_multiply", "scalar"), &MLPPTensor3::scalar_multiply); ClassDB::bind_method(D_METHOD("scalar_multiply", "scalar"),
ClassDB::bind_method(D_METHOD("scalar_multiplyn", "scalar"), &MLPPTensor3::scalar_multiplyn); &MLPPTensor3::scalar_multiply);
ClassDB::bind_method(D_METHOD("scalar_multiplyb", "scalar", "A"), &MLPPTensor3::scalar_multiplyb); ClassDB::bind_method(D_METHOD("scalar_multiplyn", "scalar"),
&MLPPTensor3::scalar_multiplyn);
ClassDB::bind_method(D_METHOD("scalar_multiplyb", "scalar", "A"),
&MLPPTensor3::scalar_multiplyb);
ClassDB::bind_method(D_METHOD("scalar_add", "scalar"), &MLPPTensor3::scalar_add); ClassDB::bind_method(D_METHOD("scalar_add", "scalar"),
ClassDB::bind_method(D_METHOD("scalar_addn", "scalar"), &MLPPTensor3::scalar_addn); &MLPPTensor3::scalar_add);
ClassDB::bind_method(D_METHOD("scalar_addb", "scalar", "A"), &MLPPTensor3::scalar_addb); ClassDB::bind_method(D_METHOD("scalar_addn", "scalar"),
&MLPPTensor3::scalar_addn);
ClassDB::bind_method(D_METHOD("scalar_addb", "scalar", "A"),
&MLPPTensor3::scalar_addb);
ClassDB::bind_method(D_METHOD("exponentiate", "p"), &MLPPTensor3::exponentiate); ClassDB::bind_method(D_METHOD("exponentiate", "p"),
ClassDB::bind_method(D_METHOD("exponentiaten", "p"), &MLPPTensor3::exponentiaten); &MLPPTensor3::exponentiate);
ClassDB::bind_method(D_METHOD("exponentiateb", "A", "p"), &MLPPTensor3::exponentiateb); ClassDB::bind_method(D_METHOD("exponentiaten", "p"),
&MLPPTensor3::exponentiaten);
ClassDB::bind_method(D_METHOD("exponentiateb", "A", "p"),
&MLPPTensor3::exponentiateb);
ClassDB::bind_method(D_METHOD("sqrt"), &MLPPTensor3::sqrt); ClassDB::bind_method(D_METHOD("sqrt"), &MLPPTensor3::sqrt);
ClassDB::bind_method(D_METHOD("sqrtn"), &MLPPTensor3::sqrtn); ClassDB::bind_method(D_METHOD("sqrtn"), &MLPPTensor3::sqrtn);

View File

@ -1,6 +1,5 @@
#ifndef MLPP_TENSOR3_H #ifndef MLPP_TENSOR3_H
#define MLPP_TENSOR3_H #define MLPP_TENSOR3_H
#ifndef GDNATIVE
/*************************************************************************/ /*************************************************************************/
/* mlpp_tensor3.h */ /* mlpp_tensor3.h */
@ -32,6 +31,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/containers/pool_vector.h" #include "core/containers/pool_vector.h"
@ -42,17 +45,6 @@
#include "core/os/memory.h" #include "core/os/memory.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#else
#include "core/containers/vector.h"
#include "core/defs.h"
#include "core/math_funcs.h"
#include "core/os/memory.h"
#include "core/pool_arrays.h"
#include "gen/resource.h"
#endif #endif
#include "mlpp_matrix.h" #include "mlpp_matrix.h"
@ -67,13 +59,9 @@ public:
Array get_data(); Array get_data();
void set_data(const Array &p_from); void set_data(const Array &p_from);
_FORCE_INLINE_ real_t *ptrw() { _FORCE_INLINE_ real_t *ptrw() { return _data; }
return _data;
}
_FORCE_INLINE_ const real_t *ptr() const { _FORCE_INLINE_ const real_t *ptr() const { return _data; }
return _data;
}
void z_slice_add(const Vector<real_t> &p_row); void z_slice_add(const Vector<real_t> &p_row);
void z_slice_add_pool_vector(const PoolRealArray &p_row); void z_slice_add_pool_vector(const PoolRealArray &p_row);
@ -98,14 +86,17 @@ public:
_FORCE_INLINE_ bool empty() const { return _size == Size3i(); } _FORCE_INLINE_ bool empty() const { return _size == Size3i(); }
_FORCE_INLINE_ int z_slice_data_size() const { return _size.x * _size.y; } _FORCE_INLINE_ int z_slice_data_size() const { return _size.x * _size.y; }
_FORCE_INLINE_ Size2i z_slice_size() const { return Size2i(_size.x, _size.y); } _FORCE_INLINE_ Size2i z_slice_size() const {
return Size2i(_size.x, _size.y);
}
_FORCE_INLINE_ int data_size() const { return _size.x * _size.y * _size.z; } _FORCE_INLINE_ int data_size() const { return _size.x * _size.y * _size.z; }
_FORCE_INLINE_ Size3i size() const { return _size; } _FORCE_INLINE_ Size3i size() const { return _size; }
void resize(const Size3i &p_size); void resize(const Size3i &p_size);
void shape_set(const Size3i &p_size); void shape_set(const Size3i &p_size);
_FORCE_INLINE_ int calculate_index(int p_index_z, int p_index_y, int p_index_x) const { _FORCE_INLINE_ int calculate_index(int p_index_z, int p_index_y,
int p_index_x) const {
return p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z; return p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z;
} }
@ -134,58 +125,68 @@ public:
_data[p_index] = p_val; _data[p_index] = p_val;
} }
_FORCE_INLINE_ real_t element_get(int p_index_z, int p_index_y, int p_index_x) const { _FORCE_INLINE_ real_t element_get(int p_index_z, int p_index_y,
int p_index_x) const {
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0); ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0); ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);
ERR_FAIL_INDEX_V(p_index_z, _size.z, 0); ERR_FAIL_INDEX_V(p_index_z, _size.z, 0);
return _data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z]; return _data[p_index_y * _size.x + p_index_x +
_size.x * _size.y * p_index_z];
} }
_FORCE_INLINE_ void element_set(int p_index_z, int p_index_y, int p_index_x, real_t p_val) { _FORCE_INLINE_ void element_set(int p_index_z, int p_index_y, int p_index_x,
real_t p_val) {
ERR_FAIL_INDEX(p_index_x, _size.x); ERR_FAIL_INDEX(p_index_x, _size.x);
ERR_FAIL_INDEX(p_index_y, _size.y); ERR_FAIL_INDEX(p_index_y, _size.y);
ERR_FAIL_INDEX(p_index_z, _size.z); ERR_FAIL_INDEX(p_index_z, _size.z);
_data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z] = p_val; _data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z] =
p_val;
} }
Vector<real_t> row_get_vector(int p_index_z, int p_index_y) const; Vector<real_t> row_get_vector(int p_index_z, int p_index_y) const;
PoolRealArray row_get_pool_vector(int p_index_z, int p_index_y) const; PoolRealArray row_get_pool_vector(int p_index_z, int p_index_y) const;
Ref<MLPPVector> row_get_mlpp_vector(int p_index_z, int p_index_y) const; Ref<MLPPVector> row_get_mlpp_vector(int p_index_z, int p_index_y) const;
void row_get_into_mlpp_vector(int p_index_z, int p_index_y, Ref<MLPPVector> target) const; void row_get_into_mlpp_vector(int p_index_z, int p_index_y,
Ref<MLPPVector> target) const;
void row_set_vector(int p_index_z, int p_index_y, const Vector<real_t> &p_row); void row_set_vector(int p_index_z, int p_index_y,
void row_set_pool_vector(int p_index_z, int p_index_y, const PoolRealArray &p_row); const Vector<real_t> &p_row);
void row_set_mlpp_vector(int p_index_z, int p_index_y, const Ref<MLPPVector> &p_row); void row_set_pool_vector(int p_index_z, int p_index_y,
const PoolRealArray &p_row);
void row_set_mlpp_vector(int p_index_z, int p_index_y,
const Ref<MLPPVector> &p_row);
Vector<real_t> z_slice_get_vector(int p_index_z) const; Vector<real_t> z_slice_get_vector(int p_index_z) const;
PoolRealArray z_slice_get_pool_vector(int p_index_z) const; PoolRealArray z_slice_get_pool_vector(int p_index_z) const;
Ref<MLPPVector> z_slice_get_mlpp_vector(int p_index_z) const; Ref<MLPPVector> z_slice_get_mlpp_vector(int p_index_z) const;
void z_slice_get_into_mlpp_vector(int p_index_z, Ref<MLPPVector> target) const; void z_slice_get_into_mlpp_vector(int p_index_z,
Ref<MLPPVector> target) const;
Ref<MLPPMatrix> z_slice_get_mlpp_matrix(int p_index_z) const; Ref<MLPPMatrix> z_slice_get_mlpp_matrix(int p_index_z) const;
void z_slice_get_into_mlpp_matrix(int p_index_z, Ref<MLPPMatrix> target) const; void z_slice_get_into_mlpp_matrix(int p_index_z,
Ref<MLPPMatrix> target) const;
void z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row); void z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row);
void z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_row); void z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_row);
void z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &p_row); void z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &p_row);
void z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &p_mat); void z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &p_mat);
//TODO resize() need to be reworked for add and remove to work, in any other direction than z // TODO resize() need to be reworked for add and remove to work, in any other
//void x_slice_add(const Ref<MLPPMatrix> &p_matrix); // direction than z void x_slice_add(const Ref<MLPPMatrix> &p_matrix); void
//void x_slice_remove(int p_index); // x_slice_remove(int p_index);
void x_slice_get_into(int p_index_x, Ref<MLPPMatrix> target) const; void x_slice_get_into(int p_index_x, Ref<MLPPMatrix> target) const;
Ref<MLPPMatrix> x_slice_get(int p_index_x) const; Ref<MLPPMatrix> x_slice_get(int p_index_x) const;
void x_slice_set(int p_index_x, const Ref<MLPPMatrix> &p_mat); void x_slice_set(int p_index_x, const Ref<MLPPMatrix> &p_mat);
//void y_slice_add(const Ref<MLPPMatrix> &p_matrix); // void y_slice_add(const Ref<MLPPMatrix> &p_matrix);
//void y_slice_remove(int p_index); // void y_slice_remove(int p_index);
void y_slice_get_into(int p_index_y, Ref<MLPPMatrix> target) const; void y_slice_get_into(int p_index_y, Ref<MLPPMatrix> target) const;
Ref<MLPPMatrix> y_slice_get(int p_index_y) const; Ref<MLPPMatrix> y_slice_get(int p_index_y) const;
void y_slice_set(int p_index_y, const Ref<MLPPMatrix> &p_mat); void y_slice_set(int p_index_y, const Ref<MLPPMatrix> &p_mat);
public: public:
//Image api // Image api
enum ImageChannelFlags { enum ImageChannelFlags {
IMAGE_CHANNEL_FLAG_R = 1 << 0, IMAGE_CHANNEL_FLAG_R = 1 << 0,
@ -195,38 +196,62 @@ public:
IMAGE_CHANNEL_FLAG_NONE = 0, IMAGE_CHANNEL_FLAG_NONE = 0,
IMAGE_CHANNEL_FLAG_RG = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G, IMAGE_CHANNEL_FLAG_RG = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G,
IMAGE_CHANNEL_FLAG_RGB = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B, IMAGE_CHANNEL_FLAG_RGB =
IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
IMAGE_CHANNEL_FLAG_GB = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B, IMAGE_CHANNEL_FLAG_GB = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
IMAGE_CHANNEL_FLAG_GBA = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A, IMAGE_CHANNEL_FLAG_GBA =
IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
IMAGE_CHANNEL_FLAG_BA = IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A, IMAGE_CHANNEL_FLAG_BA = IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
IMAGE_CHANNEL_FLAG_RGBA = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A, IMAGE_CHANNEL_FLAG_RGBA = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G |
IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
}; };
void z_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA); void z_slices_add_image(const Ref<Image> &p_img,
const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
Ref<Image> z_slice_get_image(const int p_index_z) const; Ref<Image> z_slice_get_image(const int p_index_z) const;
Ref<Image> z_slices_get_image(const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const; Ref<Image> z_slices_get_image(const int p_index_r = -1,
const int p_index_g = -1,
const int p_index_b = -1,
const int p_index_a = -1) const;
void z_slice_get_into_image(Ref<Image> p_target, const int p_index_z, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const; void z_slice_get_into_image(
void z_slices_get_into_image(Ref<Image> p_target, const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const; Ref<Image> p_target, const int p_index_z,
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
void z_slices_get_into_image(Ref<Image> p_target, const int p_index_r = -1,
const int p_index_g = -1,
const int p_index_b = -1,
const int p_index_a = -1) const;
void z_slice_set_image(const Ref<Image> &p_img, const int p_index_z, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R); void z_slice_set_image(const Ref<Image> &p_img, const int p_index_z,
void z_slices_set_image(const Ref<Image> &p_img, const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1); const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
void z_slices_set_image(const Ref<Image> &p_img, const int p_index_r = -1,
const int p_index_g = -1, const int p_index_b = -1,
const int p_index_a = -1);
void set_from_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA); void set_from_image(const Ref<Image> &p_img,
const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
//void x_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA); // void x_slices_add_image(const Ref<Image> &p_img, const int p_channels =
// IMAGE_CHANNEL_FLAG_RGBA);
Ref<Image> x_slice_get_image(const int p_index_x) const; Ref<Image> x_slice_get_image(const int p_index_x) const;
void x_slice_get_into_image(Ref<Image> p_target, const int p_index_x, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const; void x_slice_get_into_image(
void x_slice_set_image(const Ref<Image> &p_img, const int p_index_x, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R); Ref<Image> p_target, const int p_index_x,
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
void x_slice_set_image(const Ref<Image> &p_img, const int p_index_x,
const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
//void y_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA); // void y_slices_add_image(const Ref<Image> &p_img, const int p_channels =
// IMAGE_CHANNEL_FLAG_RGBA);
Ref<Image> y_slice_get_image(const int p_index_y) const; Ref<Image> y_slice_get_image(const int p_index_y) const;
void y_slice_get_into_image(Ref<Image> p_target, const int p_index_y, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const; void y_slice_get_into_image(
void y_slice_set_image(const Ref<Image> &p_img, const int p_index_y, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R); Ref<Image> p_target, const int p_index_y,
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
void y_slice_set_image(const Ref<Image> &p_img, const int p_index_y,
const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
public: public:
//math api // math api
void add(const Ref<MLPPTensor3> &B); void add(const Ref<MLPPTensor3> &B);
Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B) const; Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B) const;
@ -238,7 +263,8 @@ public:
void division_element_wise(const Ref<MLPPTensor3> &B); void division_element_wise(const Ref<MLPPTensor3> &B);
Ref<MLPPTensor3> division_element_wisen(const Ref<MLPPTensor3> &B) const; Ref<MLPPTensor3> division_element_wisen(const Ref<MLPPTensor3> &B) const;
void division_element_wiseb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B); void division_element_wiseb(const Ref<MLPPTensor3> &A,
const Ref<MLPPTensor3> &B);
void sqrt(); void sqrt();
Ref<MLPPTensor3> sqrtn() const; Ref<MLPPTensor3> sqrtn() const;
@ -271,10 +297,12 @@ public:
Ref<MLPPVector> flatten() const; Ref<MLPPVector> flatten() const;
void flatteno(Ref<MLPPVector> out) const; void flatteno(Ref<MLPPVector> out) const;
//real_t norm_2(std::vector<std::vector<std::vector<real_t>>> A); // real_t norm_2(std::vector<std::vector<std::vector<real_t>>> A);
Ref<MLPPMatrix> tensor_vec_mult(const Ref<MLPPVector> &b); Ref<MLPPMatrix> tensor_vec_mult(const Ref<MLPPVector> &b);
//std::vector<std::vector<std::vector<real_t>>> vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>> A, std::vector<std::vector<real_t>> B); // std::vector<std::vector<std::vector<real_t>>>
// vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>> A,
// std::vector<std::vector<real_t>> B);
public: public:
void fill(real_t p_val); void fill(real_t p_val);
@ -296,7 +324,9 @@ public:
void set_from_mlpp_vectors_array(const Array &p_from); void set_from_mlpp_vectors_array(const Array &p_from);
void set_from_mlpp_matrices_array(const Array &p_from); void set_from_mlpp_matrices_array(const Array &p_from);
bool is_equal_approx(const Ref<MLPPTensor3> &p_with, real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const; bool
is_equal_approx(const Ref<MLPPTensor3> &p_with,
real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
String to_string(); String to_string();
@ -307,7 +337,8 @@ public:
// TODO: These are temporary // TODO: These are temporary
std::vector<real_t> to_flat_std_vector() const; std::vector<real_t> to_flat_std_vector() const;
void set_from_std_vectors(const std::vector<std::vector<std::vector<real_t>>> &p_from); void set_from_std_vectors(
const std::vector<std::vector<std::vector<real_t>>> &p_from);
std::vector<std::vector<std::vector<real_t>>> to_std_vector(); std::vector<std::vector<std::vector<real_t>>> to_std_vector();
MLPPTensor3(const std::vector<std::vector<std::vector<real_t>>> &p_from); MLPPTensor3(const std::vector<std::vector<std::vector<real_t>>> &p_from);

View File

@ -1,6 +1,5 @@
#ifndef MLPP_VECTOR_H #ifndef MLPP_VECTOR_H
#define MLPP_VECTOR_H #define MLPP_VECTOR_H
#ifndef GDNATIVE
/*************************************************************************/ /*************************************************************************/
/* mlpp_vector.h */ /* mlpp_vector.h */
@ -32,6 +31,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
@ -43,16 +45,6 @@
#include "core/object/resource.h" #include "core/object/resource.h"
#else
#include "core/containers/vector.h"
#include "core/defs.h"
#include "core/math_funcs.h"
#include "core/os/memory.h"
#include "core/pool_arrays.h"
#include "gen/resource.h"
#endif #endif
//REMOVE //REMOVE

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,7 +30,11 @@
#include "mann.h" #include "mann.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../cost/cost.h" #include "../cost/cost.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../regularization/reg.h" #include "../regularization/reg.h"

View File

@ -30,7 +30,11 @@
#include "mlp.h" #include "mlp.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../cost/cost.h" #include "../cost/cost.h"

View File

@ -31,12 +31,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../regularization/reg.h" #include "../regularization/reg.h"

View File

@ -29,6 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#include "multi_output_layer.h" #include "multi_output_layer.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
int MLPPMultiOutputLayer::get_n_output() { int MLPPMultiOutputLayer::get_n_output() {

View File

@ -31,10 +31,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../cost/cost.h" #include "../cost/cost.h"

View File

@ -30,7 +30,11 @@
#include "multinomial_nb.h" #include "multinomial_nb.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/local_vector.h" #include "core/containers/local_vector.h"
#endif
#include "../utilities/utilities.h" #include "../utilities/utilities.h"

View File

@ -31,11 +31,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/hash_map.h" #include "core/containers/hash_map.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -29,6 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#include "numerical_analysis.h" #include "numerical_analysis.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"

View File

@ -36,12 +36,16 @@
// //
// //
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#endif
class MLPPVector; class MLPPVector;
class MLPPMatrix; class MLPPMatrix;

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -29,6 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#include "output_layer.h" #include "output_layer.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
int MLPPOutputLayer::get_n_hidden() { int MLPPOutputLayer::get_n_hidden() {

View File

@ -31,10 +31,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../cost/cost.h" #include "../cost/cost.h"

View File

@ -29,6 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#include "pca.h" #include "pca.h"
#include "../data/data.h" #include "../data/data.h"
Ref<MLPPMatrix> MLPPPCA::get_input_set() { Ref<MLPPMatrix> MLPPPCA::get_input_set() {

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,7 +30,11 @@
#include "reg.h" #include "reg.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -36,7 +36,11 @@
#include "../regularization/reg.h" #include "../regularization/reg.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include <random> #include <random>

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -29,10 +29,16 @@
/*************************************************************************/ /*************************************************************************/
#include "stat.h" #include "stat.h"
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../data/data.h" #include "../data/data.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/hash_map.h" #include "core/containers/hash_map.h"
#endif
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -34,9 +34,13 @@
// https://towardsdatascience.com/svm-implementation-from-scratch-python-2db2fc52e5c2 // https://towardsdatascience.com/svm-implementation-from-scratch-python-2db2fc52e5c2
// Illustratd a practical definition of the Hinge Loss function and its gradient when optimizing with SGD. // Illustratd a practical definition of the Hinge Loss function and its gradient when optimizing with SGD.
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,7 +30,11 @@
#include "mlpp_matrix_tests.h" #include "mlpp_matrix_tests.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"

View File

@ -31,6 +31,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
@ -38,6 +41,7 @@
#include "core/object/reference.h" #include "core/object/reference.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#endif
#include "mlpp_tests.h" #include "mlpp_tests.h"

View File

@ -30,9 +30,13 @@
#include "mlpp_tests.h" #include "mlpp_tests.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#include "core/log/logger.h" #include "core/log/logger.h"
#endif
//TODO remove //TODO remove
#include <cmath> #include <cmath>

View File

@ -31,6 +31,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/containers/vector.h" #include "core/containers/vector.h"
@ -38,6 +41,7 @@
#include "core/object/reference.h" #include "core/object/reference.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#endif
// TODO port this class to use the test module once it's working // TODO port this class to use the test module once it's working
// Also don't forget to remove it's bindings // Also don't forget to remove it's bindings

View File

@ -29,9 +29,14 @@
/*************************************************************************/ /*************************************************************************/
#include "transforms.h" #include "transforms.h"
#include "../lin_alg/lin_alg.h" #include "../lin_alg/lin_alg.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#endif
// DCT ii. // DCT ii.
// https://www.mathworks.com/help/images/discrete-cosine-transform.html // https://www.mathworks.com/help/images/discrete-cosine-transform.html

View File

@ -36,9 +36,13 @@
// //
// //
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"

View File

@ -31,9 +31,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,9 +30,13 @@
#include "utilities.h" #include "utilities.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#include "core/math/random_pcg.h" #include "core/math/random_pcg.h"
#endif
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>

View File

@ -31,12 +31,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_vector.h" #include "../lin_alg/mlpp_vector.h"

View File

@ -30,35 +30,31 @@
#include "wgan.h" #include "wgan.h"
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/log/logger.h" #include "core/log/logger.h"
#include "core/object/method_bind_ext.gen.inc"
#endif
#include "../activation/activation.h" #include "../activation/activation.h"
#include "../cost/cost.h" #include "../cost/cost.h"
#include "../regularization/reg.h" #include "../regularization/reg.h"
#include "../utilities/utilities.h" #include "../utilities/utilities.h"
#include "core/object/method_bind_ext.gen.inc" Ref<MLPPMatrix> MLPPWGAN::get_output_set() { return _output_set; }
void MLPPWGAN::set_output_set(const Ref<MLPPMatrix> &val) { _output_set = val; }
Ref<MLPPMatrix> MLPPWGAN::get_output_set() { int MLPPWGAN::get_k() const { return _k; }
return _output_set; void MLPPWGAN::set_k(const int val) { _k = val; }
}
void MLPPWGAN::set_output_set(const Ref<MLPPMatrix> &val) {
_output_set = val;
}
int MLPPWGAN::get_k() const {
return _k;
}
void MLPPWGAN::set_k(const int val) {
_k = val;
}
Ref<MLPPMatrix> MLPPWGAN::generate_example(int n) { Ref<MLPPMatrix> MLPPWGAN::generate_example(int n) {
return model_set_test_generator(MLPPMatrix::create_gaussian_noise(n, _k)); return model_set_test_generator(MLPPMatrix::create_gaussian_noise(n, _k));
} }
void MLPPWGAN::gradient_descent(real_t learning_rate, int max_epoch, bool ui) { void MLPPWGAN::gradient_descent(real_t learning_rate, int max_epoch, bool ui) {
//MLPPCost mlpp_cost; // MLPPCost mlpp_cost;
real_t cost_prev = 0; real_t cost_prev = 0;
int epoch = 1; int epoch = 1;
int n = _output_set->size().y; int n = _output_set->size().y;
@ -80,35 +76,48 @@ void MLPPWGAN::gradient_descent(real_t learning_rate, int max_epoch, bool ui) {
// Training of the discriminator. // Training of the discriminator.
for (int i = 0; i < CRITIC_INTERATIONS; i++) { for (int i = 0; i < CRITIC_INTERATIONS; i++) {
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k); generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
discriminator_input_set->set_from_mlpp_matrix(model_set_test_generator(generator_input_set)); discriminator_input_set->set_from_mlpp_matrix(
discriminator_input_set->rows_add_mlpp_matrix(_output_set); // Fake + real inputs. model_set_test_generator(generator_input_set));
discriminator_input_set->rows_add_mlpp_matrix(
_output_set); // Fake + real inputs.
ly_hat = model_set_test_discriminator(discriminator_input_set); ly_hat = model_set_test_discriminator(discriminator_input_set);
loutput_set = MLPPVector::create_vec_one(n)->scalar_multiplyn(-1); // WGAN changes y_i = 1 and y_i = 0 to y_i = 1 and y_i = -1 loutput_set = MLPPVector::create_vec_one(n)->scalar_multiplyn(
-1); // WGAN changes y_i = 1 and y_i = 0 to y_i = 1 and y_i = -1
Ref<MLPPVector> output_set_real = MLPPVector::create_vec_one(n); Ref<MLPPVector> output_set_real = MLPPVector::create_vec_one(n);
loutput_set->append_mlpp_vector(output_set_real); // Fake + real output scores. loutput_set->append_mlpp_vector(
output_set_real); // Fake + real output scores.
DiscriminatorGradientResult discriminator_gradient_results = compute_discriminator_gradients(ly_hat, loutput_set); DiscriminatorGradientResult discriminator_gradient_results =
Vector<Ref<MLPPMatrix>> cumulative_discriminator_hidden_layer_w_grad = discriminator_gradient_results.cumulative_hidden_layer_w_grad; compute_discriminator_gradients(ly_hat, loutput_set);
Ref<MLPPVector> output_discriminator_w_grad = discriminator_gradient_results.output_w_grad; Vector<Ref<MLPPMatrix>> cumulative_discriminator_hidden_layer_w_grad =
discriminator_gradient_results.cumulative_hidden_layer_w_grad;
Ref<MLPPVector> output_discriminator_w_grad =
discriminator_gradient_results.output_w_grad;
real_t lrpn = learning_rate / n; real_t lrpn = learning_rate / n;
for (int j = 0; j < cumulative_discriminator_hidden_layer_w_grad.size(); ++j) { for (int j = 0; j < cumulative_discriminator_hidden_layer_w_grad.size();
cumulative_discriminator_hidden_layer_w_grad.write[j]->scalar_multiply(lrpn); ++j) {
cumulative_discriminator_hidden_layer_w_grad.write[j]->scalar_multiply(
lrpn);
} }
output_discriminator_w_grad->scalar_multiply(learning_rate / n); output_discriminator_w_grad->scalar_multiply(learning_rate / n);
update_discriminator_parameters(cumulative_discriminator_hidden_layer_w_grad, output_discriminator_w_grad, learning_rate); update_discriminator_parameters(
cumulative_discriminator_hidden_layer_w_grad,
output_discriminator_w_grad, learning_rate);
} }
// Training of the generator. // Training of the generator.
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k); generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
discriminator_input_set->set_from_mlpp_matrix(model_set_test_generator(generator_input_set)); discriminator_input_set->set_from_mlpp_matrix(
model_set_test_generator(generator_input_set));
ly_hat = model_set_test_discriminator(discriminator_input_set); ly_hat = model_set_test_discriminator(discriminator_input_set);
loutput_set = MLPPVector::create_vec_one(n); loutput_set = MLPPVector::create_vec_one(n);
Vector<Ref<MLPPMatrix>> cumulative_generator_hidden_layer_w_grad = compute_generator_gradients(_y_hat, loutput_set); Vector<Ref<MLPPMatrix>> cumulative_generator_hidden_layer_w_grad =
compute_generator_gradients(_y_hat, loutput_set);
real_t lrpn = learning_rate / n; real_t lrpn = learning_rate / n;
@ -116,7 +125,8 @@ void MLPPWGAN::gradient_descent(real_t learning_rate, int max_epoch, bool ui) {
cumulative_generator_hidden_layer_w_grad.write[i]->scalar_multiply(lrpn); cumulative_generator_hidden_layer_w_grad.write[i]->scalar_multiply(lrpn);
} }
update_generator_parameters(cumulative_generator_hidden_layer_w_grad, learning_rate); update_generator_parameters(cumulative_generator_hidden_layer_w_grad,
learning_rate);
forward_pass(); forward_pass();
@ -144,18 +154,24 @@ void MLPPWGAN::save(const String &file_name) {
/* /*
if (!network.empty()) { if (!network.empty()) {
util.saveParameters(file_name, network[0].weights, network[0].bias, 0, 1); util.saveParameters(file_name, network[0].weights, network[0].bias, 0,
for (uint32_t i = 1; i < network.size(); i++) { 1); for (uint32_t i = 1; i < network.size(); i++) {
util.saveParameters(fileName, network[i].weights, network[i].bias, 1, i + 1); util.saveParameters(fileName, network[i].weights,
network[i].bias, 1, i + 1);
} }
util.saveParameters(file_name, outputLayer->weights, outputLayer->bias, 1, network.size() + 1); util.saveParameters(file_name, outputLayer->weights,
} else { outputLayer->bias, 1, network.size() + 1); } else {
util.saveParameters(file_name, outputLayer->weights, outputLayer->bias, 0, network.size() + 1); util.saveParameters(file_name, outputLayer->weights,
outputLayer->bias, 0, network.size() + 1);
} }
*/ */
} }
void MLPPWGAN::create_layer(int n_hidden, MLPPActivation::ActivationFunction activation, MLPPUtilities::WeightDistributionType weight_init, MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) { void MLPPWGAN::create_layer(int n_hidden,
MLPPActivation::ActivationFunction activation,
MLPPUtilities::WeightDistributionType weight_init,
MLPPReg::RegularizationType reg, real_t lambda,
real_t alpha) {
Ref<MLPPHiddenLayer> layer; Ref<MLPPHiddenLayer> layer;
layer.instance(); layer.instance();
@ -203,11 +219,11 @@ void MLPPWGAN::remove_layer(const int index) {
_network.remove(index); _network.remove(index);
} }
int MLPPWGAN::get_layer_count() const { int MLPPWGAN::get_layer_count() const { return _network.size(); }
return _network.size();
}
void MLPPWGAN::add_output_layer(MLPPUtilities::WeightDistributionType weight_init, MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) { void MLPPWGAN::add_output_layer(
MLPPUtilities::WeightDistributionType weight_init,
MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) {
ERR_FAIL_COND(_network.empty()); ERR_FAIL_COND(_network.empty());
if (!_output_layer.is_valid()) { if (!_output_layer.is_valid()) {
@ -236,8 +252,7 @@ MLPPWGAN::MLPPWGAN() {
_y_hat.instance(); _y_hat.instance();
} }
MLPPWGAN::~MLPPWGAN() { MLPPWGAN::~MLPPWGAN() {}
}
Ref<MLPPMatrix> MLPPWGAN::model_set_test_generator(const Ref<MLPPMatrix> &X) { Ref<MLPPMatrix> MLPPWGAN::model_set_test_generator(const Ref<MLPPMatrix> &X) {
if (!_network.empty()) { if (!_network.empty()) {
@ -253,7 +268,8 @@ Ref<MLPPMatrix> MLPPWGAN::model_set_test_generator(const Ref<MLPPMatrix> &X) {
return _network.write[_network.size() / 2]->get_a(); return _network.write[_network.size() / 2]->get_a();
} }
Ref<MLPPVector> MLPPWGAN::model_set_test_discriminator(const Ref<MLPPMatrix> &X) { Ref<MLPPVector>
MLPPWGAN::model_set_test_discriminator(const Ref<MLPPMatrix> &X) {
if (!_network.empty()) { if (!_network.empty()) {
for (int i = _network.size() / 2 + 1; i < _network.size(); i++) { for (int i = _network.size() / 2 + 1; i < _network.size(); i++) {
if (i == _network.size() / 2 + 1) { if (i == _network.size() / 2 + 1) {
@ -281,12 +297,17 @@ real_t MLPPWGAN::cost(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &y) {
for (int i = 0; i < _network.size() - 1; ++i) { for (int i = 0; i < _network.size() - 1; ++i) {
Ref<MLPPHiddenLayer> layer = _network[i]; Ref<MLPPHiddenLayer> layer = _network[i];
total_reg_term += regularization.reg_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()); total_reg_term +=
regularization.reg_termm(layer->get_weights(), layer->get_lambda(),
layer->get_alpha(), layer->get_reg());
} }
total_reg_term += regularization.reg_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg()); total_reg_term += regularization.reg_termv(
_output_layer->get_weights(), _output_layer->get_lambda(),
_output_layer->get_alpha(), _output_layer->get_reg());
return mlpp_cost.run_cost_norm_vector(_output_layer->get_cost(), y_hat, y) + total_reg_term; return mlpp_cost.run_cost_norm_vector(_output_layer->get_cost(), y_hat, y) +
total_reg_term;
} }
void MLPPWGAN::forward_pass() { void MLPPWGAN::forward_pass() {
@ -315,11 +336,16 @@ void MLPPWGAN::forward_pass() {
_y_hat->set_from_mlpp_vector(_output_layer->get_a()); _y_hat->set_from_mlpp_vector(_output_layer->get_a());
} }
void MLPPWGAN::update_discriminator_parameters(const Vector<Ref<MLPPMatrix>> &hidden_layer_updations, const Ref<MLPPVector> &output_layer_updation, real_t learning_rate) { void MLPPWGAN::update_discriminator_parameters(
const Vector<Ref<MLPPMatrix>> &hidden_layer_updations,
const Ref<MLPPVector> &output_layer_updation, real_t learning_rate) {
int n = _output_set->size().y; int n = _output_set->size().y;
_output_layer->set_weights(_output_layer->get_weights()->subn(output_layer_updation)); _output_layer->set_weights(
_output_layer->set_bias(_output_layer->get_bias() - learning_rate * _output_layer->get_delta()->sum_elements() / n); _output_layer->get_weights()->subn(output_layer_updation));
_output_layer->set_bias(_output_layer->get_bias() -
learning_rate *
_output_layer->get_delta()->sum_elements() / n);
if (!_network.empty()) { if (!_network.empty()) {
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1]; Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
@ -327,7 +353,8 @@ void MLPPWGAN::update_discriminator_parameters(const Vector<Ref<MLPPMatrix>> &hi
Ref<MLPPMatrix> slice = hidden_layer_updations[0]; Ref<MLPPMatrix> slice = hidden_layer_updations[0];
layer->set_weights(layer->get_weights()->subn(slice)); layer->set_weights(layer->get_weights()->subn(slice));
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n))); layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
for (int i = _network.size() - 2; i > _network.size() / 2; i--) { for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
layer = _network[i]; layer = _network[i];
@ -335,12 +362,15 @@ void MLPPWGAN::update_discriminator_parameters(const Vector<Ref<MLPPMatrix>> &hi
slice = hidden_layer_updations[(_network.size() - 2) - i + 1]; slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
layer->set_weights(layer->get_weights()->subn(slice)); layer->set_weights(layer->get_weights()->subn(slice));
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n))); layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
} }
} }
} }
void MLPPWGAN::update_generator_parameters(const Vector<Ref<MLPPMatrix>> &hidden_layer_updations, real_t learning_rate) { void MLPPWGAN::update_generator_parameters(
const Vector<Ref<MLPPMatrix>> &hidden_layer_updations,
real_t learning_rate) {
if (!_network.empty()) { if (!_network.empty()) {
int n = _output_set->size().y; int n = _output_set->size().y;
@ -351,99 +381,158 @@ void MLPPWGAN::update_generator_parameters(const Vector<Ref<MLPPMatrix>> &hidden
slice = hidden_layer_updations[(_network.size() - 2) - i + 1]; slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
//std::cout << network[i].weights.size() << "x" << network[i].weights[0].size() << std::endl; // std::cout << network[i].weights.size() << "x" <<
//std::cout << hiddenLayerUpdations[(network.size() - 2) - i + 1].size() << "x" << hiddenLayerUpdations[(network.size() - 2) - i + 1][0].size() << std::endl; // network[i].weights[0].size() << std::endl; std::cout <<
// hiddenLayerUpdations[(network.size() - 2) - i + 1].size() << "x" <<
// hiddenLayerUpdations[(network.size() - 2) - i + 1][0].size() <<
// std::endl;
layer->set_weights(layer->get_weights()->subn(slice)); layer->set_weights(layer->get_weights()->subn(slice));
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n))); layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
} }
} }
} }
MLPPWGAN::DiscriminatorGradientResult MLPPWGAN::compute_discriminator_gradients(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) { MLPPWGAN::DiscriminatorGradientResult
MLPPWGAN::compute_discriminator_gradients(const Ref<MLPPVector> &y_hat,
const Ref<MLPPVector> &output_set) {
MLPPCost mlpp_cost; MLPPCost mlpp_cost;
MLPPActivation avn; MLPPActivation avn;
MLPPReg regularization; MLPPReg regularization;
DiscriminatorGradientResult data; DiscriminatorGradientResult data;
_output_layer->set_delta(mlpp_cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set)->hadamard_productn(avn.run_activation_deriv_vector(_output_layer->get_activation(), _output_layer->get_z()))); _output_layer->set_delta(
mlpp_cost
.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set)
->hadamard_productn(avn.run_activation_deriv_vector(
_output_layer->get_activation(), _output_layer->get_z())));
data.output_w_grad = _output_layer->get_input()->transposen()->mult_vec(_output_layer->get_delta()); data.output_w_grad = _output_layer->get_input()->transposen()->mult_vec(
data.output_w_grad->add(regularization.reg_deriv_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg())); _output_layer->get_delta());
data.output_w_grad->add(regularization.reg_deriv_termv(
_output_layer->get_weights(), _output_layer->get_lambda(),
_output_layer->get_alpha(), _output_layer->get_reg()));
if (!_network.empty()) { if (!_network.empty()) {
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1]; Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
layer->set_delta(_output_layer->get_delta()->outer_product(_output_layer->get_weights())->hadamard_productn(avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z()))); layer->set_delta(_output_layer->get_delta()
->outer_product(_output_layer->get_weights())
->hadamard_productn(avn.run_activation_deriv_matrix(
layer->get_activation(), layer->get_z())));
Ref<MLPPMatrix> hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta()); Ref<MLPPMatrix> hidden_layer_w_grad =
layer->get_input()->transposen()->multn(layer->get_delta());
data.cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well. data.cumulative_hidden_layer_w_grad.push_back(
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
layer->get_reg()))); // Adding to our cumulative hidden layer grads.
// Maintain reg terms as well.
//std::cout << "HIDDENLAYER FIRST:" << hiddenLayerWGrad.size() << "x" << hiddenLayerWGrad[0].size() << std::endl; // std::cout << "HIDDENLAYER FIRST:" << hiddenLayerWGrad.size() << "x" <<
//std::cout << "WEIGHTS SECOND:" << layer.weights.size() << "x" << layer.weights[0].size() << std::endl; // hiddenLayerWGrad[0].size() << std::endl; std::cout << "WEIGHTS SECOND:"
// << layer.weights.size() << "x" << layer.weights[0].size() << std::endl;
for (int i = _network.size() - 2; i > _network.size() / 2; i--) { for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
layer = _network[i]; layer = _network[i];
Ref<MLPPHiddenLayer> next_layer = _network[i + 1]; Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
layer->set_delta(next_layer->get_delta()->multn(next_layer->get_weights()->transposen())->hadamard_productn(avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z()))); layer->set_delta(next_layer->get_delta()
->multn(next_layer->get_weights()->transposen())
->hadamard_productn(avn.run_activation_deriv_matrix(
layer->get_activation(), layer->get_z())));
hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta()); hidden_layer_w_grad =
data.cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well. layer->get_input()->transposen()->multn(layer->get_delta());
data.cumulative_hidden_layer_w_grad.push_back(
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
layer->get_reg()))); // Adding to our cumulative hidden layer
// grads. Maintain reg terms as well.
} }
} }
return data; return data;
} }
Vector<Ref<MLPPMatrix>> MLPPWGAN::compute_generator_gradients(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) { Vector<Ref<MLPPMatrix>>
MLPPWGAN::compute_generator_gradients(const Ref<MLPPVector> &y_hat,
const Ref<MLPPVector> &output_set) {
class MLPPCost cost; class MLPPCost cost;
MLPPActivation avn; MLPPActivation avn;
MLPPReg regularization; MLPPReg regularization;
Vector<Ref<MLPPMatrix>> cumulative_hidden_layer_w_grad; // Tensor containing ALL hidden grads. Vector<Ref<MLPPMatrix>>
cumulative_hidden_layer_w_grad; // Tensor containing ALL hidden grads.
Ref<MLPPVector> cost_deriv_vector = cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set); Ref<MLPPVector> cost_deriv_vector =
Ref<MLPPVector> activation_deriv_vector = avn.run_activation_deriv_vector(_output_layer->get_activation(), _output_layer->get_z()); cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set);
Ref<MLPPVector> activation_deriv_vector = avn.run_activation_deriv_vector(
_output_layer->get_activation(), _output_layer->get_z());
_output_layer->set_delta(cost_deriv_vector->hadamard_productn(activation_deriv_vector)); _output_layer->set_delta(
cost_deriv_vector->hadamard_productn(activation_deriv_vector));
Ref<MLPPVector> output_w_grad = _output_layer->get_input()->transposen()->mult_vec(_output_layer->get_delta()); Ref<MLPPVector> output_w_grad =
output_w_grad->add(regularization.reg_deriv_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg())); _output_layer->get_input()->transposen()->mult_vec(
_output_layer->get_delta());
output_w_grad->add(regularization.reg_deriv_termv(
_output_layer->get_weights(), _output_layer->get_lambda(),
_output_layer->get_alpha(), _output_layer->get_reg()));
if (!_network.empty()) { if (!_network.empty()) {
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1]; Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
Ref<MLPPMatrix> activation_deriv_matrix = avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z()); Ref<MLPPMatrix> activation_deriv_matrix = avn.run_activation_deriv_matrix(
layer->set_delta(_output_layer->get_delta()->outer_product(_output_layer->get_weights())->hadamard_productn(activation_deriv_matrix)); layer->get_activation(), layer->get_z());
layer->set_delta(_output_layer->get_delta()
->outer_product(_output_layer->get_weights())
->hadamard_productn(activation_deriv_matrix));
Ref<MLPPMatrix> hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta()); Ref<MLPPMatrix> hidden_layer_w_grad =
layer->get_input()->transposen()->multn(layer->get_delta());
cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well. cumulative_hidden_layer_w_grad.push_back(
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
layer->get_reg()))); // Adding to our cumulative hidden layer grads.
// Maintain reg terms as well.
for (int i = _network.size() - 2; i >= 0; i--) { for (int i = _network.size() - 2; i >= 0; i--) {
layer = _network[i]; layer = _network[i];
Ref<MLPPHiddenLayer> next_layer = _network[i + 1]; Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
activation_deriv_matrix = avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z()); activation_deriv_matrix = avn.run_activation_deriv_matrix(
layer->get_activation(), layer->get_z());
layer->set_delta(next_layer->get_delta()->multn(next_layer->get_weights()->transposen())->hadamard_productn(activation_deriv_matrix)); layer->set_delta(next_layer->get_delta()
hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta()); ->multn(next_layer->get_weights()->transposen())
->hadamard_productn(activation_deriv_matrix));
hidden_layer_w_grad =
layer->get_input()->transposen()->multn(layer->get_delta());
cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well. cumulative_hidden_layer_w_grad.push_back(
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
layer->get_reg()))); // Adding to our cumulative hidden layer
// grads. Maintain reg terms as well.
} }
} }
return cumulative_hidden_layer_w_grad; return cumulative_hidden_layer_w_grad;
} }
void MLPPWGAN::handle_ui(int epoch, real_t cost_prev, const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) { void MLPPWGAN::handle_ui(int epoch, real_t cost_prev,
const Ref<MLPPVector> &y_hat,
const Ref<MLPPVector> &output_set) {
MLPPUtilities::cost_info(epoch, cost_prev, cost(y_hat, output_set)); MLPPUtilities::cost_info(epoch, cost_prev, cost(y_hat, output_set));
PLOG_MSG("Layer " + itos(_network.size() + 1) + ":"); PLOG_MSG("Layer " + itos(_network.size() + 1) + ":");
MLPPUtilities::print_ui_vb(_output_layer->get_weights(), _output_layer->get_bias()); MLPPUtilities::print_ui_vb(_output_layer->get_weights(),
_output_layer->get_bias());
if (!_network.empty()) { if (!_network.empty()) {
for (int i = _network.size() - 1; i >= 0; i--) { for (int i = _network.size() - 1; i >= 0; i--) {
@ -458,23 +547,38 @@ void MLPPWGAN::handle_ui(int epoch, real_t cost_prev, const Ref<MLPPVector> &y_h
void MLPPWGAN::_bind_methods() { void MLPPWGAN::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output_set"), &MLPPWGAN::get_output_set); ClassDB::bind_method(D_METHOD("get_output_set"), &MLPPWGAN::get_output_set);
ClassDB::bind_method(D_METHOD("set_output_set", "val"), &MLPPWGAN::set_output_set); ClassDB::bind_method(D_METHOD("set_output_set", "val"),
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output_set", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_output_set", "get_output_set"); &MLPPWGAN::set_output_set);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output_set",
PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"),
"set_output_set", "get_output_set");
ClassDB::bind_method(D_METHOD("get_k"), &MLPPWGAN::get_k); ClassDB::bind_method(D_METHOD("get_k"), &MLPPWGAN::get_k);
ClassDB::bind_method(D_METHOD("set_k", "val"), &MLPPWGAN::set_k); ClassDB::bind_method(D_METHOD("set_k", "val"), &MLPPWGAN::set_k);
ADD_PROPERTY(PropertyInfo(Variant::INT, "k"), "set_k", "get_k"); ADD_PROPERTY(PropertyInfo(Variant::INT, "k"), "set_k", "get_k");
ClassDB::bind_method(D_METHOD("generate_example", "n"), &MLPPWGAN::generate_example); ClassDB::bind_method(D_METHOD("generate_example", "n"),
ClassDB::bind_method(D_METHOD("gradient_descent", "learning_rate", "max_epoch", "ui"), &MLPPWGAN::gradient_descent, false); &MLPPWGAN::generate_example);
ClassDB::bind_method(
D_METHOD("gradient_descent", "learning_rate", "max_epoch", "ui"),
&MLPPWGAN::gradient_descent, false);
ClassDB::bind_method(D_METHOD("score"), &MLPPWGAN::score); ClassDB::bind_method(D_METHOD("score"), &MLPPWGAN::score);
ClassDB::bind_method(D_METHOD("save", "file_name"), &MLPPWGAN::save); ClassDB::bind_method(D_METHOD("save", "file_name"), &MLPPWGAN::save);
ClassDB::bind_method(D_METHOD("create_layer", "activation", "weight_init", "reg", "lambda", "alpha"), &MLPPWGAN::create_layer, MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT, MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5); ClassDB::bind_method(D_METHOD("create_layer", "activation", "weight_init",
"reg", "lambda", "alpha"),
&MLPPWGAN::create_layer,
MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT,
MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
ClassDB::bind_method(D_METHOD("add_layer", "layer"), &MLPPWGAN::add_layer); ClassDB::bind_method(D_METHOD("add_layer", "layer"), &MLPPWGAN::add_layer);
ClassDB::bind_method(D_METHOD("get_layer", "index"), &MLPPWGAN::get_layer); ClassDB::bind_method(D_METHOD("get_layer", "index"), &MLPPWGAN::get_layer);
ClassDB::bind_method(D_METHOD("remove_layer", "index"), &MLPPWGAN::remove_layer); ClassDB::bind_method(D_METHOD("remove_layer", "index"),
&MLPPWGAN::remove_layer);
ClassDB::bind_method(D_METHOD("get_layer_count"), &MLPPWGAN::score); ClassDB::bind_method(D_METHOD("get_layer_count"), &MLPPWGAN::score);
ClassDB::bind_method(D_METHOD("add_output_layer", "weight_init", "reg", "lambda", "alpha"), &MLPPWGAN::add_output_layer, MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT, MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5); ClassDB::bind_method(
D_METHOD("add_output_layer", "weight_init", "reg", "lambda", "alpha"),
&MLPPWGAN::add_output_layer,
MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT,
MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
} }

View File

@ -31,11 +31,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef USING_SFW
#include "sfw.h"
#else
#include "core/containers/vector.h" #include "core/containers/vector.h"
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/object/reference.h" #include "core/object/reference.h"
#endif
#include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_matrix.h"
#include "../lin_alg/mlpp_tensor3.h" #include "../lin_alg/mlpp_tensor3.h"