MCPcopy Create free account
hub / github.com/cactus-compute/cactus / concat

Method concat

cactus/graph/graph_builder.cpp:1172–1199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1170}
1171
1172size_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
1201size_t CactusGraph::cat(const std::vector<size_t>& inputs, int axis) {
1202 if (inputs.empty()) {

Callers 15

cactus_graph_concatFunction · 0.45
forward_visionMethod · 0.45
build_attentionMethod · 0.45
build_conv1dMethod · 0.45
build_conv1dMethod · 0.45
build_gated_deltanetMethod · 0.45
build_attentionMethod · 0.45

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected