Skip to content

[FEATURE]: Array/Vector Map and Reduce #1441

@Laxan3000

Description

@Laxan3000

Feature Description

To map (Map Node): apply an operation on every element of an array/vector and output the result for each element (input: array/vector - output: array/vector). Basically a Math Node for each element of an array/vector without having to separate all the values and joining them back.

To reduce (Reduce Node): apply an operation on the first element of the array/vector and return the calculated value for the operation of the next element, and so on (input: array/vector - output: double/integer). This node may be used to sum the entire array/vector, calculate the average, find the greater/smaller number, find the lcm/GCD, etc.

Either two separate nodes or a single node ("Array Operation Node"?).

Alternatively, an Array Map/Reduce Start/End Node (similar to Image Edit Start/End) that's an enclosed for-loop with an array input, any amount of nodes after the Map Start Node, and an Array Map/Reduce End Node that outputs [Map: the list of the whole elements after each operation was applied; Reduce: the result of the whole operations] (with the added accumulator output for the Reduce operation).

+-----------------+
|    Array Map    |
+-----------------+
|          Output [ <- array
| Operation [...] |
] Array           |
+-----------------+

+------------------+
|   Array Reduce   |
+------------------+
|           Output [ <- final value
| Operation [....] |
] Array            |
+------------------+


+-----------------------+
| Array Operation Start |
+-----------------------+
|         Array Element [
|           Accumulator [ <- only visible if Reduce
| [ ] Reduce            |
] Array                 |
+-----------------------+

+-----------------------+
|  Array Operation End  |
+-----------------------+
|                Output [ <- value if Reduce else array
] Result                |
+-----------------------+
<-- Result will be the accumulator for the next iteration -->

Steps how to use this feature

1. User places down their array/vector;
2. User places down Map/Reduce/Array Operation Node;
3. They insert their array/vector as input of that node;
4. They select which operation they would like the node to do (Map: addition/subtraction/multiplication... [same as Math node] - Reduce: sum/avg/max/min/lcm/gcd/...);
5. They take the output to whichever next node they like.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions