diff --git a/CMakeLists.txt b/CMakeLists.txt index d75e85a..4f78279 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ include(CMakePackageConfigHelpers) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# ExprTK库在macOS 15.4中编译会有错误 添加以下命令对应检查项 +add_compile_options(-Wno-missing-template-arg-list-after-template-kw) + # 添加编译选项 option(GCTL_OPENMP "Use the OpenMP library" ON) option(GCTL_NETCDF "Use the NetCDF library" ON) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7b50a73..33447b2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -21,7 +21,7 @@ add_example(fir_filter_ex OFF) add_example(fft_filter_ex OFF) add_example(windowfunc_ex OFF) add_example(legendre_ex OFF) -add_example(refellipsoid_ex ON) +add_example(refellipsoid_ex OFF) add_example(kde_ex OFF) add_example(meshio_ex OFF) add_example(autodiff_ex OFF) @@ -34,4 +34,6 @@ add_example(gmt_ex OFF) add_example(gnuplot_ex OFF) add_example(cliplot_ex OFF) add_example(stl_io_ex OFF) -add_example(ply_io_ex OFF) \ No newline at end of file +add_example(ply_io_ex OFF) +add_example(sparray_ex OFF) +add_example(sparray2d_ex OFF) \ No newline at end of file diff --git a/example/sparray2d_ex.cpp b/example/sparray2d_ex.cpp new file mode 100644 index 0000000..71a4231 --- /dev/null +++ b/example/sparray2d_ex.cpp @@ -0,0 +1,43 @@ +/******************************************************** + * ██████╗ ██████╗████████╗██╗ + * ██╔════╝ ██╔════╝╚══██╔══╝██║ + * ██║ ███╗██║ ██║ ██║ + * ██║ ██║██║ ██║ ██║ + * ╚██████╔╝╚██████╗ ██║ ███████╗ + * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝ + * Geophysical Computational Tools & Library (GCTL) + * + * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn) + * + * GCTL is distributed under a dual licensing scheme. You can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 2 + * of the License, or (at your option) any later version. You should have + * received a copy of the GNU Lesser General Public License along with this + * program. If not, see . + * + * If the terms and conditions of the LGPL v.2. would prevent you from using + * the GCTL, please consider the option to obtain a commercial license for a + * fee. These licenses are offered by the GCTL's original author. As a rule, + * licenses are provided "as-is", unlimited in time for a one time fee. Please + * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget + * to include some description of your company and the realm of its activities. + * Also add information on how to contact you by electronic and paper mail. + ******************************************************/ + +#include "gctl/core.h" + +int main(int argc, char const *argv[]) +{ + gctl::sparray2d M(10, 10, 0.0); + + M.at(4)->set(4, 5); + M.at(2)->set(3, 8); + M.at(6)->set(8, 2); + + for (int i = 0; i < M.size(); i++) + { + M.at(i)->show_full(); + } + return 0; +} \ No newline at end of file diff --git a/example/sparray_ex.cpp b/example/sparray_ex.cpp new file mode 100644 index 0000000..9ad967d --- /dev/null +++ b/example/sparray_ex.cpp @@ -0,0 +1,114 @@ +/******************************************************** + * ██████╗ ██████╗████████╗██╗ + * ██╔════╝ ██╔════╝╚══██╔══╝██║ + * ██║ ███╗██║ ██║ ██║ + * ██║ ██║██║ ██║ ██║ + * ╚██████╔╝╚██████╗ ██║ ███████╗ + * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝ + * Geophysical Computational Tools & Library (GCTL) + * + * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn) + * + * GCTL is distributed under a dual licensing scheme. You can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 2 + * of the License, or (at your option) any later version. You should have + * received a copy of the GNU Lesser General Public License along with this + * program. If not, see . + * + * If the terms and conditions of the LGPL v.2. would prevent you from using + * the GCTL, please consider the option to obtain a commercial license for a + * fee. These licenses are offered by the GCTL's original author. As a rule, + * licenses are provided "as-is", unlimited in time for a one time fee. Please + * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget + * to include some description of your company and the realm of its activities. + * Also add information on how to contact you by electronic and paper mail. + ******************************************************/ + +#include "../lib/core.h" +#include "../lib/algorithms.h" + +int main(int argc, char const *argv[]) +{ + srand(time(0)); + gctl::sparray M(50, 0.0); + gctl::sparray L; + + int tmp_id[13] = {4, 2, 6, 7, 8, 12, 23, 43, 33, 47, 38, 15, 1}; + int tmp_size = 13; + for (int i = 0; i < tmp_size; i++) + { + M.set(tmp_id[i], gctl::random(10.0, 20.0)); + } + + M.show_list(); + std::cout << "************" << std::endl; + + M.copy_to(L, 2); + L.show_list(); + + M.set(18, 100); + M.set(38, 100); + M.remove(12); + + std::cout << "************" << std::endl; + M.show_list(); + + gctl::array C(50, -1.0); + M.export_dense(C, 1.0, gctl::AppendVal); + for (int i = 0; i < C.size(); i++) + { + std::cout << C.at(i) << " "; + } + std::cout << std::endl; + + gctl::sparray N(C, -1, 1e-10); + N.show_list(); + + std::cout << "Test 2" << std::endl; + + M.clear(); + M.malloc(20, 0.0); + + M.set(5, 6.5); + M.set(9, 9.1); + M.set(3, 4.3); + M.set(17, 1.4); + M.set(10, 3.5); + M.set(7, 7.4); + + M.show_list(); + + M.remove(17); + M.remove(9); + + std::cout << "**********" << std::endl; + M.show_list(); + + std::cout << "Test 3" << std::endl; + + int test_size = 500000; + + M.clear(); + M.malloc(test_size, 0.0); + + clock_t start = clock(); + for (int i = 0; i < 300000; i++) + { + M.set(i, gctl::random(10.0, 20.0)); + } + for (int i = 300001; i < test_size; i++) + { + M.set(i, gctl::random(10.0, 20.0)); + } + M.set(300000, 15.8888); + + clock_t end = clock(); + std::cout << "sparray set() time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl; + + std::cout << "M.at(300000) = " << M.value(300000) << std::endl; + + M.show_list(299995, 300005); + + return 0; +} \ No newline at end of file diff --git a/lib/core/sparray.h b/lib/core/sparray.h index dfa75f5..d57322e 100644 --- a/lib/core/sparray.h +++ b/lib/core/sparray.h @@ -433,7 +433,7 @@ namespace gctl for (int i = 0; i < arr1d.size(); i++) { - b.insert(arr1d[i].id, multipler*arr1d[i].val); + b.set(arr1d[i].id, multipler*arr1d[i].val); } return; }