Skip to content

Commit d6bf48c

Browse files
committed
Remove core graphics usage
1 parent 9e8b18d commit d6bf48c

8 files changed

Lines changed: 108 additions & 26 deletions

File tree

Sources/Matft/core/object/mfdata.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ public class MfData: MfDataProtocol{
105105

106106
if let data_imag_ptr = data_imag_ptr{
107107
self.data_imag = allocate_unsafeMRPtr(type: Float.self, count: storedSize)
108-
memcpy(self.data_imag, data_imag_ptr, self.storedByteSize)
108+
memcpy(self.data_imag!, data_imag_ptr, self.storedByteSize)
109109
}
110110
else{
111111
self.data_imag = nil
112112
}
113113
case .Double:
114114
self.data_real = allocate_unsafeMRPtr(type: Double.self, count: storedSize)
115115
memcpy(self.data_real, data_real_ptr, self.storedByteSize)
116-
116+
117117
if let data_imag_ptr = data_imag_ptr{
118118
self.data_imag = allocate_unsafeMRPtr(type: Double.self, count: storedSize)
119-
memcpy(self.data_imag, data_imag_ptr, self.storedByteSize)
119+
memcpy(self.data_imag!, data_imag_ptr, self.storedByteSize)
120120
}
121121
else{
122122
self.data_imag = nil

Sources/Matft/core/util/common/order.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal func copy_all_mfarray(_ src_mfarray: MfArray) -> MfArray{
3535
srcptr in
3636
dst_mfarray.withUnsafeMutableStartImagPointer(datatype: Float.self){
3737
dstptr in
38-
memcpy(dstptr, srcptr, MemoryLayout<Float>.size*newsize)
38+
memcpy(dstptr!, srcptr, MemoryLayout<Float>.size*newsize)
3939
}
4040
}
4141
}
@@ -52,7 +52,7 @@ internal func copy_all_mfarray(_ src_mfarray: MfArray) -> MfArray{
5252
srcptr in
5353
dst_mfarray.withUnsafeMutableStartImagPointer(datatype: Double.self){
5454
dstptr in
55-
memcpy(dstptr, srcptr, MemoryLayout<Double>.size*newsize)
55+
memcpy(dstptr!, srcptr, MemoryLayout<Double>.size*newsize)
5656
}
5757
}
5858
}

Sources/Matft/function/method/conversion+method.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//
88

99
import Foundation
10+
#if canImport(CoreML)
1011
import CoreML
12+
#endif
1113

1214
extension MfArray{
1315
/**
@@ -112,6 +114,7 @@ extension MfArray{
112114
}
113115

114116

117+
#if canImport(CoreML)
115118
/// Convert MfArray to MLMultiArray
116119
/// - Returns: Converted MLMultiArray
117120
@available(macOS 12.0, *)
@@ -128,6 +131,7 @@ extension MfArray{
128131
return try MLMultiArray(dataPointer: ptrD, shape: self.shape.map{ NSNumber(value: $0) } , dataType: MLMultiArrayDataType.double, strides: self.strides.map{ NSNumber(value: $0) }, deallocator: _deallocator_MLMultiArray_pointer)
129132
}
130133
}
134+
#endif
131135

132136
/**
133137
Create broadcasted mfarray.
@@ -276,6 +280,8 @@ extension MfArray{
276280
}
277281
}
278282

283+
#if canImport(CoreML)
279284
fileprivate func _deallocator_MLMultiArray_pointer(_ ptr: UnsafeMutableRawPointer) -> Void {
280285
ptr.deallocate()
281286
}
287+
#endif

Sources/Matft/function/static/biop+static.swift

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ extension Matft{
3131
}
3232
}
3333
else{
34+
#if canImport(Accelerate)
3435
switch MfType.storedType(rettype){
3536
case .Float:
3637
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvadd)
3738
case .Double:
3839
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvaddD)
3940
}
41+
#else
42+
fatalError("Complex array operations are not supported on this platform")
43+
#endif
4044
}
4145
}
42-
46+
4347
/**
4448
Element-wise addition of mfarray and scalar
4549
- parameters:
@@ -64,12 +68,16 @@ extension Matft{
6468
}
6569
}
6670
else{
71+
#if canImport(Accelerate)
6772
switch MfType.storedType(retmftype) {
6873
case .Float:
6974
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvadd)
7075
case .Double:
7176
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvaddD)
7277
}
78+
#else
79+
fatalError("Complex array operations are not supported on this platform")
80+
#endif
7381
}
7482
}
7583
/**
@@ -96,12 +104,16 @@ extension Matft{
96104
}
97105
}
98106
else{
107+
#if canImport(Accelerate)
99108
switch MfType.storedType(retmftype) {
100109
case .Float:
101110
return biopzvs_by_vDSP(r_mfarray, Float.from(l_scalar), vDSP_zrvadd)
102111
case .Double:
103112
return biopzvs_by_vDSP(r_mfarray, Double.from(l_scalar), vDSP_zrvaddD)
104113
}
114+
#else
115+
fatalError("Complex array operations are not supported on this platform")
116+
#endif
105117
}
106118
}
107119
/**
@@ -122,12 +134,16 @@ extension Matft{
122134
}
123135
}
124136
else{
137+
#if canImport(Accelerate)
125138
switch MfType.storedType(rettype){
126139
case .Float:
127140
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvsub)
128141
case .Double:
129142
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvsubD)
130143
}
144+
#else
145+
fatalError("Complex array operations are not supported on this platform")
146+
#endif
131147
}
132148
}
133149
/**
@@ -154,12 +170,16 @@ extension Matft{
154170
}
155171
}
156172
else{
173+
#if canImport(Accelerate)
157174
switch MfType.storedType(retmftype) {
158175
case .Float:
159176
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvsub)
160177
case .Double:
161178
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvsubD)
162179
}
180+
#else
181+
fatalError("Complex array operations are not supported on this platform")
182+
#endif
163183
}
164184
}
165185
/**
@@ -186,12 +206,16 @@ extension Matft{
186206
}
187207
}
188208
else{
209+
#if canImport(Accelerate)
189210
switch MfType.storedType(retmftype) {
190211
case .Float:
191212
return biopzvs_by_vDSP(-r_mfarray, Float.from(l_scalar), vDSP_zrvadd)
192213
case .Double:
193214
return biopzvs_by_vDSP(-r_mfarray, Double.from(l_scalar), vDSP_zrvaddD)
194215
}
216+
#else
217+
fatalError("Complex array operations are not supported on this platform")
218+
#endif
195219
}
196220
}
197221
/**
@@ -212,12 +236,16 @@ extension Matft{
212236
}
213237
}
214238
else{
239+
#if canImport(Accelerate)
215240
switch MfType.storedType(rettype){
216241
case .Float:
217242
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvmul_)
218243
case .Double:
219244
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvmulD_)
220245
}
246+
#else
247+
fatalError("Complex array operations are not supported on this platform")
248+
#endif
221249
}
222250
}
223251
/**
@@ -244,12 +272,16 @@ extension Matft{
244272
}
245273
}
246274
else{
275+
#if canImport(Accelerate)
247276
switch MfType.storedType(retmftype) {
248277
case .Float:
249278
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvmul)
250279
case .Double:
251280
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvmulD)
252281
}
282+
#else
283+
fatalError("Complex array operations are not supported on this platform")
284+
#endif
253285
}
254286
}
255287
/**
@@ -276,12 +308,16 @@ extension Matft{
276308
}
277309
}
278310
else{
311+
#if canImport(Accelerate)
279312
switch MfType.storedType(retmftype) {
280313
case .Float:
281314
return biopzvs_by_vDSP(r_mfarray, Float.from(l_scalar), vDSP_zrvmul)
282315
case .Double:
283316
return biopzvs_by_vDSP(r_mfarray, Double.from(l_scalar), vDSP_zrvmulD)
284317
}
318+
#else
319+
fatalError("Complex array operations are not supported on this platform")
320+
#endif
285321
}
286322
}
287323
/**
@@ -304,12 +340,16 @@ extension Matft{
304340
}
305341
}
306342
else{
343+
#if canImport(Accelerate)
307344
switch MfType.storedType(rettype){
308345
case .Float:
309346
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvdiv)
310347
case .Double:
311348
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvdivD)
312349
}
350+
#else
351+
fatalError("Complex array operations are not supported on this platform")
352+
#endif
313353
}
314354
}
315355
/**
@@ -336,12 +376,16 @@ extension Matft{
336376
}
337377
}
338378
else{
379+
#if canImport(Accelerate)
339380
switch MfType.storedType(retmftype) {
340381
case .Float:
341382
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvdiv)
342383
case .Double:
343384
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvdivD)
344385
}
386+
#else
387+
fatalError("Complex array operations are not supported on this platform")
388+
#endif
345389
}
346390
}
347391
/**
@@ -368,12 +412,16 @@ extension Matft{
368412
}
369413
}
370414
else{
415+
#if canImport(Accelerate)
371416
switch MfType.storedType(retmftype) {
372417
case .Float:
373418
return biopzsv_by_vDSP(Float.from(l_scalar), r_mfarray, vDSP_ztrans)
374419
case .Double:
375420
return biopzsv_by_vDSP(Double.from(l_scalar), r_mfarray, vDSP_ztransD)
376421
}
422+
#else
423+
fatalError("Complex array operations are not supported on this platform")
424+
#endif
377425
}
378426
}
379427

Sources/Matft/function/static/complex+static.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import Foundation
99
#if canImport(Accelerate)
1010
import Accelerate
11-
#endif
1211

1312
extension Matft.complex{
14-
13+
1514
/**
1615
Return the angle of the complex argument
1716
- parameters:
@@ -25,7 +24,7 @@ extension Matft.complex{
2524
else{
2625
src_mfarray = mfarray
2726
}
28-
27+
2928
switch src_mfarray.storedType{
3029
case .Float:
3130
let ret = z2r_by_vDSP(src_mfarray, vDSP_zvphas)
@@ -37,7 +36,7 @@ extension Matft.complex{
3736
return ret
3837
}
3938
}
40-
39+
4140
/**
4241
Return the conjugate of the complex mfarray
4342
- parameters:
@@ -47,15 +46,15 @@ extension Matft.complex{
4746
if mfarray.isReal{
4847
return mfarray.deepcopy(.Row)
4948
}
50-
49+
5150
switch mfarray.storedType{
5251
case .Float:
5352
return conjugate_by_vDSP(mfarray, vDSP_zvconj)
5453
case .Double:
5554
return conjugate_by_vDSP(mfarray, vDSP_zvconjD)
5655
}
5756
}
58-
57+
5958
/**
6059
Complex absolute
6160
- parameters:
@@ -65,7 +64,7 @@ extension Matft.complex{
6564
if mfarray.isReal{
6665
return Matft.math.abs(mfarray)
6766
}
68-
67+
6968
switch mfarray.storedType{
7069
case .Float:
7170
let ret = z2r_by_vDSP(mfarray, vDSP_zvabs)
@@ -77,7 +76,7 @@ extension Matft.complex{
7776
return ret
7877
}
7978
}
80-
79+
8180
/**
8281
Complex absolute and argument
8382
- parameters:
@@ -92,10 +91,11 @@ extension Matft.complex{
9291
return (Matft.math.abs(mfarray), Matft.nums_like(Double.zero, mfarray: mfarray))
9392
}
9493
}
95-
94+
9695
return (Matft.complex.abs(mfarray), Matft.complex.angle(mfarray))
9796
}
9897
}
98+
#endif
9999

100100
/// Check it is real or not. if the mfarray is complex, raise precondition failure.
101101
/// - Parameters:

0 commit comments

Comments
 (0)