From bf14ada53936bec924765640f80ac14bc683caef Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Fri, 25 Jul 2025 12:24:15 +0800 Subject: [PATCH] tmp --- CMakeLists.txt | 2 +- src/core/kde_ex.cpp | 8 ++++---- src/core/matrix_ex.cpp | 13 ++++++++++--- src/core/multinary_ex.cpp | 3 ++- src/optimization/{ex1.cpp => lcg_solver_ex.cpp} | 6 ++++-- 5 files changed, 21 insertions(+), 11 deletions(-) rename src/optimization/{ex1.cpp => lcg_solver_ex.cpp} (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 749da9a..d0a3f85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if(GCTL_FOUND) endif() if(GCTL_FOUND AND GCTL_OPTIMIZATION_FOUND) - add_example(optimization ex1 ON OFF ON OFF) + add_example(optimization lcg_solver_ex ON OFF ON OFF) add_example(optimization lgd_solver_ex ON OFF ON OFF) add_example(optimization ex3 ON OFF ON OFF) add_example(optimization ex4 ON OFF ON OFF) diff --git a/src/core/kde_ex.cpp b/src/core/kde_ex.cpp index e268cda..e8dcaac 100644 --- a/src/core/kde_ex.cpp +++ b/src/core/kde_ex.cpp @@ -71,13 +71,13 @@ int main(int argc, char const *argv[]) try */ array x(201), y(301); - x.sequence(-1.0, 0.01); - y.sequence(0.0, 0.01); + sequence(x, -1.0, 0.01); + sequence(y, 0.0, 0.01); kde2d k(0.1, 0.1, x, y); array a(10000), b(10000); - a.random_float(0, 0.2, RdNormal, 0); - b.random_float(1.5, 0.3, RdNormal, 0); + random_float(a, 0.0, 0.2, RdNormal, 0); + random_float(b, 1.5, 0.3, RdNormal, 0); gaussian_para2d g1(0, 1.5, 0.2, 0.3, 0); diff --git a/src/core/matrix_ex.cpp b/src/core/matrix_ex.cpp index fc871dd..2bf075f 100644 --- a/src/core/matrix_ex.cpp +++ b/src/core/matrix_ex.cpp @@ -33,7 +33,7 @@ using namespace gctl; int main(int argc, char const *argv[]) try { _2d_matrix m(5, 4); - m.sequence(1.0, 1.0, 0.1); + sequence2d(m, 1.0, 1.0, 0.1); m.show(); m.resize(2, 10); @@ -43,10 +43,17 @@ int main(int argc, char const *argv[]) try m2.show(); _1d_array a, a2; - m.export_array(a); - m2.export_array(a2); + export_array(m, a, RowMajor); + export_array(m, a2, ColMajor); a.show(); a2.show(); + + random_float(m2, 0.0, 1.0); + m2.show(); + + _2i_matrix m3(5, 5); + random_int(m3, 0, 10); + m3.show(); return 0; } catch(std::exception &e) diff --git a/src/core/multinary_ex.cpp b/src/core/multinary_ex.cpp index abde5d8..88e63e1 100644 --- a/src/core/multinary_ex.cpp +++ b/src/core/multinary_ex.cpp @@ -25,6 +25,7 @@ * Also add information on how to contact you by electronic and paper mail. ******************************************************/ +#include "gctl/core.h" #include "gctl/poly.h" #include "gctl/math.h" @@ -40,7 +41,7 @@ int main(int argc, char const *argv[]) try //ml.init(xs, std); array x(201); - x.sequence(0.1, 0.001); + sequence(x, 0.1, 0.001); for (size_t i = 0; i < x.size(); i++) { diff --git a/src/optimization/ex1.cpp b/src/optimization/lcg_solver_ex.cpp similarity index 96% rename from src/optimization/ex1.cpp rename to src/optimization/lcg_solver_ex.cpp index 47e765c..acdd40f 100644 --- a/src/optimization/ex1.cpp +++ b/src/optimization/lcg_solver_ex.cpp @@ -25,6 +25,8 @@ * Also add information on how to contact you by electronic and paper mail. ******************************************************/ +#include "gctl/core/array_algorithm.h" +#include "gctl/core/matrix_algorithm.h" #include "gctl/optimization/lcg.h" #include "gctl/graphic/gnuplot.h" @@ -63,7 +65,7 @@ private: ex1::ex1() { kernel.resize(M, N); - kernel.random_float(-1.0, 1.0, gctl::RdUniform); + random_float(kernel, -1.0, 1.0, gctl::RdUniform); tmp_arr.resize(M); p.resize(N); @@ -109,7 +111,7 @@ int main(int argc, char const *argv[]) { // 生成一组正演解 gctl::array fm(N); - fm.random_float(1.0, 2.0, gctl::RdUniform); + random_float(fm, 1.0, 2.0, gctl::RdUniform); ex1 test;