Added `sqrtInPlace` to ‘Arithmetic.swift’

This commit is contained in:
Vincent Esche 2019-09-24 15:40:48 +02:00
parent 3ee5748f87
commit 7f12a24c44
1 changed files with 24 additions and 0 deletions

View File

@ -702,6 +702,30 @@ public func sqrt<MI: UnsafeMemoryAccessible, MO: UnsafeMutableMemoryAccessible>(
}
}
// MARK: - Square Root: In Place
/// Elemen-wise square root.
///
/// - Warning: does not support memory stride (assumes stride is 1).
func sqrtInPlace<C: UnsafeMutableMemoryAccessible>(_ lhs: inout C) where C.Element == Float {
var elementCount: Int32 = numericCast(lhs.count)
lhs.withUnsafeMutableMemory { lm in
precondition(lm.stride == 1, "\(#function) doesn't support step values other than 1")
vvsqrtf(lm.pointer, lm.pointer, &elementCount)
}
}
/// Elemen-wise square root.
///
/// - Warning: does not support memory stride (assumes stride is 1).
func sqrtInPlace<C: UnsafeMutableMemoryAccessible>(_ lhs: inout C) where C.Element == Double {
var elementCount: Int32 = numericCast(lhs.count)
lhs.withUnsafeMutableMemory { lm in
precondition(lm.stride == 1, "\(#function) doesn't support step values other than 1")
vvsqrt(lm.pointer, lm.pointer, &elementCount)
}
}
// MARK: - Dot Product
public func dot<L: UnsafeMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: L, _ rhs: R) -> Float where L.Element == Float, R.Element == Float {