Questions tagged [equality]

Equality is a relationship between two or more items or variables or objects that exists if (1) the items are the same item, variable, or object or (2) the items are different items, variables or objects but they have the same value. This tag should generally be used with programming language specific tags as well as other contextual tags such as database system. The post should include as much context about the equality test as is possible.

177 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10votes
1answer
4kviews

Minimization with R nloptr package - multiple equality constraints

Is it possible to specify more than one equality constraint in nloptr function in R? The code that I am trying to run is the following: eval_f <- function( x ) { return( list( "objective" = x[3]^...
user avatar
6votes
0answers
391views

How to remove duplicates in list of objects without __hash__

I have a list of custom objects from which I want to remove the duplicates. Normally, you would do this by defining both __eq__ and __hash__ for your objects and then taking the set of the list of ...
user avatar
  • 20.6k
6votes
1answer
817views

A first chance exception of type 'System.InvalidCastException' occurred in WindowsBase.dll

I'm getting this exception when binding the ItemsSource of a ListBox to an ObservableCollection<object>. The collection is populated with a mix of {DependencyPropertyChangedEventArgs, ...
user avatar
5votes
0answers
248views

Why does this type equality check fail in SBT but succeed in my IDE?

I encountered an interesting issue while writing unit tests, a particular piece of type checking Scala code succeeding when I run the tests through my IDE (IntelliJ Idea), while failing when I run ...
user avatar
5votes
0answers
127views

What's the difference between these two definitions of equality in Agda?

I installed Agda and started playing around. I tried to define an equality type and came up with the following solution: data _≡_ {A : Set} : A -> A -> Set where refl : {x : A} -> x ≡ x ...
user avatar
  • 4,852
4votes
0answers
213views

Error in Ipython module memory_profiler, %mprun

As you can see, result of the code below is unfair, because it can't be that iterator spent same time as "return" or "if y:". Why is it? How can I fix it? In some tests my code is too heavy so I ...
user avatar
4votes
0answers
123views

Any nice way to test structures (esp containing `Decimal`) for exact equality

In versions of .net prior to 4.0, if a structure contained only primitive fields, the Equals operator for the struct would only return true if all fields matched precisely. In 4.0, Microsoft changed ...
user avatar
  • 72.8k
3votes
0answers
199views

How to make records equality case-insensitive for strings?

I really like the C# 9 records. However, I can't find an elegant and concise way to accomplish somethink like this: record MyKey(string Foo, int Bar); [Fact] public void ShouldEqualIgnoreCase() { ...
user avatar
  • 390
3votes
0answers
42views

Testing Vector for equality with NAs in subscripts R

I discovered a strange behavior in R and wanted to ask whether it can lead to problems. Here is an example of what I mean: x<-c(1,2,3,4,NA, 5) x==1 x this returns: TRUE FALSE FALSE FALSE NA ...
user avatar
  • 73
3votes
0answers
65views

How can one reason about two eta equivalent agda programs with different behavior?

I'm trying to implement the sigma elimination as via the induction principle, and am not understanding why pr₂ is fine, but pr₂' is highlighting yellow with the constraint error below, as these ...
user avatar
3votes
0answers
82views

What is "unit" in MS's otherwise useful snippet HasMinimalDifference for double equality

The documentation for Double.Equals contains a useful method public static bool HasMinimalDifference(double value1, double value2, int units) { long lValue1 = BitConverter.DoubleToInt64Bits(...
user avatar
  • 2,857
3votes
0answers
111views

Seemingly identical primitive values aren't equal

A strange case popped up. Two properties of two objects are being cast to the same primitive type and (seemingly) have the same value. However, the equality comparer returns false. If we use the ...
user avatar
  • 5,011
3votes
1answer
626views

operator== in base and Equals in derived

I have a base class that is compared by reference, and a derived class that is compared by value (showing just the lines that are relevant here): class Term : IReadOnlyList<Term> public ...
user avatar
  • 28.2k
3votes
0answers
71views

How to properly override equality logic and preserve data binding capabilities

I would like to have a reference on how to correctly implement a class that satisfies following requisites: implementing a logic for equality that depends from its content, i.e. its fields proven ...
user avatar
3votes
0answers
85views

Copying XML input to output verbatim in Haskell

As per title. The application is user-written configuration files which might from time to time have to be updated in certain parts but otherwise should be unchanged. A starting point is just to be ...
user avatar
3votes
1answer
171views

What's a good hash for an object with two strings and two BOOLs?

What's a good hash for a class with two strings and two BOOLs? e.g. @interface Person : NSObject @property (nonatomic, copy) NSString *identifier; @property (nonatomic, copy) NSString *name; @...
user avatar
  • 39.1k
3votes
1answer
530views

Composition vs Inheritance for Equality & Hashcode providers

When comparing entities and aggregate roots I use an ABC, which I borrowed from Oren Eini: Generic Entity Equality. For value objects I was equally ingenious. I used Jimmy Bogard’s Value Object ABC: ...
user avatar
2votes
0answers
104views

What is the time-complexity of this equality operator between two containers?

I'm testing my understanding of complexity and want to verify my answer. I have an equality operator between two containers of the same type. My algorithm iterates over the lhs (aka this) and tests ...
user avatar
  • 6,105
2votes
0answers
256views

Idiomatic way to check if some (not all) properties of two objects equal in Kotlin

Let's assume i have a class with two instances: class Car(val id: Int, val color: Color, val pistons: Int, val spoiler: Boolean) val audi = Car(1234, Color.BLUE, 8, false) val bmw = Car(4321, Color....
user avatar
  • 955
2votes
0answers
124views

int and double equality with const in Dart

If I do final x = (2 == 2.0); Then x is true. But if I do const x = (2 == 2.0); Then x is false. I would expect both to be true based on the docs: If one operand is a double and the other is an int,...
user avatar
  • 418k
2votes
4answers
66views

Why are arrays equal to their corresponding strings?

Why is an array evaluated to true when it is compared to its corresponding string? var a = [1,2,3]; var b = '1,2,3'; console.log(a==b);// true Variable a stores the memory address of the array it ...
user avatar
2votes
0answers
44views

Explanation for nested decimals behaviour in ValueType GetHashCode/Equals implementation

I was scratching my head over an unexpected failing comparison between two instances of a custom struct. I hope someone can either point me to reference source or documentation, or confirm whether ...
user avatar
  • 2,049
2votes
0answers
217views

In Idris, how to show that a non-trivial equality is Refl?

I'm building a little dependently-typed lambda calculus interpreter: import Data.Vect %default total {- fin helper functions and lemmas -} incrFin : Fin n -> Fin (S n) -> Fin (S n) incrFin x ...
user avatar
  • 127
2votes
0answers
145views

F#: Mutually recursive type definitions with custom equality operators

I'm trying to create a set of types which should have equality defined for comparison with each-other. I got this far without a problem: [<CustomEquality; NoComparison>] type Foo = Foo of ...
user avatar
  • 55.5k
2votes
1answer
69views

Naming a set of equality equations Python

I am currently working on solving a system of equations. A subset of the equations are: eq1 = pi1 * q[0+1] == pi0 * r[0+1] eq2 = pi2 * q[0+1] == pi0 * r[1+1] + pi1 * r[1+1] eq3 = pi3 * q[0+...
user avatar
2votes
1answer
123views

Android Studio 2 comparing Object and boolean compile succeeds when it shouldn't?

I (mistakenly) wrote the following code in an Android project. for (Map<String, Object> occurrence : occurrences) { if (occurrence.get("cancelled") == true) { // don't display ...
user avatar
  • 1,614
2votes
0answers
88views

C++ Equality checking in maps from pointers

SOME_MAP<Foo*, int> map = SOME_MAP<Foo*, int>(); Foo *a = new Foo(42); Foo *b = new Foo(42); map[a] = 42; cout << map[b] << endl; // Should print 42 if *a == *b. Is there ...
user avatar
2votes
0answers
147views

Bound function object identity in Python

This bit of Python has me puzzled. class my_class(object): def f(): return 1 c = my_class() f1 = c.f f2 = c.f assert not f1 is f2 assert id(f1) != id(f2) assert f1 == f2 All three ...
user avatar
2votes
1answer
81views

Scala - Use different equality comparisons/hashing for the same type

So, in .NET, you can define implementations of IEqualityComparer and pass them to the constructor of a Dictionary or HashSet. Otherwise, the collections will look at the Equals and GetHashCode methods....
user avatar
  • 8,025
2votes
0answers
237views

C# Byte Array of lists (or dictionaries) with equal content are not equal

I have two Lists with the same content. The first one had added three items and removed one again. The second one had added only the remaining two items. Then I converted both to byte array, but the ...
user avatar
2votes
0answers
985views

isKindOfClass test in isEqual method with inheritance

I've seen many implementions of isEqual use isKindOfClass, similar to the following: - (BOOL) isEqual:(id)object { if ([object isKindOfClass:[self class]) return [self testEqualityFurther]...
user avatar
  • 1,438
1vote
0answers
9views

How can I make the code carry out a function if a variable a is equal to a string or integer?

I'm doing a simple program for practice, and I've stumbled upon a problem. I want the program to terminate if I don't get a string input, but it isn't working. if num_2 != int ...
user avatar
1vote
0answers
7views

Why are these two strings not equal and how would I make it so they are?

I'm trying to figure out why I am able to successfully find strings in my Trie when using keys assigned to Dictionary[] but when I try to create an entirely different string of the same value, I am ...
user avatar
1vote
1answer
41views

Comparing double-precision numbers that are potentially infinite

I have two double variables that can potentially be equal to Infinity. I would like to compare them and allow for a margin of error. I cannot use assertEquals due to the environment I work with. I ...
user avatar
  • 822
1vote
1answer
176views

When are Dafny sequences equal?

Hi Having defined a function that builds a sequence from a set it is easy to verify that from equal sets the function must return equal sequences. But this is not what the results look liked qr = [3,...
user avatar
1vote
0answers
19views

Swift protocol or abstract class similar to EqualityComparer<T>

Is there any Procotol or abstract class similar to EqualityComparer in Swift language? https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.equalitycomparer-1?view=netcore-3.1
user avatar
1vote
0answers
52views

How to compare specified type element of the array?

I have a extension method to judge if an item exists in the array/list. I encountered a problem that how to judge the equality between two elements if the T is an Array/List? Suppose [1, 2] and [2, ...
user avatar
1vote
1answer
92views

How to perform inner join between two dataframes based upon difference between two columns of two different data frames

I would like to merge two data frames based upon both a time period, and lat lon coordinates. I originally performed an outer product to construct distances between the two data-frames using a ...
user avatar
1vote
4answers
1kviews

How to count the equal elements of 2 different vectors in c++?

I am trying to find a way to count how many elements are equal in 2 different vectors of the same size in c++. The vectors hold structs and i want to compare the equality by a double variable of the ...
user avatar
1vote
0answers
30views

Comparing the class body in JCodeModel with the body of a .java file

I have a JCodeModel object which includes a class body, would be written to a .java file: codeModel.build(new File("src").getAbsoluteFile()); There might already be the same .java class file in the ...
user avatar
1vote
0answers
121views

Checking equality up to transpose in numpy

Given two multidimensional arrays in numpy of the same shape (in my case they are tensors where every dimension is equal, so the shape would be [2,...,2]) I would like to test whether one can be ...
user avatar
  • 501
1vote
1answer
2kviews

Pro and cons of using util.inspect for checking deep object equality

What are the pros and cons of using the inspect function in node's util module for checking deep object equality, regarding accuracy and performance? I believe it is at least more comprehensive than ...
user avatar
  • 6,009
1vote
1answer
822views

Use AutoMapper for equality testing?

Suppose I have a class. For simplicity, let's assume its fields are all strings: public class Book { public string Title {get;set;} public string Author {get;set;} } I want to define two ...
user avatar
1vote
0answers
98views

Compare all elements of two vectors for equality

I am trying a simple vector comparison between two vectors which are defined as follows: pow_2 <- sapply(1:50, function(x) 2^x) n_2 <- sapply(1:50, function(x) x^2) I now need to compute the ...
user avatar
  • 1,746
1vote
0answers
337views

linq to entities: compare string variable with NVarchar field

This code results in timeout exception String City_Code = null; var result = (from r in myContext.TableA where ( City_Code == r.City_Code ) select r ).ToList(); ...
user avatar
  • 11
1vote
2answers
114views

C#: Use unsafe code to compare a variable to default(T)

I want to test whether a variable of unknown type has been assiged a non-default value. The variable is probably a struct type, so I can't solve this with where T : class. The struct's IEquatable<...
user avatar
  • 19
1vote
0answers
41views

jQuery doesn't recognize identical textnodes (sometimes)

I wanted to use jQuery to tweak the copy-mechanism. I noticed that when the anchor and focus nodes of a selection were the same, the corresponding jQuery objects (compared using the .is method) were ...
user avatar
1vote
0answers
112views

Is there a way to stop reference equality checking in TypeScript?

Since there's no way to do operator overloading in TypeScript, is there a way I can tell the transpiler/IDE that this isn't allowed: this.vector1 == this.vector2; I have vectors which I want to be ...
user avatar
  • 19.6k
1vote
0answers
69views

UIImage equality issues – how to compare UIImage to store image data?

Both of the following return NO for me: [image isEqual:[UIImage imageWithData:UIImagePNGRepresentation(image)]]; [image isEqual:[UIImage imageWithData:UIImageJPEGRepresentation(image, 1.0f)]]; Is ...
user avatar
1vote
0answers
206views

What happen with the unreferenced objects when a object changes their reference?

By example, I have two objects: var obj1 = {x: 1, y: 2}, obj2 = {z: 3}; Internally the variables obj1 and obj2 are references to objects like this: || variable obj1 || =====> {x: 1, y: 2} ...
user avatar

15 30 50 per page