-
Notifications
You must be signed in to change notification settings - Fork 2
SplitLayer #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's leave as is
include/layers/SplitLayer.hpp
Outdated
| private: | ||
| int axis_; | ||
| std::vector<int> splits_; | ||
| int num_outputs_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| int num_outputs_ = 0; | |
| int num_outputs_; |
src/layers/SplitLayer.cpp
Outdated
| } | ||
|
|
||
| int SplitLayer::get_normalized_axis(int rank) const { | ||
| if (axis_ < 0) return axis_ + rank; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still can have underflow. For example: axis = -5, rank = 2
src/layers/SplitLayer.cpp
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.