| 373 | } |
| 374 | |
| 375 | void Compute(OpKernelContext* ctx) override { |
| 376 | const Tensor* input_tensor; |
| 377 | srand((unsigned)time(NULL)); |
| 378 | |
| 379 | OP_REQUIRES_OK(ctx, ctx->input("input", &input_tensor)); |
| 380 | OP_REQUIRES(ctx, TensorShapeUtils::IsVector(input_tensor->shape()), |
| 381 | errors::InvalidArgument("input must be a vector, got shape: ", |
| 382 | input_tensor->shape().DebugString())); |
| 383 | |
| 384 | const auto input_vec = input_tensor->vec<string>(); |
| 385 | const int64 batch_size = input_vec.dimension(0); |
| 386 | |
| 387 | const Tensor* delimiter_tensor; |
| 388 | OP_REQUIRES_OK(ctx, ctx->input("delimiter", &delimiter_tensor)); |
| 389 | OP_REQUIRES( |
| 390 | ctx, TensorShapeUtils::IsScalar(delimiter_tensor->shape()), |
| 391 | errors::InvalidArgument("delimiter must be a scalar, got shape: ", |
| 392 | delimiter_tensor->shape().DebugString())); |
| 393 | const auto delimiter_vec = delimiter_tensor->flat<string>(); |
| 394 | const string& delimiter = delimiter_vec(0); |
| 395 | |
| 396 | uint64 start = 0; |
| 397 | uint64 end = 0; |
| 398 | |
| 399 | if (element_cost_ == 0 && batch_size) { |
| 400 | size_t sample_id = rand() % batch_size; |
| 401 | std::vector<StringPiece> temp_for_warm_up = |
| 402 | skip_empty_ ? |
| 403 | Split(input_vec(sample_id), delimiter, str_util::SkipEmpty()) |
| 404 | : Split(input_vec(sample_id), delimiter, str_util::AllowEmpty()); |
| 405 | start = Env::Default()->NowNanos(); |
| 406 | temp_for_warm_up = |
| 407 | skip_empty_ ? |
| 408 | Split(input_vec(sample_id), delimiter, str_util::SkipEmpty()) |
| 409 | : Split(input_vec(sample_id), delimiter, str_util::AllowEmpty()); |
| 410 | end = Env::Default()->NowNanos(); |
| 411 | element_cost_ = end - start; |
| 412 | } |
| 413 | uint64 element_cost = element_cost_; |
| 414 | |
| 415 | if (element_cost * batch_size >= parallel_limit_) { |
| 416 | ParallelSplit(ctx, input_vec, batch_size, delimiter); |
| 417 | } else { |
| 418 | SequentialSplit(ctx, input_vec, batch_size, delimiter); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | private: |
| 423 | bool skip_empty_; |
nothing calls this directly
no test coverage detected