Re: float[][] vs double[][] in VisAD file form


It looks like the binary option promotes to double, and the serial
option forces float?


Curtis Rueden wrote:


I was using Java serialization to save some FlatFields to a disk
cache file. I decided to switch this logic over to the VisADForm
binary writer. I noticed that the size of the FlatFields on disk
doubled with this scheme.

These FlatFields were populated with setSamples(float[][], boolean).
I did some experiments with VisADForm in serialization vs binary
mode, and with float[][] vs double[][], and I'm confused.

Below is my test program. And here is the output:

C:\java\test>java BinaryFieldSizeTest
Float files should be ~400000 bytes.
Double files should be ~800000 bytes.

C:\java\test>ls -l *.vad
-rw-r--r--    1 root     None       800271 Jul 21 16:58 binary-double.vad
-rw-r--r--    1 root     None       800271 Jul 21 16:58 binary-float.vad
-rw-r--r--    1 root     None       403626 Jul 21 16:58 serial-double.vad
-rw-r--r--    1 root     None       403626 Jul 21 16:58 serial-float.vad

It doesn't seem to matter if the FlatField has double[][] samples
or float[][] samples. And the binary version is twice as large as
the serialized version. In particular, it is disconcerting that
the "serial-double.vad" is twice as small as it should be.

Is something wrong with my code? Or is this behavior a bug? Is
there an easy way around the problem? Is there an easy fix that
could be applied to the VisADForm writer?



import visad.*;

public class BinaryFieldSizeTest {

 public static void main(String[] args) throws Exception {
   int cx = 500;
   int cy = 200;
   int count = cx * cy;
   double[][] sampsD = new double[1][count];
   float[][] sampsF = new float[1][count];
   for (int i=0; i<count; i++) {
     sampsD[0][i] = count * Math.random();
     sampsF[0][i] = (float) sampsD[0][i];

   RealType x = RealType.getRealType("x");
   RealType y = RealType.getRealType("y");
   RealTupleType xy = new RealTupleType(x, y);
   RealType value = RealType.getRealType("value");
   FunctionType ftype = new FunctionType(xy, value);
   Integer2DSet fset = new Integer2DSet(xy, cx, cy);

   FlatField fieldD = new FlatField(ftype, fset);
   fieldD.setSamples(sampsD, false);

   FlatField fieldF = new FlatField(ftype, fset);
   fieldF.setSamples(sampsF, false);

   VisADForm binaryD = new VisADForm(true);"binary-double.vad", fieldD, true);

   VisADForm serialD = new VisADForm(false);"serial-double.vad", fieldD, true);

   VisADForm binaryF = new VisADForm(true);"binary-float.vad", fieldF, true);

   VisADForm serialF = new VisADForm(false);"serial-float.vad", fieldF, true);

   int sizeF = 4 * count;
   System.out.println("Float files should be ~" + sizeF + " bytes.");

   int sizeD = 8 * count;
   System.out.println("Double files should be ~" + sizeD + " bytes.");


  • 2004 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: