0001 http://mattt.me)
0023 import Accelerate
0024
0025
0027 public func abs(x: [Double]) -> [Double] {
0028 var results = [Double](count: x.count, repeatedValue: 0.0)
0029 vvfabs(&results, x, [Int32(x.count)])
0030
0031 return results
0032 }
0033
0034 public func abs(x: [Float]) -> [Float] {
0035 var results = [Float](count: x.count, repeatedValue: 0.0)
0036 vvfabsf(&results, x, [Int32(x.count)])
0037
0038 return results
0039 }
0040
0041
0043 public func ceil(x: [Float]) -> [Float] {
0044 var results = [Float](count: x.count, repeatedValue: 0.0)
0045 vvceilf(&results, x, [Int32(x.count)])
0046
0047 return results
0048 }
0049
0050 public func ceil(x: [Double]) -> [Double] {
0051 var results = [Double](count: x.count, repeatedValue: 0.0)
0052 vvceil(&results, x, [Int32(x.count)])
0053
0054 return results
0055 }
0056
0057
0059 public func clip(x: [Float], low: Float, high: Float) -> [Float] {
0060 var results = [Float](count: x.count, repeatedValue: 0.0), y = low, z = high
0061 vDSP_vclip(x, 1, &y, &z, &results, 1, vDSP_Length(x.count))
0062
0063 return results
0064 }
0065
0066 public func clip(x: [Double], low: Double, high: Double) -> [Double] {
0067 var results = [Double](count: x.count, repeatedValue: 0.0), y = low, z = high
0068 vDSP_vclipD(x, 1, &y, &z, &results, 1, vDSP_Length(x.count))
0069
0070 return results
0071 }
0072
0073
0075 public func copysign(sign: [Float], magnitude: [Float]) -> [Float] {
0076 var results = [Float](count: sign.count, repeatedValue: 0.0)
0077 vvcopysignf(&results, magnitude, sign, [Int32(sign.count)])
0078
0079 return results
0080 }
0081
0082 public func copysign(sign: [Double], magnitude: [Double]) -> [Double] {
0083 var results = [Double](count: sign.count, repeatedValue: 0.0)
0084 vvcopysign(&results, magnitude, sign, [Int32(sign.count)])
0085
0086 return results
0087 }
0088
0089
0091 public func floor(x: [Float]) -> [Float] {
0092 var results = [Float](count: x.count, repeatedValue: 0.0)
0093 vvfloorf(&results, x, [Int32(x.count)])
0094
0095 return results
0096 }
0097
0098 public func floor(x: [Double]) -> [Double] {
0099 var results = [Double](count: x.count, repeatedValue: 0.0)
0100 vvfloor(&results, x, [Int32(x.count)])
0101
0102 return results
0103 }
0104
0105
0107 public func neg(x: [Float]) -> [Float] {
0108 var results = [Float](count: x.count, repeatedValue: 0.0)
0109 vDSP_vneg(x, 1, &results, 1, vDSP_Length(x.count))
0110
0111 return results
0112 }
0113
0114 public func neg(x: [Double]) -> [Double] {
0115 var results = [Double](count: x.count, repeatedValue: 0.0)
0116 vDSP_vnegD(x, 1, &results, 1, vDSP_Length(x.count))
0117
0118 return results
0119 }
0120
0121
0123 public func rec(x: [Float]) -> [Float] {
0124 var results = [Float](count: x.count, repeatedValue: 0.0)
0125 vvrecf(&results, x, [Int32(x.count)])
0126
0127 return results
0128 }
0129
0130 public func rec(x: [Double]) -> [Double] {
0131 var results = [Double](count: x.count, repeatedValue: 0.0)
0132 vvrec(&results, x, [Int32(x.count)])
0133
0134 return results
0135 }
0136
0137
0139 public func round(x: [Float]) -> [Float] {
0140 var results = [Float](count: x.count, repeatedValue: 0.0)
0141 vvnintf(&results, x, [Int32(x.count)])
0142
0143 return results
0144 }
0145
0146 public func round(x: [Double]) -> [Double] {
0147 var results = [Double](count: x.count, repeatedValue: 0.0)
0148 vvnint(&results, x, [Int32(x.count)])
0149
0150 return results
0151 }
0152
0153
0155 public func threshold(x: [Float], low: Float) -> [Float] {
0156 var results = [Float](count: x.count, repeatedValue: 0.0), y = low
0157 vDSP_vthr(x, 1, &y, &results, 1, vDSP_Length(x.count))
0158
0159 return results
0160 }
0161
0162 public func threshold(x: [Double], low: Double) -> [Double] {
0163 var results = [Double](count: x.count, repeatedValue: 0.0), y = low
0164 vDSP_vthrD(x, 1, &y, &results, 1, vDSP_Length(x.count))
0165
0166 return results
0167 }
0168
0169
0171 public func trunc(x: [Float]) -> [Float] {
0172 var results = [Float](count: x.count, repeatedValue: 0.0)
0173 vvintf(&results, x, [Int32(x.count)])
0174
0175 return results
0176 }
0177
0178 public func trunc(x: [Double]) -> [Double] {
0179 var results = [Double](count: x.count, repeatedValue: 0.0)
0180 vvint(&results, x, [Int32(x.count)])
0181
0182 return results
0183 }
0184