ExpandDims.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #define LOG_TAG "Operations"
  17. #include "ExpandDims.h"
  18. #include "Utils.h"
  19. namespace android {
  20. namespace nn {
  21. namespace expand_dims {
  22. bool prepare(const Shape& input, int32_t axis, Shape* output) {
  23. NN_CHECK(handleNegativeAxis(getNumberOfDimensions(input) + 1, &axis));
  24. output->type = input.type;
  25. output->offset = input.offset;
  26. output->scale = input.scale;
  27. output->dimensions.assign(input.dimensions.begin(), input.dimensions.end());
  28. output->dimensions.insert(output->dimensions.begin() + axis, 1);
  29. return true;
  30. }
  31. bool eval(const uint8_t* inputData, const Shape& inputShape, int32_t axis, uint8_t* outputData,
  32. const Shape& outputShape) {
  33. memcpy(outputData, inputData,
  34. nonExtensionOperandSizeOfData(inputShape.type, inputShape.dimensions));
  35. return true;
  36. }
  37. } // namespace expand_dims
  38. } // namespace nn
  39. } // namespace android