SplitLayer#192
Conversation
| size_t outer_size = 1; | ||
| for (int i = 0; i < axis; ++i) { | ||
| outer_size *= shape[i]; | ||
| } | ||
|
|
||
| size_t inner_size = 1; | ||
| for (size_t i = axis + 1; i < shape.dims(); ++i) { | ||
| inner_size *= shape[i]; | ||
| } |
There was a problem hiding this comment.
Consider using std::accumulate
size_t outer_size = std::accumulate(
shape.begin(), shape.begin() + axis,
static_cast<size_t>(1), std::multiplies<size_t>());
size_t inner_size = std::accumulate(
shape.begin() + axis + 1, shape.end(),
static_cast<size_t>(1), std::multiplies<size_t>());
There was a problem hiding this comment.
we do not have access to the vector<size_t> dims_ inside the Shape class, as it is a private field. and therefore we cannot use iterators
| private: | ||
| int axis_; | ||
| std::vector<int> splits_; | ||
| int num_outputs_ = 0; |
There was a problem hiding this comment.
| int num_outputs_ = 0; | |
| int num_outputs_; |
| } | ||
|
|
||
| int SplitLayer::get_normalized_axis(int rank) const { | ||
| if (axis_ < 0) return axis_ + rank; |
There was a problem hiding this comment.
This still can have underflow. For example: axis = -5, rank = 2
| const auto& part_sizes = | ||
| splits_.empty() | ||
| ? std::vector<int>(num_outputs_, | ||
| static_cast<int>(shape[axis]) / num_outputs_) | ||
| : splits_; |
There was a problem hiding this comment.
this is for the ability to split into equal parts if splits_ are not specified
| #include "layers/Tensor.hpp" | ||
|
|
||
| using namespace it_lab_ai; | ||
|
|
There was a problem hiding this comment.
Please, add negative axis tests
|
Use block copies where memory is contiguous. For each output slice at fixed outer/part, the data region is contiguous (output_axis_size * inner_size elements). Replace the inner element-wise loops with a single std::copy_n (or memcpy when types allow). This will significantly reduce overhead on larger tensors. |
|
Make the mode explicit. splits_ vs num_outputs_ are mutually exclusive. Consider: |
|
Tests to add |
|
Behavior when num_outputs_ > size_along_axis is undefined. |
No description provided.