This commit is contained in:
张壹 2025-07-25 12:24:15 +08:00
parent 27aff7e2f5
commit bf14ada539
5 changed files with 21 additions and 11 deletions

View File

@ -97,7 +97,7 @@ if(GCTL_FOUND)
endif() endif()
if(GCTL_FOUND AND GCTL_OPTIMIZATION_FOUND) 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 lgd_solver_ex ON OFF ON OFF)
add_example(optimization ex3 ON OFF ON OFF) add_example(optimization ex3 ON OFF ON OFF)
add_example(optimization ex4 ON OFF ON OFF) add_example(optimization ex4 ON OFF ON OFF)

View File

@ -71,13 +71,13 @@ int main(int argc, char const *argv[]) try
*/ */
array<double> x(201), y(301); array<double> x(201), y(301);
x.sequence(-1.0, 0.01); sequence(x, -1.0, 0.01);
y.sequence(0.0, 0.01); sequence(y, 0.0, 0.01);
kde2d k(0.1, 0.1, x, y); kde2d k(0.1, 0.1, x, y);
array<double> a(10000), b(10000); array<double> a(10000), b(10000);
a.random_float(0, 0.2, RdNormal, 0); random_float(a, 0.0, 0.2, RdNormal, 0);
b.random_float(1.5, 0.3, RdNormal, 0); random_float(b, 1.5, 0.3, RdNormal, 0);
gaussian_para2d g1(0, 1.5, 0.2, 0.3, 0); gaussian_para2d g1(0, 1.5, 0.2, 0.3, 0);

View File

@ -33,7 +33,7 @@ using namespace gctl;
int main(int argc, char const *argv[]) try int main(int argc, char const *argv[]) try
{ {
_2d_matrix m(5, 4); _2d_matrix m(5, 4);
m.sequence(1.0, 1.0, 0.1); sequence2d(m, 1.0, 1.0, 0.1);
m.show(); m.show();
m.resize(2, 10); m.resize(2, 10);
@ -43,10 +43,17 @@ int main(int argc, char const *argv[]) try
m2.show(); m2.show();
_1d_array a, a2; _1d_array a, a2;
m.export_array(a); export_array(m, a, RowMajor);
m2.export_array(a2); export_array(m, a2, ColMajor);
a.show(); a.show();
a2.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; return 0;
} }
catch(std::exception &e) catch(std::exception &e)

View File

@ -25,6 +25,7 @@
* Also add information on how to contact you by electronic and paper mail. * Also add information on how to contact you by electronic and paper mail.
******************************************************/ ******************************************************/
#include "gctl/core.h"
#include "gctl/poly.h" #include "gctl/poly.h"
#include "gctl/math.h" #include "gctl/math.h"
@ -40,7 +41,7 @@ int main(int argc, char const *argv[]) try
//ml.init(xs, std); //ml.init(xs, std);
array<double> x(201); array<double> x(201);
x.sequence(0.1, 0.001); sequence(x, 0.1, 0.001);
for (size_t i = 0; i < x.size(); i++) for (size_t i = 0; i < x.size(); i++)
{ {

View File

@ -25,6 +25,8 @@
* Also add information on how to contact you by electronic and paper mail. * 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/optimization/lcg.h"
#include "gctl/graphic/gnuplot.h" #include "gctl/graphic/gnuplot.h"
@ -63,7 +65,7 @@ private:
ex1::ex1() ex1::ex1()
{ {
kernel.resize(M, N); 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); tmp_arr.resize(M);
p.resize(N); p.resize(N);
@ -109,7 +111,7 @@ int main(int argc, char const *argv[])
{ {
// 生成一组正演解 // 生成一组正演解
gctl::array<double> fm(N); gctl::array<double> fm(N);
fm.random_float(1.0, 2.0, gctl::RdUniform); random_float(fm, 1.0, 2.0, gctl::RdUniform);
ex1 test; ex1 test;