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

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

This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.


  • Subject: MultiArray.getType() vs ((Type [])obj)[ii]
  • Date: Tue, 3 Mar 1998 11:15:05 -0700

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