2

I am trying to create an ILLogical array that selects data between upper and lower limits like this:

ILLogical ix = a > limit[0] & a < limit[1]

where a and limit are ILArray< double >. I get an ILArgumentException about "Nonscalar logical to bool conversion" asking me to see ILSettings.LogicalArrayToBoolConversion. Changing the '&' to '&&' doesn't help. Is there no way to set up a compound test resulting in an ILLogical? What are my alternatives?

RxJx
  • 61
  • 2
  • 1
    I guess one way is to combine the tests into a single test: ix = (a - limit[0]) * (limit[1] - a) > 0 – RxJx Apr 18 '17 at 17:06

1 Answers1

1

There is no (convenient) way to overload the binary logical operators as & in C# in the way required here. Also, if such way would exist it would badly act against common intuition and likely cause more confusion than convenience.

Instead use the functional interface with ILMath.and() & Co:

 ILLogical ix = ILMath.and(a > limit[0], a < limit[1]); 

See: API class documentation on and

user492238
  • 4,094
  • 1
  • 20
  • 26
  • I actually had already tried that and got the same error. That's what led me to the solution I added as a comment to my first post. – RxJx Apr 19 '17 at 21:53
  • I think the reason 'and' failed for me was that I was using the C# bindings at https://github.com/arrayfire/arrayfire-dotnet which didn't bind it. Once I added that binding 'and' did work. – RxJx Apr 20 '17 at 20:03
  • From the [online docu](http://ilnumerics.net/Opoverload.html): _The C# operators | (bitwise or) and & (bitwise and) are not applicable to ILArray. Overriding them would conflict with the || operator which is used for combining ILLogical arrays and considered more important._ – Haymo Kutschbach Apr 27 '17 at 14:50