简体   繁体   中英

Bitwise operations on Armadillo vectors

I need to do bitwise operations between two vectors. I dont want to use loops. I am using Armadillo. Could anyone help me with this?

Edit:

By vector I mean a vector template provided by Armadillo library. Something like this:

urowvec newvec1 = zeros < urowvec >(5);

urowvec newvec2 = ones < urowvec >(5);

urowvec newvec3 = newvec1 | newvec2;

But this gives me error with armadillo.

Thanks

If you implement this:

inline urowvec operator|(const urowvec& lhs, urowvec& rhs){
  // ToDo - operate on an element by element basis, and return
  // a urowvec. Decide on something reasonable if the vectors
  // differ in size.
}

and make sure this is included in every compilation unit requiring the operator, then urowvec newvec3 = newvec1 | newvec2; urowvec newvec3 = newvec1 | newvec2; will be valid.

You can do the same thing for the other bitwise operators.

Any reasonable compiler will elide the value copy.

to do bitwise operations use the bitwise operators

 |   bitwise or
 &   bitwise and
 ^   bitwise xor
 ~   bitwise not
<<  bitwise shift left
>>  bitwise shift right

if you gave a more specific question you might get a more specific answer. By vector do you mean a std::vector, is it a vector of ints? or do you mean an array of bits?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM