Skip to content

Conversation

@joey12300
Copy link
Collaborator

@joey12300 joey12300 commented Aug 8, 2022

PR types

New features

PR changes

APIs

Describe

  1. Add 7 reduce functions for FDTensor: Max, Min, Sum, All, Any, Mean, Prod
  2. Add cpp unittests for 7 reduce functions.
  3. Add pull request template

Usage

FDTensor input, output;
std::vector<int> inputs = {2, 4, 3, 7, 1, 5};
input.SetExternalData({2, 3}, FDDataType::INT32, inputs.data());

// Calculate the max value for axis 0 of `inputs`
// The output result would be [[7, 4, 5]]
Max(input, &output, {0}, /* keep_dim = */true);

// Calculate the min value for axis 0 of `inputs`
// The output result would be [[2, 1, 3]]
Min(input, &output, {0}, true);

// Calculate the sum value for axis 0 of `inputs`
// The output result would be [[9, 5, 8]]
Sum(input, &output, {0}, true);

// Calculate the mean value for axis 0 of `inputs`
// The output result would be [[4, 2, 4]]
Mean(input, &output, {0}, true);

// Calculate the product value for axis 0 of `inputs`
// The output result would be [[14, 4, 15]]
Prod(input, &output, {0}, true);

std::array<bool, 6> bool_inputs = {false, false, true, true, false, true};
input.SetExternalData({2, 3}, FDDataType::BOOL, bool_inputs.data());

// Calculate the any value for axis 0 of `inputs`
// The output result would be [[true, false, true]]
Any(input, &output, {0}, true);

// Calculate the any value for axis 0 of `inputs`
// The output result would be [[false, false, true]]
All(input, &output, {0}, true);

@joey12300 joey12300 changed the title [WIP] Add math function for FDTensor Add reduce functions for FDTensor Aug 9, 2022
@joey12300 joey12300 marked this pull request as ready for review August 9, 2022 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants