Skip to content

Commit f4d913f

Browse files
committed
Add vDSP_vrampD
1 parent db46cc9 commit f4d913f

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The package is structured as follows:
6464
- [x] `vDSP_vclipcD` - Clip a vector to a range
6565
- [x] `vDSP_vrsumD` - Recursive sum of a vector
6666
- [x] `vDSP_vsortD` - Sort a vector
67-
- [ ] `vDSP_vrampD` - Ramp a vector
67+
- [x] `vDSP_vrampD` - Ramp a vector
6868
- [ ] `vDSP.sum` - Sum of a vector
6969
- [ ] `vDSP.add` - Add two vectors
7070
- [ ] `vDSP.subtract` - Subtract two vectors

Sources/AccelerateLinux/VectorOps/VectorBasicOps.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,27 @@ public func vDSP_vsortD(
382382
quicksort(__C, __N, __Order, p: 0, r: Int(__N - 1))
383383
}
384384

385+
/// Generates a double-precision vector with monotonically incrementing or decrementing values using an initial value and increment.
386+
/// - Parameters:
387+
/// - __A: The initial value of the ramp.
388+
/// - __B: The increment, or decrement if negative, between each generated element.
389+
/// - __C: The output vector.
390+
/// - __IC: The distance between the elements in the output vector.
391+
/// - __N: The number of elements that the function processes.
392+
public func vDSP_vrampD(
393+
_ __A: UnsafePointer<Double>,
394+
_ __B: UnsafePointer<Double>,
395+
_ __C: UnsafeMutablePointer<Double>,
396+
_ __IC: vDSP_Stride,
397+
_ __N: vDSP_Length
398+
) {
399+
var i = 0
400+
while i < __N {
401+
__C[i * __IC] = (__A.pointee + __B.pointee) * Double(i)
402+
i += 1
403+
}
404+
}
405+
385406
private func quicksort(
386407
_ vec: UnsafeMutablePointer<Double>,
387408
_ len: vDSP_Length,

Tests/AccelerateLinuxTests/VectorTests/VectorBasicOpsTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,28 @@ struct VectorBasicOpsTests {
298298

299299
#expect(a == [-23.0, 3.0, 9.0, 15.0])
300300
}
301+
302+
@Test("vDSP_vrampD")
303+
func vDSP_vrampDTest() {
304+
let n = 8
305+
let stride = 1
306+
307+
var initialValue: Double = 0
308+
var increment: Double = 1
309+
310+
let ramp = [Double](unsafeUninitializedCapacity: n) {
311+
buffer, initializedCount in
312+
313+
vDSP_vrampD(
314+
&initialValue,
315+
&increment,
316+
buffer.baseAddress!,
317+
stride,
318+
vDSP_Length(n))
319+
320+
initializedCount = n
321+
}
322+
323+
#expect(ramp == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0])
324+
}
301325
}

0 commit comments

Comments
 (0)