/*------------------------------------------------------------------------------ * Copyright (c) 2023 by Bai Bing (seread@163.com) * S++ COPYING file for copying and redistribution conditions. * * Alians IT Studio. *----------------------------------------------------------------------------*/ #pragma once #include "ASMatrix.h" namespace ais { //============================================================================ // Method Description: /// Reverse the order of elements in an array along the given axis. /// /// @param array /// @param axis /// @return Matrix /// template Matrix flip(const Matrix &array, Axis axis = Axis::NONE) { switch (axis) { case Axis::NONE: { Matrix returnArray(array); std::reverse(std::execution::par_unseq, returnArray.begin(), returnArray.end()); return returnArray; } case Axis::COLUMN: { Matrix returnArray(array); for (uint32_t row = 0; row < array.shape().rows; ++row) { std::reverse(std::execution::par_unseq, returnArray.begin(row), returnArray.end(row)); } return returnArray; } case Axis::ROW: { return flip(array.transpose(), Axis::COLUMN).transpose(); } default: { THROW_INVALID_ARGUMENT("Unimplemented axis type."); return {}; // get rid of compiler warning } } } //============================================================================ // Method Description: /// Flip array in the left/right direction. /// /// @param array /// @return Matrix /// template Matrix fliplr(const Matrix &array) { return flip(array, Axis::COLUMN); } //============================================================================ // Method Description: /// Flip array in the up/down direction. /// /// @param array /// @return Matrix /// template Matrix flipud(const Matrix &array) { return flip(array, Axis::ROW); } } // namespace ais