| 241 | |
| 242 | template <typename FunctionType, typename ExecType> |
| 243 | void CheckAddDispatch(FunctionType* func, ExecType exec) { |
| 244 | using KernelType = typename FunctionType::KernelType; |
| 245 | |
| 246 | ASSERT_EQ(0, func->num_kernels()); |
| 247 | ASSERT_EQ(0, func->kernels().size()); |
| 248 | |
| 249 | std::vector<InputType> in_types1 = {int32(), int32()}; |
| 250 | OutputType out_type1 = int32(); |
| 251 | |
| 252 | ASSERT_OK(func->AddKernel(in_types1, out_type1, exec)); |
| 253 | ASSERT_OK(func->AddKernel({int32(), int8()}, int32(), exec)); |
| 254 | |
| 255 | // Duplicate sig is okay |
| 256 | ASSERT_OK(func->AddKernel(in_types1, out_type1, exec)); |
| 257 | |
| 258 | // Add a kernel |
| 259 | KernelType kernel({float64(), float64()}, float64(), exec); |
| 260 | ASSERT_OK(func->AddKernel(kernel)); |
| 261 | |
| 262 | ASSERT_EQ(4, func->num_kernels()); |
| 263 | ASSERT_EQ(4, func->kernels().size()); |
| 264 | |
| 265 | // Try adding some invalid kernels |
| 266 | ASSERT_RAISES(Invalid, func->AddKernel({}, int32(), exec)); |
| 267 | ASSERT_RAISES(Invalid, func->AddKernel({int32()}, int32(), exec)); |
| 268 | ASSERT_RAISES(Invalid, func->AddKernel({int8(), int8(), int8()}, int32(), exec)); |
| 269 | |
| 270 | // Add valid and invalid kernel using kernel struct directly |
| 271 | KernelType valid_kernel({boolean(), boolean()}, boolean(), exec); |
| 272 | ASSERT_OK(func->AddKernel(valid_kernel)); |
| 273 | |
| 274 | KernelType invalid_kernel({boolean()}, boolean(), exec); |
| 275 | ASSERT_RAISES(Invalid, func->AddKernel(invalid_kernel)); |
| 276 | |
| 277 | ASSERT_OK_AND_ASSIGN(const Kernel* dispatched, func->DispatchExact({int32(), int32()})); |
| 278 | KernelSignature expected_sig(in_types1, out_type1); |
| 279 | ASSERT_TRUE(dispatched->signature->Equals(expected_sig)); |
| 280 | |
| 281 | // No kernel available |
| 282 | ASSERT_RAISES(NotImplemented, func->DispatchExact({utf8(), utf8()})); |
| 283 | |
| 284 | // Wrong arity |
| 285 | ASSERT_RAISES(Invalid, func->DispatchExact({})); |
| 286 | ASSERT_RAISES(Invalid, func->DispatchExact({int32(), int32(), int32()})); |
| 287 | } |
| 288 | |
| 289 | TEST(ScalarVectorFunction, DispatchExact) { |
| 290 | ScalarFunction func1("scalar_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty()); |
no test coverage detected