imglib / imglib2-algorithm

Image processing algorithms for ImgLib2
http://imglib2.net/
Other
22 stars 20 forks source link

ImgMath fixes #75

Closed acardona closed 5 years ago

acardona commented 5 years ago

Two fixes for ImgMath:

  1. A critical issue, that appears only in scripting languages that fail to find the 2-argument constructor of many functions, and instead use the varargs argument with 2 arguments. The Util.wrapMap was not ready to work with less than 3 arguments.
    1. A minor issue: lack of two static functions in ImgMath: img (to wrap a RandomAccessibleInterval) and number (to wrap a number). These two enable convenient operations like e.g. copying and image into another, and filling an image with a number.
tpietzsch commented 5 years ago

Looks fine to me.

I'm not familiar with the context here, but would it make sense to make VarargsFunction.wrapMap() actual vararg, i.e., take Object... obs instead of Object[] obs?

acardona commented 5 years ago

Thanks for looking at the code changes.

The VarargsFunction.wrapMap() has to take an Object[], because it is invoked by ABinaryFunction which itself takes a varargs, which within the code block appears as an Object[]. Otherwise, it would be passing an Object[][]. So all is fine as is, and works correctly, which is the most important.

tpietzsch commented 5 years ago

👍

tpietzsch commented 5 years ago

The VarargsFunction.wrapMap() has to take an Object[], because it is invoked by ABinaryFunction which itself takes a varargs, which within the code block appears as an Object[]. Otherwise, it would be passing an Object[][]. So all is fine as is, and works correctly, which is the most important.

Hmm, actually, did you try that???

    private static void ao( final Object... i ) {
        System.out.println( Arrays.toString( i ) );
    }

    private static void bo( final Object... i ) {
        ao( i );
    }

    public static void main( final String[] args ) {
        ao( "x", 1, 2 );
        bo( "x", 1, 2 );
    }

prints

[x, 1, 2]
[x, 1, 2]

So it looks like Object... varargs will not be re-wrapped as Object[][]

acardona commented 5 years ago

Good to know! I was for some reason convinced that's not the case.

I have some features pending for ImgMath, will test and address the varargs in the next PR.

On Nov 16, 2018, at 7:11 AM, tpietzsch notifications@github.com wrote:

The VarargsFunction.wrapMap() has to take an Object[], because it is invoked by ABinaryFunction which itself takes a varargs, which within the code block appears as an Object[]. Otherwise, it would be passing an Object[][]. So all is fine as is, and works correctly, which is the most important.

Hmm, actually, did you try that???

private static void ao( final Object... i ) { System.out.println( Arrays.toString( i ) ); }

private static void bo( final Object... i ) { ao( i ); }

public static void main( final String[] args ) { ao( "x", 1, 2 ); bo( "x", 1, 2 ); } prints

[x, 1, 2] [x, 1, 2] So it looks like Object... varargs will not be re-wrapped as Object[][]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.