Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:hguo/ftk into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hguo committed Nov 21, 2023
2 parents ebb4aef + c79846a commit 0188d2a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions include/ftk/ndarray.hh
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ template <typename T>
template <typename T1>
void ndarray<T>::reshape(const ndarray<T1>& array)
{
reshape(array);
reshapef(array.shapef());
}

template <typename T>
Expand Down Expand Up @@ -1246,7 +1246,7 @@ template <typename T>
ndarray<T> ndarray<T>::stack(const std::vector<ndarray<T>>& arrays)
{
ndarray<T> result;
std::vector<size_t> result_shape = arrays[0].shape();
std::vector<size_t> result_shape = arrays[0].shapef();
result_shape.push_back(arrays.size());
result.reshapef(result_shape);

Expand Down Expand Up @@ -1283,7 +1283,7 @@ template <typename T>
pybind11::array_t<T, pybind11::array::c_style> ndarray<T>::to_numpy() const
{
auto result = pybind11::array_t<T>(nelem());
result.resize(shape());
result.resize(shapef());
pybind11::buffer_info buf = result.request();

T *ptr = (T*)buf.ptr;
Expand Down
2 changes: 1 addition & 1 deletion include/ftk/ndarray/ndarray_base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T> void reshape(const ndarray<T>& array); //! copy shape from another array
// template <typename T> void reshape(const ndarray<T>& array); //! copy shape from another array

public:
size_t indexf(const std::vector<size_t>& idx) const;
Expand Down
4 changes: 2 additions & 2 deletions include/ftk/ndarray/synthetic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ndarray<T> 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);
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ ndarray<T> synthetic_double_gyre_unstructured(
const T epsilon = 0.25)
{
ndarray<T> result;
result.reshapef(coords);
result.reshape(coords);
result.set_multicomponents();

for (auto i = 0; i < coords.dim(1); i ++) {
Expand Down
26 changes: 13 additions & 13 deletions python/pyftk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ PYBIND11_MODULE(pyftk, m) {
throw std::runtime_error("Number of dimensions must be 4 (1, width, height, 1)");

ftk::ndarray<double> 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 );
Expand Down Expand Up @@ -55,10 +55,10 @@ PYBIND11_MODULE(pyftk, m) {
throw std::runtime_error("Number of dimensions must be 4 (2, width, height, 1)");

ftk::ndarray<double> 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 );
Expand Down Expand Up @@ -95,8 +95,8 @@ PYBIND11_MODULE(pyftk, m) {
throw std::runtime_error("Number of dimensions must be 4: (1, width, height, time)");

ftk::ndarray<double> 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 );
Expand Down Expand Up @@ -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<double>(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<ftk::ndarray<double>> 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<double>::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");
Expand All @@ -172,7 +172,7 @@ PYBIND11_MODULE(pyftk, m) {
std::vector<size_t> shape = {(size_t)DW, (size_t)DH};
for (int k = 0; k < DT; k ++) {
auto a = ftk::synthetic_moving_extremum<double, 2>(shape, xc, dir, (double)k);
a.reshape(1, DW, DH);
a.reshapef(1, DW, DH);
arrays.push_back( a );
}
return ftk::ndarray<double>::stack(arrays).to_numpy();
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down

0 comments on commit 0188d2a

Please sign in to comment.