Skip to content

Commit 34113d1

Browse files
authored
Merge pull request #21339 from DougGregor/simd-custom-string-convertible
[SIMD] Add CustomDebugStringConvertible conformance for SIMD types.
2 parents 2bc5623 + fbf4bb7 commit 34113d1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stdlib/public/core/SIMDVectorTypes.swift.gyb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public extension SIMD${n} where Scalar : FixedWidthInteger {
109109
}
110110
}
111111

112+
extension SIMD${n} : CustomDebugStringConvertible {
113+
/// Debug string representation
114+
public var debugDescription: String {
115+
return "SIMD${n}<\(Scalar.self)>(${', '.join(map(lambda c:
116+
'\\(self['+ str(c) + '])',
117+
xrange(n)))})"
118+
}
119+
}
112120

113121
public extension SIMD${n} where Scalar : BinaryFloatingPoint {
114122
@inlinable

test/stdlib/simd.swift.gyb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,10 @@ simdTestSuite.test("matrix elements") {
313313
% end # for type
314314
}
315315

316+
simdTestSuite.test("debug description") {
317+
expectEqual("SIMD2<Float>(1.0, 2.5)",
318+
SIMD2<Float>(1.0, 2.5).debugDescription)
319+
}
320+
316321
runAllTests()
317322

0 commit comments

Comments
 (0)