| 1170 | } |
| 1171 | |
| 1172 | size_t CactusGraph::concat(size_t input1, size_t input2, int axis) { |
| 1173 | const auto& buffer1 = get_output_buffer(input1); |
| 1174 | const auto& buffer2 = get_output_buffer(input2); |
| 1175 | |
| 1176 | if (buffer1.shape.size() != buffer2.shape.size()) { |
| 1177 | throw std::runtime_error("Concat requires inputs with same number of dimensions"); |
| 1178 | } |
| 1179 | |
| 1180 | std::vector<size_t> output_shape = buffer1.shape; |
| 1181 | size_t ndims = output_shape.size(); |
| 1182 | |
| 1183 | if (axis < 0) axis += ndims; |
| 1184 | if (axis < 0 || static_cast<size_t>(axis) >= ndims) { |
| 1185 | throw std::runtime_error("Invalid axis for concat operation"); |
| 1186 | } |
| 1187 | |
| 1188 | for (size_t i = 0; i < ndims; ++i) { |
| 1189 | if (i != static_cast<size_t>(axis) && buffer1.shape[i] != buffer2.shape[i]) { |
| 1190 | throw std::runtime_error("Concat inputs must have same shape except on concat axis"); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | output_shape[axis] = buffer1.shape[axis] + buffer2.shape[axis]; |
| 1195 | |
| 1196 | OpParams params; |
| 1197 | params.axis = axis; |
| 1198 | return add_node(OpType::CONCAT, {input1, input2}, output_shape, params); |
| 1199 | } |
| 1200 | |
| 1201 | size_t CactusGraph::cat(const std::vector<size_t>& inputs, int axis) { |
| 1202 | if (inputs.empty()) { |
no test coverage detected