Skip to content

Commit 5b243b7

Browse files
committed
Add vDSP_vsdivD
1 parent 3fa56c9 commit 5b243b7

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The package is structured as follows:
5656
- [x] `vDSP_vminD` - Element-wise minimum of two vectors
5757
- [x] `vDSP_vmaxD` - Element-wise maximum of two vectors
5858
- [x] `vDSP_vdivD` - Divide two vectors
59+
- [x] `vDSP_vsdivD` - Divide a vector by a scalar
5960
- [x] `vvpow` - Raise a vector to a power
6061
- [x] `vDSP_vclrD` - Clear a vector
6162
- [x] `vDSP_vfillD` - Fill a vector with a value

Sources/AccelerateLinux/VectorOps/VectorBasicOps.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,29 @@ public func vDSP_vdivD(
482482
}
483483
}
484484

485+
/// Calculates the double-precision element-wise division of a vector and a scalar value, using the specified stride.
486+
/// - Parameters:
487+
/// - __A: The input vector, A.
488+
/// - __IA: The distance between the elements in the input vector.
489+
/// - __B: The scalar value, B.
490+
/// - __C: The output vector, C.
491+
/// - __IC: The distance between the elements in the output vector.
492+
/// - __N: The number of elements that the function processes.
493+
public func vDSP_vsdivD(
494+
_ __A: UnsafePointer<Double>,
495+
_ __IA: vDSP_Stride,
496+
_ __B: UnsafePointer<Double>,
497+
_ __C: UnsafeMutablePointer<Double>,
498+
_ __IC: vDSP_Stride,
499+
_ __N: vDSP_Length
500+
) {
501+
var i = 0
502+
while i < __N {
503+
__C[i * __IC] = __A[i * __IA] / __B.pointee
504+
i += 1
505+
}
506+
}
507+
485508
/// Calculates the sine of each element in an array of double-precision values.
486509
/// - Parameters:
487510
/// - y: The output array, y.

Tests/AccelerateLinuxTests/VectorTests/VectorBasicOpsTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,29 @@ struct VectorBasicOpsTests {
396396
#expect(c == [10.0, 10.0, 10.0, 10.0, 10.0])
397397
}
398398

399+
@Test("vDSP_vsdivD")
400+
func vDSP_vsdivDTest() {
401+
let stride = 1
402+
let count = 5
403+
404+
let a: [Double] = [1, 2, 3, 4, 5]
405+
let b: Double = 10
406+
407+
let c = [Double](unsafeUninitializedCapacity: count) {
408+
buffer, initializedCount in
409+
410+
vDSP_vsdivD(
411+
a, stride,
412+
[b],
413+
buffer.baseAddress!, stride,
414+
vDSP_Length(count))
415+
416+
initializedCount = count
417+
}
418+
419+
#expect(c == [0.1, 0.2, 0.3, 0.4, 0.5])
420+
}
421+
399422
@Test("vvsin")
400423
func vvsinTest() {
401424
let pi = Double.pi

0 commit comments

Comments
 (0)