finish PIVector doc
This commit is contained in:
@@ -1936,7 +1936,13 @@ public:
|
||||
//! \~russian Изменяет размерность массива, из одномерного массива создает двухмерный.
|
||||
//! \~\details
|
||||
//! \~russian
|
||||
//! \param rows размер внешнего массива
|
||||
//! \param cols размер внутренних массивов
|
||||
//! \param order порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder
|
||||
//! \~english
|
||||
//! \param rows size external array
|
||||
//! \param cols size internal arrays
|
||||
//! \param order the order of traversing the source array is set using \a ReshapeOrder
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3, 4};
|
||||
//! PIVector<PIVector<int>> m1 = v.reshape(2,2);
|
||||
@@ -1944,7 +1950,7 @@ public:
|
||||
//! PIVector<PIVector<int>> m2 = v.reshape(2,2, ReshapeByColumn);
|
||||
//! piCout << m2; // {{1, 3}, {2, 4}}
|
||||
//! \endcode
|
||||
//! \~\sa \a map(), \a reduce()
|
||||
//! \~\sa \a map(), \a reduce(), \a flatten()
|
||||
inline PIVector<PIVector<T>> reshape(size_t rows, size_t cols, ReshapeOrder order = ReshapeByRow) const {
|
||||
#ifndef NDEBUG
|
||||
if (rows*cols != piv_size) {
|
||||
@@ -1971,10 +1977,25 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Changes the dimension of the array, creates a one-dimensional array from a two-dimensional array.
|
||||
//! \~russian Изменяет размерность массива, из двухмерный массива создает одномерный.
|
||||
//! \~\details
|
||||
//! \~russian Делает массив плоским.
|
||||
//! Порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder.
|
||||
//! \~english Makes the array flat.
|
||||
//! Еhe order of traversing the source array is set using \a ReshapeOrder.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3, 4, 5, 6};
|
||||
//! PIVector<PIVector<int>> xv = v.reshape(3,2);
|
||||
//! piCout << xv; // {{1, 2}, {3, 4}, {5, 6}}
|
||||
//! piCout << xv.flatten<int>(); // {1, 2, 3, 4, 5, 6}
|
||||
//! \endcode
|
||||
//! \~\sa \a map(), \a reduce(), \a reshape()
|
||||
template<typename C, typename std::enable_if<
|
||||
std::is_same<T, PIVector<C>>::value
|
||||
, int>::type = 0>
|
||||
inline PIVector<C> flat(ReshapeOrder order = ReshapeByRow) const {
|
||||
inline PIVector<C> flatten(ReshapeOrder order = ReshapeByRow) const {
|
||||
PIVector<C> ret;
|
||||
if (isEmpty()) return ret;
|
||||
size_t rows = size();
|
||||
@@ -1996,35 +2017,31 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Changes the dimension of the two-dimensional array.
|
||||
//! \~russian Изменяет размерность двухмерного массива.
|
||||
//! \~\details
|
||||
//! \~russian
|
||||
//! \param rows размер внешнего массива
|
||||
//! \param cols размер внутренних массивов
|
||||
//! \param order порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder
|
||||
//! \~english
|
||||
//! \param rows size external array
|
||||
//! \param cols size internal arrays
|
||||
//! \param order the order of traversing the source array is set using \a ReshapeOrder
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3, 4, 5, 6};
|
||||
//! PIVector<PIVector<int>> xv = v.reshape(3,2);
|
||||
//! piCout << xv; // {{1, 2}, {3, 4}, {5, 6}}
|
||||
//! piCout << xv.reshape<int>(2,3); // {{1, 2, 3}, {4, 5, 6}}
|
||||
//! \endcode
|
||||
//! \~\sa \a map(), \a reduce(), \a reshape()
|
||||
template<typename C, typename std::enable_if<
|
||||
std::is_same<T, PIVector<C>>::value
|
||||
, int>::type = 0>
|
||||
inline PIVector<PIVector<C>> reshape(size_t rows, size_t cols, ReshapeOrder order = ReshapeByRow) const {
|
||||
#ifndef NDEBUG
|
||||
if (rows*cols != piv_size) {
|
||||
printf("error with PIVector<%s>::reshape\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(rows*cols == piv_size);
|
||||
PIVector<PIVector<C>> ret;
|
||||
if (isEmpty()) return ret;
|
||||
// size_t old_rows = size();
|
||||
// size_t old_cols = at(0).size();
|
||||
// ret.resize(rows);
|
||||
// if (order == ReshapeByRow) {
|
||||
// for (size_t r = 0; r < rows; r++) {
|
||||
// ret.append(at(r));
|
||||
// }
|
||||
// }
|
||||
// if (order == ReshapeByColumn) {
|
||||
// for (size_t c = 0; c < cols; c++) {
|
||||
// for (size_t r = 0; r < rows; r++) {
|
||||
// ret << at(r)[c];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ret.resize(rows * cols);
|
||||
return ret;
|
||||
PIVector<C> fl = flatten<C>();
|
||||
return fl.reshape(rows, cols, order);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
8
main.cpp
8
main.cpp
@@ -62,8 +62,10 @@ PICout operator <<(PICout s, const ConstChars & v) {
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIVector<int> v{1, 2, 3, 4};
|
||||
PIVector<PIVector<int>> v2 = v.reshape(2,2, ReshapeByRow);
|
||||
piCout << v2;
|
||||
PIVector<int> v{1, 2, 3, 4, 5, 6};
|
||||
PIVector<PIVector<int>> xv = v.reshape(3,2);
|
||||
piCout << xv;
|
||||
piCout << xv.flatten<int>();
|
||||
piCout << xv.reshape<int>(2,3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user