research/seq_flow_lite/tflite_ops/layer_norm.cc
// Performs sanity checks on input axis and resolves into valid dimensions.
Performs sanity checks on input axis and resolves into valid dimensions.
Performs sanity checks on input axis and resolves into valid dimensions .
inline bool ResolveAxis(const int num_dims, const int* axis, const int num_axis,
                        int* out_axis, int* out_num_axis) {
  *out_num_axis = 0;
  if (num_dims == 0) {
    return true;
  }
  std::unordered_set<int> unique_indices;
  for (int64_t idx = 0; idx < num_axis; ++idx) {
    int current = axis[idx] < 0 ? (axis[idx] + num_dims) : axis[idx];
    assert(current >= 0 && current < num_dims);
    if (unique_indices.find(current) == unique_indices.end()) {
      unique_indices.insert(current);
      out_axis[*out_num_axis] = current;
      *out_num_axis += 1;
    }
  }
  return true;
}
inline bool ResolveAxis ( const int num_dims , const int * axis , const int num_axis , int * out_axis , int * out_num_axis ) { * out_num_axis = 0 ; if ( num_dims == 0 ) { return true ; } std :: unordered_set < int > unique_indices ; for ( int64_t idx = 0 ; idx < num_axis ; ++ idx ) { int current = axis [ idx ] < 0 ? ( axis [ idx ] + num_dims ) : axis [ idx ] ; assert ( current >= 0 && current < num_dims ) ; if ( unique_indices . find ( current ) == unique_indices . end ( ) ) { unique_indices . insert ( current ) ; out_axis [ * out_num_axis ] = current ; * out_num_axis += 1 ; } } return true ; }
Performs sanity checks on input axis and resolves into valid dimensions.
Performs sanity checks on input axis and resolves into valid dimensions .
// Short-circuit axis resolution for scalars; the axis will go unused. // Using an unordered set to reduce complexity in looking up duplicates. // Handle negative index. // Only adding the axis if it wasn't added before.