Skip to content

Commit c1787d7

Browse files
committed
Add fallback implementations with fatal errors until we are able to implement this part
1 parent bda0fe7 commit c1787d7

3 files changed

Lines changed: 567 additions & 2 deletions

File tree

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//
88

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

1214
extension Matft{
1315
//infix
@@ -29,15 +31,19 @@ extension Matft{
2931
}
3032
}
3133
else{
34+
#if canImport(Accelerate)
3235
switch MfType.storedType(rettype){
3336
case .Float:
3437
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvadd)
3538
case .Double:
3639
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvaddD)
3740
}
41+
#else
42+
fatalError("Complex array operations are not supported on this platform")
43+
#endif
3844
}
3945
}
40-
46+
4147
/**
4248
Element-wise addition of mfarray and scalar
4349
- parameters:
@@ -62,12 +68,16 @@ extension Matft{
6268
}
6369
}
6470
else{
71+
#if canImport(Accelerate)
6572
switch MfType.storedType(retmftype) {
6673
case .Float:
6774
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvadd)
6875
case .Double:
6976
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvaddD)
7077
}
78+
#else
79+
fatalError("Complex array operations are not supported on this platform")
80+
#endif
7181
}
7282
}
7383
/**
@@ -94,12 +104,16 @@ extension Matft{
94104
}
95105
}
96106
else{
107+
#if canImport(Accelerate)
97108
switch MfType.storedType(retmftype) {
98109
case .Float:
99110
return biopzvs_by_vDSP(r_mfarray, Float.from(l_scalar), vDSP_zrvadd)
100111
case .Double:
101112
return biopzvs_by_vDSP(r_mfarray, Double.from(l_scalar), vDSP_zrvaddD)
102113
}
114+
#else
115+
fatalError("Complex array operations are not supported on this platform")
116+
#endif
103117
}
104118
}
105119
/**
@@ -120,12 +134,16 @@ extension Matft{
120134
}
121135
}
122136
else{
137+
#if canImport(Accelerate)
123138
switch MfType.storedType(rettype){
124139
case .Float:
125140
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvsub)
126141
case .Double:
127142
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvsubD)
128143
}
144+
#else
145+
fatalError("Complex array operations are not supported on this platform")
146+
#endif
129147
}
130148
}
131149
/**
@@ -152,12 +170,16 @@ extension Matft{
152170
}
153171
}
154172
else{
173+
#if canImport(Accelerate)
155174
switch MfType.storedType(retmftype) {
156175
case .Float:
157176
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvsub)
158177
case .Double:
159178
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvsubD)
160179
}
180+
#else
181+
fatalError("Complex array operations are not supported on this platform")
182+
#endif
161183
}
162184
}
163185
/**
@@ -184,12 +206,16 @@ extension Matft{
184206
}
185207
}
186208
else{
209+
#if canImport(Accelerate)
187210
switch MfType.storedType(retmftype) {
188211
case .Float:
189212
return biopzvs_by_vDSP(-r_mfarray, Float.from(l_scalar), vDSP_zrvadd)
190213
case .Double:
191214
return biopzvs_by_vDSP(-r_mfarray, Double.from(l_scalar), vDSP_zrvaddD)
192215
}
216+
#else
217+
fatalError("Complex array operations are not supported on this platform")
218+
#endif
193219
}
194220
}
195221
/**
@@ -210,12 +236,16 @@ extension Matft{
210236
}
211237
}
212238
else{
239+
#if canImport(Accelerate)
213240
switch MfType.storedType(rettype){
214241
case .Float:
215242
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvmul_)
216243
case .Double:
217244
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvmulD_)
218245
}
246+
#else
247+
fatalError("Complex array operations are not supported on this platform")
248+
#endif
219249
}
220250
}
221251
/**
@@ -242,12 +272,16 @@ extension Matft{
242272
}
243273
}
244274
else{
275+
#if canImport(Accelerate)
245276
switch MfType.storedType(retmftype) {
246277
case .Float:
247278
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvmul)
248279
case .Double:
249280
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvmulD)
250281
}
282+
#else
283+
fatalError("Complex array operations are not supported on this platform")
284+
#endif
251285
}
252286
}
253287
/**
@@ -274,12 +308,16 @@ extension Matft{
274308
}
275309
}
276310
else{
311+
#if canImport(Accelerate)
277312
switch MfType.storedType(retmftype) {
278313
case .Float:
279314
return biopzvs_by_vDSP(r_mfarray, Float.from(l_scalar), vDSP_zrvmul)
280315
case .Double:
281316
return biopzvs_by_vDSP(r_mfarray, Double.from(l_scalar), vDSP_zrvmulD)
282317
}
318+
#else
319+
fatalError("Complex array operations are not supported on this platform")
320+
#endif
283321
}
284322
}
285323
/**
@@ -302,12 +340,16 @@ extension Matft{
302340
}
303341
}
304342
else{
343+
#if canImport(Accelerate)
305344
switch MfType.storedType(rettype){
306345
case .Float:
307346
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvdiv)
308347
case .Double:
309348
return biopzvv_by_vDSP(l_mfarray, r_mfarray, vDSP_func: vDSP_zvdivD)
310349
}
350+
#else
351+
fatalError("Complex array operations are not supported on this platform")
352+
#endif
311353
}
312354
}
313355
/**
@@ -334,12 +376,16 @@ extension Matft{
334376
}
335377
}
336378
else{
379+
#if canImport(Accelerate)
337380
switch MfType.storedType(retmftype) {
338381
case .Float:
339382
return biopzvs_by_vDSP(l_mfarray, Float.from(r_scalar), vDSP_zrvdiv)
340383
case .Double:
341384
return biopzvs_by_vDSP(l_mfarray, Double.from(r_scalar), vDSP_zrvdivD)
342385
}
386+
#else
387+
fatalError("Complex array operations are not supported on this platform")
388+
#endif
343389
}
344390
}
345391
/**
@@ -366,12 +412,16 @@ extension Matft{
366412
}
367413
}
368414
else{
415+
#if canImport(Accelerate)
369416
switch MfType.storedType(retmftype) {
370417
case .Float:
371418
return biopzsv_by_vDSP(Float.from(l_scalar), r_mfarray, vDSP_ztrans)
372419
case .Double:
373420
return biopzsv_by_vDSP(Double.from(l_scalar), r_mfarray, vDSP_ztransD)
374421
}
422+
#else
423+
fatalError("Complex array operations are not supported on this platform")
424+
#endif
375425
}
376426
}
377427

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

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

99
import Foundation
10+
#if canImport(Accelerate)
1011
import Accelerate
12+
#endif
1113
import Collections
1214

1315
extension Matft{
@@ -45,13 +47,18 @@ extension Matft{
4547
}
4648
}
4749
else{
50+
#if canImport(Accelerate)
4851
switch newStoredType{
4952
case .Float://double to float
5053
return zcontiguous_and_astype_by_vDSP(mfarray, mftype: mftype, mforder: mforder, src_type: DSPDoubleSplitComplex.self, dst_type: DSPSplitComplex.self, vDSP_func: vDSP_vdpsp)
5154

5255
case .Double://float to double
5356
return zcontiguous_and_astype_by_vDSP(mfarray, mftype: mftype, mforder: mforder, src_type: DSPSplitComplex.self, dst_type: DSPDoubleSplitComplex.self, vDSP_func: vDSP_vspdp)
5457
}
58+
#else
59+
// Fallback for WASI: convert complex arrays element by element
60+
return _zcontiguous_and_astype_fallback(mfarray, mftype: mftype, mforder: mforder)
61+
#endif
5562
}
5663
}
5764
/**
@@ -298,12 +305,17 @@ extension Matft{
298305
}
299306
}
300307
else{
308+
#if canImport(Accelerate)
301309
switch mfarray.storedType{
302310
case .Float:
303311
return zcontiguous_by_vDSP(mfarray, vDSP_zvmov, mforder: mforder)
304312
case .Double:
305313
return zcontiguous_by_vDSP(mfarray, vDSP_zvmovD, mforder: mforder)
306314
}
315+
#else
316+
// Fallback for WASI: copy complex arrays element by element
317+
return _zcontiguous_fallback(mfarray, mforder: mforder)
318+
#endif
307319
}
308320
}
309321
/**
@@ -604,7 +616,22 @@ fileprivate func _unique<T: MfStorable>(_ flattendata: inout [T], restShape: ino
604616

605617
}
606618

619+
// MARK: - WASI Fallbacks for complex array operations
620+
#if !canImport(Accelerate)
607621

622+
/// Fallback for zcontiguous_and_astype_by_vDSP on WASI
623+
/// Complex array type conversion is not supported on WASI
624+
internal func _zcontiguous_and_astype_fallback(_ mfarray: MfArray, mftype: MfType, mforder: MfOrder) -> MfArray {
625+
fatalError("Complex array type conversion is not supported on this platform (requires Accelerate framework)")
626+
}
627+
628+
/// Fallback for zcontiguous_by_vDSP on WASI
629+
/// Complex array contiguous conversion is not supported on WASI
630+
internal func _zcontiguous_fallback(_ mfarray: MfArray, mforder: MfOrder) -> MfArray {
631+
fatalError("Complex array operations are not supported on this platform (requires Accelerate framework)")
632+
}
633+
634+
#endif
608635

609636

610637
/*

0 commit comments

Comments
 (0)