You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
/*------------------------------------------------------------------------------
|
|
* 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 <typename dtype>
|
|
Matrix<dtype> flip(const Matrix<dtype> &array, Axis axis = Axis::NONE)
|
|
{
|
|
switch (axis)
|
|
{
|
|
case Axis::NONE:
|
|
{
|
|
Matrix<dtype> returnArray(array);
|
|
std::reverse(std::execution::par_unseq, returnArray.begin(), returnArray.end());
|
|
return returnArray;
|
|
}
|
|
case Axis::COLUMN:
|
|
{
|
|
Matrix<dtype> 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 <typename dtype>
|
|
Matrix<dtype> fliplr(const Matrix<dtype> &array)
|
|
{
|
|
return flip(array, Axis::COLUMN);
|
|
}
|
|
|
|
//============================================================================
|
|
// Method Description:
|
|
/// Flip array in the up/down direction.
|
|
///
|
|
/// @param array
|
|
/// @return Matrix
|
|
///
|
|
template <typename dtype>
|
|
Matrix<dtype> flipud(const Matrix<dtype> &array)
|
|
{
|
|
return flip(array, Axis::ROW);
|
|
}
|
|
} // namespace ais
|