Files
2026-07-13 12:47:05 +08:00

73 lines
2.2 KiB
C++

/* ******************************************************************************
*
*
* 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.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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
*/
#ifndef DEV_TESTS_BROADCASTSCALARCONVERTER_H
#define DEV_TESTS_BROADCASTSCALARCONVERTER_H
#include <system/op_boilerplate.h>
#include <system/op_enums.h>
#include <stdexcept>
namespace sd {
inline bool isConvertibleToScalar(broadcast::Ops op) {
int opNum = (int)op;
if (opNum <= 17) return true;
return false;
}
inline scalar::Ops convertToScalar(broadcast::Ops op) {
switch (op) {
case broadcast::Add:
return scalar::Add;
case broadcast::Subtract:
return scalar::Subtract;
case broadcast::Multiply:
return scalar::Multiply;
case broadcast::Divide:
return scalar::Divide;
case broadcast::ReverseDivide:
return scalar::ReverseDivide;
case broadcast::ReverseSubtract:
return scalar::ReverseSubtract;
case broadcast::CopyPws:
return scalar::CopyPws;
case broadcast::Pow:
return scalar::Pow;
case broadcast::MinPairwise:
return scalar::MinPairwise;
case broadcast::MaxPairwise:
return scalar::MaxPairwise;
case broadcast::AMinPairwise:
return scalar::AMinPairwise;
case broadcast::AMaxPairwise:
return scalar::AMaxPairwise;
case broadcast::SquaredSubtract:
return scalar::SquaredSubtract;
default:
THROW_EXCEPTION("Not convertible operation");
}
}
} // namespace sd
#endif // DEV_TESTS_BROADCASTSCALARCONVERTER_H