Skip to content

feat: add methods to fetch a dimension index & size according to its data format

Context

This is an implementation for issue aidge#315 (closed).

It adds the following methods:

  • For each dimension, a method to get its index according to a DataFormat
getBatchDimIdx(DataFormat::NC);   // Returns 0
getDepthDimIdx(DataFormat::NC);   // Returns 255 - A tombstone value indicating an unsupported dimension
getChannelDimIdx(DataFormat::NC); // Returns 1
  • Given a tensor and for each dimension, a method to get its index according to its DataFormat.
tensor.setDataFormat(DataFormat::NC);
tensor.getBatchDimIdx();   // It returns 0
tensor.getDepthDimIdx();   // It returns 255
tensor.getChannelDimIdx(); // It returns 1

Note

  • If format is defined, then it uses getBatchDimIdx(tensor.mDataFormat),
  • If format is undefined (Default or Any), it assumes a format according to its dimension's size.
  • Given a tensor and for each dimension, a method to get its size according to its DataFormat
Tensor tensor = Tensor({12, 22});
tensor.setDataFormat(DataFormat::NC);
tensor.getBatchDimSize();   // It returns 12
tensor.getDepthDimSize();   // It returns 1 (default for each unsupported dimensions)
tensor.getChannelDimSize(); // It returns 22

Detailed major modifications

  • Change the X-Macro signature used in those files
    • N, C, D, H, W were renamed to their corresponding labels (Batch, Channel, Depth, Height, Width)
  • Change DataFormat type to short from int
  • Added corresponding methods to DataFormat.hpp and Tensor.hpp
  • All methods are tested.
  • Python bindings node_export.py were also updated to use these functions.

Status

  • NOT DONE
  • DONE
  • TO DO
  • IN PROGRESS
Edited by Tristan de Blauwe

Merge request reports

Loading