Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array comparison #853

Closed
JeffBezanson opened this issue May 19, 2012 · 6 comments
Closed

array comparison #853

JeffBezanson opened this issue May 19, 2012 · 6 comments
Labels
breaking This change will break code
Milestone

Comments

@JeffBezanson
Copy link
Member

At this point most of us want .== for elementwise comparison. There are many reasons for this. Forming boolean arrays is often unnecessary and inefficient. More importantly, in mathematics when equality is extended to matrices it is still boolean, i.e. A=I denotes that A is everywhere equal to the identity matrix; it does not denote another matrix (of booleans).

== should be extended to containers by giving true iff it is true for all parts. This handles nested arrays, etc. with no problem.

A.==B should be equivalent to map(==, A, B). That way it always gives a container of booleans, and still uses == for all comparisons.

.< can be defined for arrays in the same way, but I'm not sure whether < should be.

@ViralBShah
Copy link
Member

As per IRC discussion

We will have == and != doing all() by default and giving a boolean. All other operations such as <, <=, >, >= remain undefined for arrays.

@pao
Copy link
Member

pao commented May 21, 2012

And the dotted operators will be array-of-booleans as Jeff proposes above? Sounds good to me.

@StefanKarpinski
Copy link
Member

Yep. That's the plan. It's tempting to define A < B to mean all(A .< B) but faster too, but maybe dangerous.

JeffBezanson added a commit that referenced this issue May 22, 2012
implemented for Array and DArray
@JeffBezanson
Copy link
Member Author

In progress on the array_comparison branch: https://github.com/JuliaLang/julia/tree/array_comparison

Other library maintainers @ViralBShah @carlobaldassi please update your array implementations.

Everybody else please try to find comparisons that need to be changed.

@carlobaldassi
Copy link
Member

The bitarray comparisons are now fixed in the array_comparison branch.
The sparse comparisons work already, via the AbstractArray version, but they could be optimized. It may also make sense to return a sparse matrix of Bools in some cases (e.g. when doing A .!= B with A and B sparse matrices the result is likely to be sparse), but not in others (e.g. A .== B). I'm not sure it's a good idea though: on one hand, it doesn't seem to break any convention; on the other hand, having .== and .!= return different types seems a bit weird.

@JeffBezanson
Copy link
Member Author

Branch merged by 3040405.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code
Projects
None yet
Development

No branches or pull requests

5 participants