Skip to content

Commit 490b0ff

Browse files
committed
Add Equality directory for Equatable extensions
1 parent 744f91f commit 490b0ff

5 files changed

Lines changed: 39 additions & 29 deletions

File tree

Sources/Numerix/Core/Matrix.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,6 @@ extension Matrix: ExpressibleByArrayLiteral {
139139
}
140140
}
141141

142-
extension Matrix: Equatable {
143-
144-
/// Compare two matrices for equality.
145-
/// - Parameters:
146-
/// - lhs: The first matrix.
147-
/// - rhs: The second matrix.
148-
/// - Returns: True if both matrices are same dimension and contain the same values.
149-
public static func == (lhs: Matrix, rhs: Matrix) -> Bool {
150-
let n = lhs.buffer.count
151-
let cmp = memcmp(lhs.buffer.baseAddress, rhs.buffer.baseAddress, MemoryLayout<Scalar>.size * n)
152-
let buffersEqual = cmp == 0 ? true : false
153-
return lhs.rows == rhs.rows && lhs.columns == rhs.columns && buffersEqual
154-
}
155-
}
156-
157142
extension Matrix: Sequence, IteratorProtocol {
158143

159144
public mutating func next() -> [Scalar]? {

Sources/Numerix/Core/Vector.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,3 @@ extension Vector: ExpressibleByArrayLiteral {
8585
self.init(elements)
8686
}
8787
}
88-
89-
extension Vector: Equatable {
90-
91-
/// Compare two vectors for equality.
92-
/// - Parameters:
93-
/// - lhs: Left-hand side vector.
94-
/// - rhs: Right-hand side vector.
95-
/// - Returns: True if both vectors are same size and contain the same values.
96-
public static func == (lhs: Vector, rhs: Vector) -> Bool {
97-
let cmp = memcmp(lhs.buffer.baseAddress, rhs.buffer.baseAddress, MemoryLayout<Scalar>.size * lhs.size)
98-
let buffersEqual = cmp == 0 ? true : false
99-
return lhs.size == rhs.size && buffersEqual
100-
}
101-
}
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Matrix extension to conform to Equatable protocol.
3+
*/
4+
5+
import Accelerate
6+
7+
extension Matrix: Equatable {
8+
9+
/// Compare two matrices for equality.
10+
/// - Parameters:
11+
/// - lhs: The first matrix.
12+
/// - rhs: The second matrix.
13+
/// - Returns: True if both matrices are same dimension and contain the same values.
14+
public static func == (lhs: Matrix, rhs: Matrix) -> Bool {
15+
let n = lhs.buffer.count
16+
let cmp = memcmp(lhs.buffer.baseAddress, rhs.buffer.baseAddress, MemoryLayout<Scalar>.size * n)
17+
let buffersEqual = cmp == 0 ? true : false
18+
return lhs.rows == rhs.rows && lhs.columns == rhs.columns && buffersEqual
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Vector extension to conform to Equatable protocol.
3+
*/
4+
5+
import Accelerate
6+
7+
extension Vector: Equatable {
8+
9+
/// Compare two vectors for equality.
10+
/// - Parameters:
11+
/// - lhs: Left-hand side vector.
12+
/// - rhs: Right-hand side vector.
13+
/// - Returns: True if both vectors are same size and contain the same values.
14+
public static func == (lhs: Vector, rhs: Vector) -> Bool {
15+
let cmp = memcmp(lhs.buffer.baseAddress, rhs.buffer.baseAddress, MemoryLayout<Scalar>.size * lhs.size)
16+
let buffersEqual = cmp == 0 ? true : false
17+
return lhs.size == rhs.size && buffersEqual
18+
}
19+
}

0 commit comments

Comments
 (0)