reduce.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "ultra_infer/core/fd_tensor.h"
  16. namespace ultra_infer {
  17. namespace function {
  18. /** Execute the maximum operation for input FDTensor along given dims.
  19. @param x The input tensor.
  20. @param out The output tensor which stores the result.
  21. @param dims The vector of axis which will be reduced.
  22. @param keep_dim Whether to keep the reduced dims, default false.
  23. @param reduce_all Whether to reduce all dims, default false.
  24. */
  25. ULTRAINFER_DECL void Max(const FDTensor &x, FDTensor *out,
  26. const std::vector<int64_t> &dims,
  27. bool keep_dim = false, bool reduce_all = false);
  28. /** Execute the minimum operation for input FDTensor along given dims.
  29. @param x The input tensor.
  30. @param out The output tensor which stores the result.
  31. @param dims The vector of axis which will be reduced.
  32. @param keep_dim Whether to keep the reduced dims, default false.
  33. @param reduce_all Whether to reduce all dims, default false.
  34. */
  35. ULTRAINFER_DECL void Min(const FDTensor &x, FDTensor *out,
  36. const std::vector<int64_t> &dims,
  37. bool keep_dim = false, bool reduce_all = false);
  38. /** Execute the sum operation for input FDTensor along given dims.
  39. @param x The input tensor.
  40. @param out The output tensor which stores the result.
  41. @param dims The vector of axis which will be reduced.
  42. @param keep_dim Whether to keep the reduced dims, default false.
  43. @param reduce_all Whether to reduce all dims, default false.
  44. */
  45. ULTRAINFER_DECL void Sum(const FDTensor &x, FDTensor *out,
  46. const std::vector<int64_t> &dims,
  47. bool keep_dim = false, bool reduce_all = false);
  48. /** Execute the all operation for input FDTensor along given dims.
  49. @param x The input tensor.
  50. @param out The output tensor which stores the result.
  51. @param dims The vector of axis which will be reduced.
  52. @param keep_dim Whether to keep the reduced dims, default false.
  53. @param reduce_all Whether to reduce all dims, default false.
  54. */
  55. ULTRAINFER_DECL void All(const FDTensor &x, FDTensor *out,
  56. const std::vector<int64_t> &dims,
  57. bool keep_dim = false, bool reduce_all = false);
  58. /** Execute the any operation for input FDTensor along given dims.
  59. @param x The input tensor.
  60. @param out The output tensor which stores the result.
  61. @param dims The vector of axis which will be reduced.
  62. @param keep_dim Whether to keep the reduced dims, default false.
  63. @param reduce_all Whether to reduce all dims, default false.
  64. */
  65. ULTRAINFER_DECL void Any(const FDTensor &x, FDTensor *out,
  66. const std::vector<int64_t> &dims,
  67. bool keep_dim = false, bool reduce_all = false);
  68. /** Execute the mean operation for input FDTensor along given dims.
  69. @param x The input tensor.
  70. @param out The output tensor which stores the result.
  71. @param dims The vector of axis which will be reduced.
  72. @param keep_dim Whether to keep the reduced dims, default false.
  73. @param reduce_all Whether to reduce all dims, default false.
  74. */
  75. ULTRAINFER_DECL void Mean(const FDTensor &x, FDTensor *out,
  76. const std::vector<int64_t> &dims,
  77. bool keep_dim = false, bool reduce_all = false);
  78. /** Execute the product operation for input FDTensor along given dims.
  79. @param x The input tensor.
  80. @param out The output tensor which stores the result.
  81. @param dims The vector of axis which will be reduced.
  82. @param keep_dim Whether to keep the reduced dims, default false.
  83. @param reduce_all Whether to reduce all dims, default false.
  84. */
  85. ULTRAINFER_DECL void Prod(const FDTensor &x, FDTensor *out,
  86. const std::vector<int64_t> &dims,
  87. bool keep_dim = false, bool reduce_all = false);
  88. /** Execute the argmax operation for input FDTensor along given dims.
  89. @param x The input tensor.
  90. @param out The output tensor which stores the result.
  91. @param axis The axis which will be reduced.
  92. @param output_dtype The data type of output FDTensor, INT64 or INT32,
  93. default to INT64.
  94. @param keep_dim Whether to keep the reduced dims, default false.
  95. @param flatten Whether to flatten FDTensor to get the argmin index, default
  96. false.
  97. */
  98. ULTRAINFER_DECL void ArgMax(const FDTensor &x, FDTensor *out, int64_t axis,
  99. FDDataType output_dtype = FDDataType::INT64,
  100. bool keep_dim = false, bool flatten = false);
  101. /** Execute the argmin operation for input FDTensor along given dims.
  102. @param x The input tensor.
  103. @param out The output tensor which stores the result.
  104. @param axis The axis which will be reduced.
  105. @param output_dtype The data type of output FDTensor, INT64 or INT32,
  106. default to INT64.
  107. @param keep_dim Whether to keep the reduced dims, default false.
  108. @param flatten Whether to flatten FDTensor to get the argmin index, default
  109. false.
  110. */
  111. ULTRAINFER_DECL void ArgMin(const FDTensor &x, FDTensor *out, int64_t axis,
  112. FDDataType output_dtype = FDDataType::INT64,
  113. bool keep_dim = false, bool flatten = false);
  114. } // namespace function
  115. } // namespace ultra_infer