Menu

#160 apply() function built-in for elementwise operation

None
closed
nobody
None
3
2023-12-13
2021-08-29
No

Taken from the devel mailing list in July 2021. Quoting Artur:
"An element could be a row, column or an item in some array. ... In principle, this is similar to Pandas's apply function: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html"

Jack remarked: "having something that help avoiding explicit loops sounds very good to me."

Related

Feature Requests: #126

Discussion

  • Sven Schreiber

    Sven Schreiber - 2023-01-04

    A cheap idea: If it were possible for a user-written hansl function to accept an unspecified "array" as an argument type (and also as return value...), then it should be fairly easy to have this in hansl. The function maybe would not even have to check whether it is getting matrices, strings, or whatever. This would be somehow similar to the generic "numeric" argument type.
    Something like this:
    <pseudo-hansl></pseudo-hansl>

    function array apply_elementwise (string funcname, const array A, const bundle args[null])
        # prepare the included arguments for string substitution
        # args members must be labeled "arg1", "arg2" etc., as per the needed ordering
        #  of positional arguments for <funcname> (or any other sortable way) 
        # And the type of those (ordered) arguments must conform to what is expected by <funcname>.
    
        string argstring = exists(args) ? ",args." ~ flatten(sort(getkeys(args)), ",args.") : ""
    
        out = A # a copy, automatically right sub-type
        loop i = 1..nelem(A)
          out[i] = feval(funcname, A[i] @argstring)  
       endloop
        return out
      end function
    

     
  • Artur Tarassow

    Artur Tarassow - 2023-01-05
    • Group: -->
    • Priority: 5 --> 1
     
  • Artur Tarassow

    Artur Tarassow - 2023-01-05
    • summary: apply() function built-in for elementwise operation --> PRIO1 : apply() function built-in for elementwise operation
     
  • Artur Tarassow

    Artur Tarassow - 2023-01-05
    • labels: --> foo
     
  • Artur Tarassow

    Artur Tarassow - 2023-01-05
    • labels: foo -->
    • summary: PRIO1 : apply() function built-in for elementwise operation --> apply() function built-in for elementwise operation
     
  • Artur Tarassow

    Artur Tarassow - 2023-01-05
    • labels: --> Prio1
     
  • Sven Schreiber

    Sven Schreiber - 2023-02-01
    • labels: Prio1 -->
    • Priority: 1 --> 3
     
  • Sven Schreiber

    Sven Schreiber - 2023-02-01

    We discussed that this is nice to have, but not top priority.

     
  • Sven Schreiber

    Sven Schreiber - 2023-10-04

    It was discussed again; getting this done in a reasonably efficient way (not just calling the same function many times in an internal loop) appears to be not so easy. Also, in the meantime more hansl functions have been enabled to work on arrays element-wise. So it's not so clear anymore whether this should be pursued.

     
  • Sven Schreiber

    Sven Schreiber - 2023-12-13
    • status: open --> closed
     
  • Sven Schreiber

    Sven Schreiber - 2023-12-13

    OK, we said that the cost-benefit relation is not good enough, and writing an explicit hansl loop is not so bad these days anyway. So we're closing this.

     

Log in to post a comment.

MongoDB Logo MongoDB