For byte piddles, one way would be to make a lookup table
and use index() to select the count. Something like this
perhaps:
pdl> $table = zeros(byte,256)
pdl> $count = sequence(byte,256)
pdl> p $count
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
250 251 252 253 254 255]
pdl> for my $shift (0..7) { $table += ( 0x01 & ($count>>$shift) ); }
pdl> p $table
[0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 4 5 1 2 2
3 2 3 3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 1 2 2 3 2 3
3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 2 3 3 4 3 4 4 5 3
4 4 5 4 5 5 6 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 1 2 2 3 2 3 3 4 2 3 3 4
3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5
6 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 3 4
4 5 4 5 5 6 4 5 5 6 5 6 6 7 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 4 5 5 6 5
6 6 7 5 6 6 7 6 7 7 8]
pdl> p $table(0xff)
[8]
pdl> p $table(0x33)
[4]
Hope this helps. BTW, if you need a more random sequence of [0,1]', you may
want to try PDL::GSL::RNG.
--Chris
On Mon, Sep 9, 2013 at 3:18 PM, mraptor <[email protected]> wrote:
> Thanks guys... that works..
>
> I can do XOR table this way :
>> p xvals(10,10)^yvals(10,10)
>
> Any idea if I can count the number of 1-bits in every element .. without
> explicit loop..
> Normally in pure perl I will do it like this :
>
> for my $n (1 .. number-of-bits ) {
> $mask = 1 << $n;
> $count ++ if $value & $mask
> }
>
> thanks
>
>
>
> On Mon, Sep 9, 2013 at 2:52 PM, Chris Marshall <[email protected]>
> wrote:
>>
>> $pdl = byte( random(100,100)>0.5 );
>>
>> PDL doesn't have bit datatypes.
>>
>> --Chris
>>
>>
>> On Mon, Sep 9, 2013 at 2:43 PM, mraptor <[email protected]> wrote:
>> > Hi,
>> >
>> > what is the best way to fill 2D pdl randomly with zeros and ones...say I
>> > have the following PDL :
>> >
>> > $pdl = pdl zeros(byte,100,100)
>> >
>> > PS> Just to be on the safe side, let me ask.. byte is the smallest type
>> > supported, there wont be by some coincidence support for something like
>> > this
>> > :
>> >
>> > $pdl = pdl zeros(bit,100,100)
>> >
>> > ;) thanks
>> >
>> > _______________________________________________
>> > Perldl mailing list
>> > [email protected]
>> > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>> >
>
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl