(3.4) dnn: fix API - explicit ctors, const methods#21429
Merged
opencv-pushbot merged 1 commit intoopencv:3.4from Jan 21, 2022
Merged
(3.4) dnn: fix API - explicit ctors, const methods#21429opencv-pushbot merged 1 commit intoopencv:3.4from
opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
This was referenced Jan 13, 2022
asmorkalov
approved these changes
Jan 17, 2022
rogday
suggested changes
Jan 17, 2022
Comment on lines
+1402
to
1410
| LayerData& getLayerData(int id) const | ||
| { | ||
| MapIdToLayerData::iterator it = layers.find(id); | ||
| MapIdToLayerData::const_iterator it = layers.find(id); | ||
|
|
||
| if (it == layers.end()) | ||
| CV_Error(Error::StsObjectNotFound, format("Layer with requested id=%d not found", id)); | ||
|
|
||
| return it->second; | ||
| return const_cast<LayerData&>(it->second); | ||
| } |
Member
There was a problem hiding this comment.
We are returning non-const reference from const method. Why do we need that?
Member
Author
There was a problem hiding this comment.
This change requires too much changes due to current.
Unfortunately LayerData is not not preserved unmodified. It is part of "graph" model and manages graph connections too.
modules/dnn/src/dnn.cpp
Outdated
| std::vector<LayerPin> pins; | ||
|
|
||
| for (int i = 0; i < layers[lid].outputBlobs.size(); i++) | ||
| for (int i = 0; i < const_cast<MapIdToLayerData&>(layers)[lid].outputBlobs.size(); i++) |
Member
There was a problem hiding this comment.
I think, we either should check that lid exists in layers, or mark layers as mutable, or don't mark this method as const. I think, the use of const_cast is unjustified here.
modules/dnn/src/dnn.cpp
Outdated
Comment on lines
3195
to
3204
| const LayerData &ld = const_cast<MapIdToLayerData&>(layers)[pin.lid]; | ||
| if ((size_t)pin.oid >= ld.outputBlobs.size()) |
Member
There was a problem hiding this comment.
If we create [pin.lid] in layers in previous line, its outputBlobs.size() is zero and the condition is true, so we can get rid of const_cast.
Member
Author
|
👍 |
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Validate: