Skip to content

Commit

Permalink
[WIP] Histogram CPU
Browse files Browse the repository at this point in the history
Input shape part.

Signed-off-by: Piotr Rak <[email protected]>
  • Loading branch information
prak-nv committed Jan 19, 2022
1 parent 8a948ee commit efcc9e3
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 36 deletions.
60 changes: 60 additions & 0 deletions dali/operators/generic/reduce/axes_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2020-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#ifndef DALI_OPERATORS_GENERIC_REDUCE_AXIS_HELPER_H__
#define DALI_OPERATORS_GENERIC_REDUCE_AXIS_HELPER_H__

#include <vector>

#include "dali/pipeline/operator/operator.h"

namespace dali {
namespace detail {

class AxesHelper {
public:
explicit inline AxesHelper(const OpSpec &spec) {
has_axes_arg_ = spec.TryGetRepeatedArgument(axes_, "axes");
has_axis_names_arg_ = spec.TryGetArgument(axis_names_, "axis_names");
has_empty_axes_arg_ =
(has_axes_arg_ && axes_.empty()) || (has_axis_names_arg_ && axis_names_.empty());

DALI_ENFORCE(!has_axes_arg_ || !has_axis_names_arg_,
"Arguments `axes` and `axis_names` are mutually exclusive");
}

void PrepareAxes(const TensorLayout &layout, int sample_dim) {
if (has_axis_names_arg_) {
axes_ = GetDimIndices(layout, axis_names_).to_vector();
return;
}

if (!has_axes_arg_) {
axes_.resize(sample_dim);
std::iota(axes_.begin(), axes_.end(), 0);
}
}

bool has_axes_arg_;
bool has_axis_names_arg_;
bool has_empty_axes_arg_;
std::vector<int> axes_;
TensorLayout axis_names_;
};

} // namespace detail
} // namespace dali

#endif // DALI_OPERATORS_GENERIC_REDUCE_AXIS_HELPER_H__
17 changes: 17 additions & 0 deletions dali/operators/generic/reduce/histogram.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "dali/operators/generic/reduce/histogram.h"

using namespace dali::hist_detail;
Loading

0 comments on commit efcc9e3

Please sign in to comment.