[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MultiArray.getType() vs ((Type [])obj)[ii]



Peter:

It seems to me that you should ask yourself the question whether

arraycopy(from ma into x[])
insomeloop {
        pixels[count++] = *** Some expression involving x[count] ***
}

would be faster, better than the alternative you are proposing

insomeloop{
pixels[count++] = *** Some expression involving
                       *** ma.getDouble(index)
}

Do you have some idea that the "function call overhead" of ma.getDouble(index)
is significant compared to x[ii]? Although probably true on a CRAY without
inlining, it is not clear to me that this is true in java.

In fact, I believe one could construct 2-D MultiArray implementation
where
        // int [2] index;
insomeloop {
        f(getDouble(index));
}

is faster than

insomeloop {
        f((double) x[i][j]);
}

and also faster than

insomeloop {
        f((double) x[i * dimsize + j]);
}

in java for large dimensions. (Think of an MultiArray implementation that
chunks data to lower memory page fault costs.)

Using the former method, you are assuming your input MultiArray is always
componentType double? (Unless you always cast...)

Using the getDouble() method, you've got the type you want (with clear
exception
semantics) no matter what input componentType is.

----

Having said all this, the current Netcdf Variable accessor methods
aren't very swift. We will be working on it.

-glenn