diff --git a/include/ftk/ndarray.hh b/include/ftk/ndarray.hh index 0cb2645b..59cef44e 100644 --- a/include/ftk/ndarray.hh +++ b/include/ftk/ndarray.hh @@ -788,7 +788,7 @@ template template void ndarray::reshape(const ndarray& array) { - reshape(array); + reshapef(array.shapef()); } template @@ -1246,7 +1246,7 @@ template ndarray ndarray::stack(const std::vector>& arrays) { ndarray result; - std::vector result_shape = arrays[0].shape(); + std::vector result_shape = arrays[0].shapef(); result_shape.push_back(arrays.size()); result.reshapef(result_shape); @@ -1283,7 +1283,7 @@ template pybind11::array_t ndarray::to_numpy() const { auto result = pybind11::array_t(nelem()); - result.resize(shape()); + result.resize(shapef()); pybind11::buffer_info buf = result.request(); T *ptr = (T*)buf.ptr; diff --git a/include/ftk/ndarray/ndarray_base.hh b/include/ftk/ndarray/ndarray_base.hh index 6df1edec..8ed78ac9 100644 --- a/include/ftk/ndarray/ndarray_base.hh +++ b/include/ftk/ndarray/ndarray_base.hh @@ -107,7 +107,7 @@ struct ndarray_base { [[deprecated]] void reshape(size_t ndims, const size_t sizes[]) { reshapef(ndims, sizes); } void reshape(const ndarray_base& array); //! copy shape from another array - template void reshape(const ndarray& array); //! copy shape from another array + // template void reshape(const ndarray& array); //! copy shape from another array public: size_t indexf(const std::vector& idx) const; diff --git a/include/ftk/ndarray/synthetic.hh b/include/ftk/ndarray/synthetic.hh index 243b6916..cd36e9c2 100644 --- a/include/ftk/ndarray/synthetic.hh +++ b/include/ftk/ndarray/synthetic.hh @@ -101,7 +101,7 @@ ndarray synthetic_woven_2Dt(int DW, int DH, int DT, T scaling_factor = T(15)) const T x = ((T(i) / (DW-1)) - 0.5) * scaling_factor, y = ((T(j) / (DH-1)) - 0.5) * scaling_factor, t = (T(k) / (DT-1)) + 1e-4; - scalar(i, j, k) = woven_function_2Dt(x, y, t); + scalar.f(i, j, k) = woven_function_2Dt(x, y, t); } } } @@ -178,7 +178,7 @@ ndarray synthetic_double_gyre_unstructured( const T epsilon = 0.25) { ndarray result; - result.reshapef(coords); + result.reshape(coords); result.set_multicomponents(); for (auto i = 0; i < coords.dim(1); i ++) { diff --git a/python/pyftk.cpp b/python/pyftk.cpp index fae73a1f..711e7663 100644 --- a/python/pyftk.cpp +++ b/python/pyftk.cpp @@ -18,8 +18,8 @@ PYBIND11_MODULE(pyftk, m) { throw std::runtime_error("Number of dimensions must be 4 (1, width, height, 1)"); ftk::ndarray data(array); - const size_t DW = data.dim(0), DH = data.dim(1); - data.reshape(DW, DH); + const size_t DW = data.dimf(0), DH = data.dimf(1); + data.reshapef(DW, DH); ftk::critical_point_tracker_2d_regular tracker(comm); tracker.set_scalar_field_source( ftk::SOURCE_GIVEN ); @@ -55,10 +55,10 @@ PYBIND11_MODULE(pyftk, m) { throw std::runtime_error("Number of dimensions must be 4 (2, width, height, 1)"); ftk::ndarray data(array); - if (data.dim(0) != 2) + if (data.dimf(0) != 2) throw std::runtime_error("The first dimension must be 2"); - const size_t DW = data.dim(1), DH = data.dim(2); - data.reshape(2, DW, DH); + const size_t DW = data.dimf(1), DH = data.dimf(2); + data.reshapef(2, DW, DH); ftk::critical_point_tracker_2d_regular tracker(comm); tracker.set_scalar_field_source( ftk::SOURCE_NONE ); @@ -95,8 +95,8 @@ PYBIND11_MODULE(pyftk, m) { throw std::runtime_error("Number of dimensions must be 4: (1, width, height, time)"); ftk::ndarray data(array); - const size_t DW = data.dim(1), DH = data.dim(2), DT = data.dim(3); - data.reshape(DW, DH, DT); + const size_t DW = data.dimf(1), DH = data.dimf(2), DT = data.dimf(3); + data.reshapef(DW, DH, DT); ftk::critical_point_tracker_2d_regular tracker(comm); tracker.set_scalar_field_source( ftk::SOURCE_GIVEN ); @@ -144,21 +144,21 @@ PYBIND11_MODULE(pyftk, m) { py::module synth = m.def_submodule("synthesizers", "Synthetic data generator"); synth.def("spiral_woven", [](int DW, int DH, int DT) { auto array = ftk::synthetic_woven_2Dt(DW, DH, DT); - array.reshape(1, DW, DH, DT); + array.reshapef(1, DW, DH, DT); return array.to_numpy(); }, R"pbdoc(Generate 2D spiral woven data)pbdoc"); synth.def("double_gyre_flow", [](int DW, int DH, int DT) { if (DT == 1) { auto array = ftk::synthetic_double_gyre(DW, DH, 0.0); - array.reshape(2, DW, DH, 1); + array.reshapef(2, DW, DH, 1); return array.to_numpy(); } else if (DT > 1) { std::vector> arrays; for (int i = 0; i < DT; i ++) arrays.push_back( ftk::synthetic_double_gyre(DW, DH, (double)i*0.1) ); auto array = ftk::ndarray::stack(arrays); - array.reshape(2, DW, DH, DT); + array.reshapef(2, DW, DH, DT); return array.to_numpy(); } else { throw std::runtime_error("DT must be an integer greater than 1"); @@ -172,7 +172,7 @@ PYBIND11_MODULE(pyftk, m) { std::vector shape = {(size_t)DW, (size_t)DH}; for (int k = 0; k < DT; k ++) { auto a = ftk::synthetic_moving_extremum(shape, xc, dir, (double)k); - a.reshape(1, DW, DH); + a.reshapef(1, DW, DH); arrays.push_back( a ); } return ftk::ndarray::stack(arrays).to_numpy(); @@ -187,7 +187,7 @@ PYBIND11_MODULE(pyftk, m) { double M[4][4]; for (int i = 0; i < 4; i ++) for (int j = 0; j < 4; j ++) - M[i][j] = m(j, i); + M[i][j] = m.f(j, i); return ftk::det4(M); }); @@ -200,7 +200,7 @@ PYBIND11_MODULE(pyftk, m) { double M[3][3]; for (int i = 0; i < 3; i ++) for (int j = 0; j < 3; j ++) - M[i][j] = m(j, i); + M[i][j] = m.f(j, i); return ftk::det3(M); });