| 86 | } |
| 87 | |
| 88 | int3 GetOffset(const SliceAttributes& attr, int src_width, int src_height, |
| 89 | int src_channels) { |
| 90 | int3 offset; |
| 91 | if (attr.strides.w > 0) { |
| 92 | offset.x = attr.starts.w; |
| 93 | } else { |
| 94 | if (attr.ends.w > 0) { |
| 95 | offset.x = attr.ends.w; |
| 96 | } else { |
| 97 | offset.x = src_width + attr.ends.w; |
| 98 | } |
| 99 | } |
| 100 | if (attr.strides.h > 0) { |
| 101 | offset.y = attr.starts.h; |
| 102 | } else { |
| 103 | if (attr.ends.h > 0) { |
| 104 | offset.y = attr.ends.h; |
| 105 | } else { |
| 106 | offset.y = src_height + attr.ends.h; |
| 107 | } |
| 108 | } |
| 109 | if (attr.strides.c > 0) { |
| 110 | offset.z = attr.starts.c; |
| 111 | } else { |
| 112 | if (attr.ends.c > 0) { |
| 113 | offset.z = attr.ends.c; |
| 114 | } else { |
| 115 | offset.z = src_channels + attr.ends.c; |
| 116 | } |
| 117 | } |
| 118 | if (Is4Alighed(attr)) { |
| 119 | offset.z /= 4; |
| 120 | } |
| 121 | return offset; |
| 122 | } |
| 123 | |
| 124 | } // namespace |
| 125 | |