-
Notifications
You must be signed in to change notification settings - Fork 17
/
preop+static.swift
58 lines (53 loc) · 1.35 KB
/
preop+static.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// File 2.swift
//
//
// Created by AM19A0 on 2020/05/20.
//
import Foundation
import Accelerate
extension Matft{
/**
Element-wise negativity
- parameters:
- mfarray: mfarray
*/
public static func neg(_ mfarray: MfArray) -> MfArray{
return _prefix_operation(mfarray, .neg)
}
/**
Element-wise Not mfarray. Returned mfarray will be bool
- parameters:
- mfarray: mfarray
*/
public static func logical_not(_ mfarray: MfArray) -> MfArray{
var ret = to_Bool(mfarray)// copy and convert to bool
ret = Matft.math.abs(ret - 1) // force cast to Float
ret.mfdata.mftype = .Bool
return ret
}
}
fileprivate enum PreOp{
case neg
}
fileprivate func _prefix_operation(_ mfarray: MfArray, _ preop: PreOp) -> MfArray{
switch preop {
case .neg:
if mfarray.isReal{
switch mfarray.storedType{
case .Float:
return preop_by_vDSP(mfarray, vDSP_vneg)
case .Double:
return preop_by_vDSP(mfarray, vDSP_vnegD)
}
}
else{
switch mfarray.storedType{
case .Float:
return zpreop_by_vDSP(mfarray, vDSP_zvneg)
case .Double:
return zpreop_by_vDSP(mfarray, vDSP_zvnegD)
}
}
}
}