Menu

#2157 Difference in total() and reduceSum() behaviour

nextrelease
open
nobody
None
5
2019-05-13
2019-05-13
No

I have (abridged):

PoyFluxFromEq = rank-2 dataset with units.
NetPoyFluxFromEq = fltarr(PoyFluxFromEq.length())
for I in range(PoyFluxFromEq.length()):

   NetPoyFluxFromEq[I]= total(PoyFluxFromEq[I, some_rank-1_index])

or

   NetPoyFluxFromEq[I]= reduceSum(PoyFluxFromEq[I, some_rank-1_index], 0)

The version using reduceSum() transfers the units of PoyFluxFromEq to NetPoyFluxFromEq. The version using total() does not.

My understanding was that total() and reduceSum() should behave identically now.

Discussion

  • Jeremy Faden

    Jeremy Faden - 2019-05-13

    Small problem, it turns out, and that's that the total function returns a double, not a rank0 dataset with a unit. There's a "total" function which takes a second argument, the index to total over, which also handles the units and is probably the source of the confusion.

    This script demos:

    randomSeed(5334)
    ds= dataset( randn(20), units='Kg' )
    print total(ds)
    print total(ds,0)
    print reduceSum(ds,0)
    ds= dataset( randn(20,30), units='Kg' )
    while ( ds.rank()>0 ): ds= total(ds,0)
    print ds
    

    So we could make the total function return a rank 0 dataset instead of a double, but I'd want to do that over a major release (v2019b or v2020a)...

     
  • Jeremy Faden

    Jeremy Faden - 2019-05-13

    For v2019a_5, I should sweep through all the filters and see what still uses double. Once rank 0 datasets were introduced, this sort of code should have been removed, but I suspect it wasn't, and this is the last remaining one.

     
MongoDB Logo MongoDB