digitalmars.D.learn - std.bitmanip - bitshift?
- Trollgeir (4/4) Dec 12 2014 http://dlang.org/phobos/std_bitmanip.html
- Steven Schveighoffer (5/9) Dec 12 2014 That is a surprising omission from a bit-oriented type...
- H. S. Teoh via Digitalmars-d-learn (9/21) Dec 12 2014 [...]
- Steven Schveighoffer (13/31) Dec 12 2014 0110
- H. S. Teoh via Digitalmars-d-learn (7/7) Dec 12 2014 Here's my implementation of <<= and >>= for BitArray:
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (8/41) Dec 13 2014 There's a dedicated >>> operator for unsigned right shift, the
- Steven Schveighoffer (11/28) Dec 15 2014 But BitArray is not signed, it's an array of bits, none of which are
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (5/43) Dec 15 2014 Yes, yebblies pointed that out in the PR. I was confused, because
http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits as they have various lengths.
Dec 12 2014
On 12/12/14 8:39 AM, Trollgeir wrote:http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits as they have various lengths.That is a surprising omission from a bit-oriented type... You also cannot opSlice a BitArray. Nice for enhancement requests, if you want to add them to the issue tracker. -Steve
Dec 12 2014
On Fri, Dec 12, 2014 at 11:13:38AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:On 12/12/14 8:39 AM, Trollgeir wrote:[...] I've started working on an implementation of this... but it's not very clear what the correct semantics should be. For example, if my starting BitArray b is 1101, say, what should be the result after b>>=1? Should it be 0110, 110, or 01101? T -- It is widely believed that reinventing the wheel is a waste of time; but I disagree: without wheel reinventers, we would be still be stuck with wooden horse-cart wheels.http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits as they have various lengths.That is a surprising omission from a bit-oriented type... You also cannot opSlice a BitArray. Nice for enhancement requests, if you want to add them to the issue tracker.
Dec 12 2014
On 12/12/14 2:17 PM, H. S. Teoh via Digitalmars-d-learn wrote:On Fri, Dec 12, 2014 at 11:13:38AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:0110 In other words, I would assume the same semantics as an unsigned int. In other other words, it's like each bit moves one to the right, and the bit that has no source gets a 0. It may be useful to add some other functions, such as roll, which would move bits that fall off the end back onto the top. And maybe expose shift as a function, which allows you to specify the bit value (or maybe range of bits) that should be shifted in from the other side. Note, I would not allow just opBinary, only opBinaryAssign. No reason to construct temporary BitArrays. -SteveOn 12/12/14 8:39 AM, Trollgeir wrote:[...] I've started working on an implementation of this... but it's not very clear what the correct semantics should be. For example, if my starting BitArray b is 1101, say, what should be the result after b>>=1? Should it be 0110, 110, or 01101?http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits as they have various lengths.That is a surprising omission from a bit-oriented type... You also cannot opSlice a BitArray. Nice for enhancement requests, if you want to add them to the issue tracker.
Dec 12 2014
Here's my implementation of <<= and >>= for BitArray: https://github.com/D-Programming-Language/phobos/pull/2797 While working with the code, I found that there are a lot of areas that need improvement. If I have some time I'll file separate PR's for them. T -- VI = Visual Irritation
Dec 12 2014
On Friday, 12 December 2014 at 19:35:26 UTC, Steven Schveighoffer wrote:On 12/12/14 2:17 PM, H. S. Teoh via Digitalmars-d-learn wrote:There's a dedicated >>> operator for unsigned right shift, the normal >> operator does a signed right shift, i.e. it copies the left-most bit: http://dlang.org/expression#ShiftExpression IMO, for consistency, bitarray should behave the same.On Fri, Dec 12, 2014 at 11:13:38AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:0110 In other words, I would assume the same semantics as an unsigned int. In other other words, it's like each bit moves one to the right, and the bit that has no source gets a 0.On 12/12/14 8:39 AM, Trollgeir wrote:[...] I've started working on an implementation of this... but it's not very clear what the correct semantics should be. For example, if my starting BitArray b is 1101, say, what should be the result after b>>=1? Should it be 0110, 110, or 01101?http://dlang.org/phobos/std_bitmanip.html Does anyone know how to bit-shift a BitArray? I'm trying to make spikes in a neural network travel along the bits as they have various lengths.That is a surprising omission from a bit-oriented type... You also cannot opSlice a BitArray. Nice for enhancement requests, if you want to add them to the issue tracker.It may be useful to add some other functions, such as roll, which would move bits that fall off the end back onto the top.Yes, that would be useful.
Dec 13 2014
On 12/13/14 5:47 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net>" wrote:On Friday, 12 December 2014 at 19:35:26 UTC, Steven Schveighoffer wrote:But BitArray is not signed, it's an array of bits, none of which are signed or designated as the sign bit. The unsigned shift operator is only for signed integral types, for unsigned values >> is simply a shift of bits. Note that your assertion that >> "copies the left-most bit" is not in the text, and is incorrect. It copies the sign bit, which doesn't exist in an unsigned type. I think >> and >>> should do the same thing, and be unsigned shifts on BitArray. -SteveOn 12/12/14 2:17 PM, H. S. Teoh via Digitalmars-d-learn wrote:There's a dedicated >>> operator for unsigned right shift, the normal >> operator does a signed right shift, i.e. it copies the left-most bit: http://dlang.org/expression#ShiftExpression IMO, for consistency, bitarray should behave the same.I've started working on an implementation of this... but it's not very clear what the correct semantics should be. For example, if my starting BitArray b is 1101, say, what should be the result after b>>=1? Should it be 0110, 110, or 01101?0110 In other words, I would assume the same semantics as an unsigned int. In other other words, it's like each bit moves one to the right, and the bit that has no source gets a 0.
Dec 15 2014
On Monday, 15 December 2014 at 15:19:25 UTC, Steven Schveighoffer wrote:On 12/13/14 5:47 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net>" wrote:Yes, yebblies pointed that out in the PR. I was confused, because the documentation doesn't say that `>>` and `>>>` only behave differently for signed integers.On Friday, 12 December 2014 at 19:35:26 UTC, Steven Schveighoffer wrote:But BitArray is not signed, it's an array of bits, none of which are signed or designated as the sign bit. The unsigned shift operator is only for signed integral types, for unsigned values >> is simply a shift of bits. Note that your assertion that >> "copies the left-most bit" is not in the text, and is incorrect. It copies the sign bit, which doesn't exist in an unsigned type. I think >> and >>> should do the same thing, and be unsigned shifts on BitArray.On 12/12/14 2:17 PM, H. S. Teoh via Digitalmars-d-learn wrote:There's a dedicated >>> operator for unsigned right shift, the normal >> operator does a signed right shift, i.e. it copies the left-most bit: http://dlang.org/expression#ShiftExpression IMO, for consistency, bitarray should behave the same.I've started working on an implementation of this... but it's not very clear what the correct semantics should be. For example, if my starting BitArray b is 1101, say, what should be the result after b>>=1? Should it be 0110, 110, or 01101?0110 In other words, I would assume the same semantics as an unsigned int. In other other words, it's like each bit moves one to the right, and the bit that has no source gets a 0.
Dec 15 2014