This commit is contained in:
张壹 2025-07-23 11:09:05 +08:00
parent 93b125cbd5
commit 7bd7a8a09b
4 changed files with 25 additions and 51 deletions

View File

@ -38,57 +38,28 @@ double get_x(const point3dc &p)
int main(int argc, char const *argv[]) try
{
// create a new array and give initial values
array<double> A(10, 0.0, 1.0);
A.memory_usage();
array<double> a(10, 1.0);
array<double> b(10, 2.0);
a.show();
std::cout << b << "\n";
A.log2linear(2);
A.show();
if (a != b) std::cout << "a != b\n";
A.linear2log(2);
A.show();
array<double> c;
c = a + b; c.show();
c = a - b; c.show();
c = b - a; c.show();
c = a * b; c.show();
c = a / b; c.show();
c = b / a; c.show();
A.for_each([](double &a){a += 1;});
A.show();
A.sequence(1.0, 0.5, 3, 4, 1);
A.show();
// copy A to a new array
array<double> B = A;
B.normalize();
B.show();
array<double> S = A + B;
std::cout << "B + A = ";
S.show();
S.normalize();
S.show();
array<point3dc> P(5);
P.sequence(point3dc(0, 0, 0), point3dc(2, 1, 0.5));
P.show(std::cout, '\n');
//array<double> Px = P.extract<double>([](const point3dc &p)->double{return p.x;});
array<double> Px = P.extract<double>(get_x);
Px.show();
// create a new 2D array
matrix<int> C(5, 5, 1);
C.sequence(0, 1, 10);
std::cout << "C = \n";
C.show();
// save array to a binary file
save_matrix2binary("tmp/array_ex_out", C, "Int");
// import 2D array to a new object
matrix<int> D;
read_binary2matrix("tmp/array_ex_out", D);
std::cout << "D = \n";
D.show();
double s = 3.0;
c = a + s; c.show();
c = a - s; c.show();
c = s - a; c.show();
c = a * s; c.show();
c = a / s; c.show();
c = s / a; c.show();
return 0;
}
catch(std::exception &e)

View File

@ -128,7 +128,8 @@ int main(int argc, char const *argv[]) try
}
_1d_array out_freq, out_power, out_std;
out_freq.resize(150, 1.0, 1.0);
out_freq.resize(150);
out_freq.sequence(1.0, 1.0);
average_radian_spec(pro_freq, pro_spec, out_freq, out_power, out_std);
std::ofstream ofile;

View File

@ -31,8 +31,9 @@ using namespace gctl;
int main(int argc, char const *argv[])
{
_1d_array a(10, 1.0, 0.1);
_1d_array a(10);
_1d_array b(10, 1.0);
a.sequence(1.0, 1.0);
_1d_array c(10);
veccpy(c, a, 2.0);

View File

@ -39,7 +39,8 @@ int main(int argc, char const *argv[]) try
//array<double> xs = {-2.2, -1.8, -1.5, -1.0, -0.7, -0.2, 0.9, 1.3, 1.9, 2.5};
//ml.init(xs, std);
array<double> x(201, 0.1, 0.001);
array<double> x(201);
x.sequence(0.1, 0.001);
for (size_t i = 0; i < x.size(); i++)
{