| 23 | |
| 24 | template <typename T, typename Context> |
| 25 | void CrossKernel(const Context& dev_ctx, |
| 26 | const DenseTensor& x, |
| 27 | const DenseTensor& y, |
| 28 | int axis, |
| 29 | DenseTensor* out) { |
| 30 | auto& input_x = x; |
| 31 | auto& input_y = y; |
| 32 | auto* output = out; |
| 33 | int dim = axis; |
| 34 | |
| 35 | auto input_x_dims = input_x.dims(); |
| 36 | |
| 37 | if (dim != DDim::kMaxRank) { |
| 38 | PADDLE_ENFORCE_EQ( |
| 39 | dim < input_x_dims.size() && dim >= (0 - input_x_dims.size()), |
| 40 | true, |
| 41 | common::errors::OutOfRange( |
| 42 | "Attr(dim) is out of range, It's expected " |
| 43 | "to be in range of [-%d, %d]. But received Attr(dim) = %d.", |
| 44 | input_x_dims.size(), |
| 45 | input_x_dims.size() - 1, |
| 46 | dim)); |
| 47 | if (dim < 0) { |
| 48 | dim += input_x_dims.size(); |
| 49 | } |
| 50 | |
| 51 | PADDLE_ENFORCE_EQ( |
| 52 | input_x_dims[dim] == 3, |
| 53 | true, |
| 54 | common::errors::InvalidArgument( |
| 55 | "Input(X/Y).dims[dim] must be equal to 3. But received: " |
| 56 | "Input(X/Y).dims[dim] = [%d].", |
| 57 | input_x_dims[dim])); |
| 58 | } else { |
| 59 | for (auto i = 0; i < input_x_dims.size(); i++) { |
| 60 | if (input_x_dims[i] == 3) { |
| 61 | dim = i; |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | PADDLE_ENFORCE_EQ(dim == DDim::kMaxRank, |
| 66 | false, |
| 67 | common::errors::InvalidArgument( |
| 68 | "There must be at least one dimension 'd' so that " |
| 69 | "Input(X/Y).dims()[d] is equal to 3. " |
| 70 | "But received: Input(X/Y).dims() == [%s].", |
| 71 | input_x_dims)); |
| 72 | } |
| 73 | if (input_x.numel() == 0 || input_y.numel() == 0) { |
| 74 | output->Resize(input_x.dims()); |
| 75 | dev_ctx.template Alloc<T>(output); |
| 76 | return; |
| 77 | } |
| 78 | int64_t outer_loops = 1; |
| 79 | for (auto i = 0; i < dim; i++) { |
| 80 | outer_loops *= input_x_dims[i]; |
| 81 | } |
| 82 | int64_t slice_size = 1; |
nothing calls this directly
no test coverage detected