Skip to content

Instantly share code, notes, and snippets.

@gab1one
Created June 27, 2018 08:39
Show Gist options
  • Save gab1one/06f9d4de1810965d87b111612c12d277 to your computer and use it in GitHub Desktop.
Save gab1one/06f9d4de1810965d87b111612c12d277 to your computer and use it in GitHub Desktop.
package net.imglib2.img.array;
import static org.junit.Assert.assertEquals;
import java.util.Random;
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess;
import net.imglib2.img.basictypeaccess.array.LongArray;
import net.imglib2.type.logic.BitType;
import org.junit.Test;
public class ArrayImgOversizeTest
{
@Test
public void testOverSizedBitImage()
{
final ArrayImgFactory< BitType > factory = new ArrayImgFactory<>( new BitType() );
final int numLongs = ( int ) Math.ceil( 1000 * 1000 / 64 );
// ArrayImg< BitType, ? > img = factory.create( 1000, 1000 );
// ArrayImg< BitType, LongArray > img = ArrayImgs.bits( 1000, 1000 );
final ArrayImg< BitType, LongArray > img = ArrayImgs.bits( new LongArray( new long[ numLongs ] ), 1000, 1000 );
final Random r = new Random( 42l );
img.forEach( p -> {
p.set( r.nextBoolean() );
} );
final long[] storage = ( long[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray();
final long[] sizes = new long[ img.numDimensions() ];
img.dimensions( sizes );
assertEquals( storage.length, numLongs );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment