Hi Ted, I used assertions to be consistent with the rest of HPPC (there are no explicit parameter validation checks unless you ask for them using -ea). I think tests should always run with -ea and having two versions of accessor methods misses the point (either you want those validation checks and run with -ea or you don't want them and skip assertions entirely). I consider HPPC a low-level library, so I assume whoever decides to use it knows how to run the JVM with assertions enabled... but I also agree that for larger audience explicit ifs/throws may be a better choice to capture problems earlier in the development process.
The difference in speed may be marginal since newer hardware/hotspot will predict those branches almost never take place and probably discard them. Dawid On Fri, Mar 25, 2011 at 5:47 PM, Ted Dunning <[email protected]> wrote: > Dawid, > > This is impressive and there have definitely been times that this would > have helped. > > Can you say more about why you used assert's for checking bounds instead of > having quick accessors without checks and normal > accessors with checks (that hopefully will get inlined and lifted)? > > The problem I have with assert is that it doesn't normally have any effect. > > > On Fri, Mar 25, 2011 at 7:36 AM, Dawid Weiss <[email protected] > > wrote: > >> Hi guys, >> >> This is not directly related to Mahout, but since most of you deal with >> computations, I think it is relevant and I seek feedback/ improvement >> ideas. >> If you've ever had to create a large array (or worse: multidimensional >> array) of a relatively simple structure-like data holder class then you >> probably know the pain of initializing sub-arrays and the memory overhead >> that jagged arrays incur. The idea to generate stub code to handle such >> cases has been around my head for a long time, but I finally managed to >> find >> some time and implement it. I really like the results so far, especially >> in >> multidimensional case the code is so much nicer. Even if you have a >> relatively simple array of byte[][] you can do this: >> >> @Struct(dimensions = 2) >> public final class Byte { >> public byte value; >> } >> >> this will generate stub class ByteArray2D (if javac has access to >> apt-processor in hppc-struct, that is; or if your maven project is >> configured properly, see hppc-examples for how to do this) with a single >> byte[] field and flattened Byte objects, including accessors to individual >> fields or valuetype-copying methods for handling entire structures. More >> is >> here: >> >> http://issues.carrot2.org/browse/HPPC-54 >> >> And a trivial sample here: >> >> >> https://github.com/carrotsearch/hppc/blob/master/hppc-examples/src/main/java/com/carrotsearch/hppc/examples/StructExample.java >> >> Again, if you have any ideas/ improvements, they are most welcome (use >> JIRA >> above for comments or fork the code on github). >> >> Dawid >> > >
