Skip to content
Snippets Groups Projects

InputCategory as bitwise flag and Better handle inputs

Merged Charles Villard requested to merge silvanosky/aidge_core:features/filter_input_nodes into dev

Context

Often optional input are treated as required inputs and this contribution make the InputCategory as a bitwise filter to ease filtering of needed inputs without altering the api.

Modified files

  • include/aidge/graph/GraphView.hpp
  • src/graph/GraphView.cpp
  • include/aidge/graph/Node.hpp
  • src/graph/Node.cpp
  • include/aidge/operator/Operator.hpp
  • include/aidge/utils/BitwiseUtils.hpp - Added

PyBind :

  • python_binding/graph/pybind_GraphView.cpp
  • python_binding/operator/pybind_Operator.cpp
  • python_binding/pybind_core.cpp

Detailed major modifications

  1. New optional (by default old behavior) filter parameter for std::set<std::shared_ptr<Aidge::Node>> Aidge::GraphView::inputNodes(InputCategory filter)
  2. enum class InputCategory is now an unsigned int object class allowing bitwise operations
  3. getNbFreeDataInputs() now return only Data and DataOptional inputs
  4. addChild now add the first available free data instead of the first data
Edited by Maxence Naud

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
252 252 if ((inputCategory(i) == InputCategory::Data || inputCategory(i) == InputCategory::OptionalData)
  • So if I understand, this condition could be changed to:

    Suggested change
    252 if ((inputCategory(i) == InputCategory::Data || inputCategory(i) == InputCategory::OptionalData)
    252 if ((inputCategory(i) && InputCategory::Data)
  • Almost, we need to cast to underlying type of the enum object and then bitwise comparison & instead of && :

    Suggested change
    Applied
    252 if ((inputCategory(i) == InputCategory::Data || inputCategory(i) == InputCategory::OptionalData)
    252 if (to_underlying(inputCategory(i) & InputCategory::Data))
  • changed this line in version 9 of the diff

  • I am not sure that is is what you do because you do not close the parenthesis after inputCategory(i), instead you convert the entire line inputCategory(i) & InputCategory::Data

  • Actually, inputCategory(i) & InputCategory::Data returns an enum, so to_underlying(inputCategory(i) & InputCategory::Data)) returns an unsigned int that can only be interpreted as an InputCategory enum

    It should not be use as a condition. Moreover since the new InputCategory enum class has no value 0 this condition would always be true

    Edited by Maxence Naud
  • I am not sure to understand, the underlying type doesn't need to be mapped to all possible constants, so 0 is a valid value.

    I kept InputCategory as an enum class instead of original c enum which is only a syntax sugar for the underlying type where enum class is an object, so you cannot directly do bitwise operation on a class.

    inputCategory(i) & InputCategory::Data return an enum object encapsulating the result of underlying bitwise operation & from (!370 (diffs))

    Then the unsigned int is used as a condition validation as 0 is false, and any other value is true. This allows to check if the InputCategory::Data (0b10 bit is set in inputCategory(i)).

    For example:

    • Optional Data have a value of 0b11 so 0b11 & 0b10 = 0b10 which is true.
    • Optional Param have a value of 0b101 so 0b101 & 0b10 = 0b00 which is false.
    Edited by Charles Villard
  • Please register or sign in to reply
  • Maxence Naud unapproved this merge request

    unapproved this merge request

  • Charles Villard resolved all threads

    resolved all threads

  • added 1 commit

    • 11fba35a - Change old data check to new bitwise filter

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading