2019-08-28 17:20:44 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2019 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* https://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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// @author raver119@gmail.com
|
|
|
|
//
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/op_boilerplate.h>
|
2019-08-28 17:20:44 +02:00
|
|
|
#if NOT_EXCLUDED(OP_bits_hamming_distance)
|
|
|
|
|
|
|
|
#include <ops/declarable/CustomOperations.h>
|
|
|
|
#include <ops/declarable/helpers/helpers.h>
|
|
|
|
#include <ops/declarable/helpers/hamming.h>
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-08-28 17:20:44 +02:00
|
|
|
namespace ops {
|
|
|
|
CUSTOM_OP_IMPL(bits_hamming_distance, 2, 1, true, 0, 0) {
|
|
|
|
auto x = INPUT_VARIABLE(0);
|
|
|
|
auto y = INPUT_VARIABLE(1);
|
2020-03-20 06:49:28 +01:00
|
|
|
auto output = OUTPUT_NULLIFIED(0);
|
2019-08-28 17:20:44 +02:00
|
|
|
|
|
|
|
REQUIRE_TRUE(x->lengthOf() == y->lengthOf(), 0, "bits_hamming_distance: both arguments must have the same length");
|
|
|
|
REQUIRE_TRUE(x->dataType() == y->dataType(), 0, "bits_hamming_distance: both arguments must have the same data type");
|
|
|
|
|
|
|
|
helpers::hamming(block.launchContext(), *x, *y, *output);
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_SHAPE_FN(bits_hamming_distance) {
|
2020-03-02 10:49:41 +01:00
|
|
|
return SHAPELIST(ConstantShapeHelper::getInstance()->scalarShapeInfo(sd::DataType::INT64));
|
2019-08-28 17:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_TYPES(bits_hamming_distance) {
|
|
|
|
getOpDescriptor()
|
|
|
|
->setAllowedInputTypes(0, {ALL_INTS})
|
|
|
|
->setAllowedInputTypes(1, {ALL_INTS})
|
2019-09-06 07:59:05 +02:00
|
|
|
->setAllowedOutputTypes(0, {ALL_INDICES});
|
2019-08-28 17:20:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|