Skip to content

Commit

Permalink
Refactor (Fixed #23, #25) (#28)
Browse files Browse the repository at this point in the history
* change folder structure

* mfarray init

* change mfdata's access modifier

* MfStructure

* withDummy -> MfData

* integrate withptr

* index

* optparams

* wrap_vDSP_convert

* vDSP

* vForce

* cblas

* stack, concat

* lapack

* update performance test results

* pointer

* newdata

* astype

* bool
  • Loading branch information
jjjkkkjjj authored Jul 1, 2022
1 parent 64762f2 commit 5c6e15c
Show file tree
Hide file tree
Showing 64 changed files with 4,190 additions and 3,887 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,133 @@
<dict>
<key>classNames</key>
<dict>
<key>ArithmeticPefTests</key>
<dict>
<key>testPeformanceAdd1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.000597</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceAdd2()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.004465</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceAdd3()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.005312</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>BoolPefTests</key>
<dict>
<key>testPeformanceEqual1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.009165</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceEqual2()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.019724</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceGreater1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.004639</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceGreater2()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.017860</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>IndexingPefTests</key>
<dict>
<key>testPeformanceBooleanIndexing1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.001214</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>MathPefTests</key>
<dict>
<key>testPeformanceSign1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.081713</real>
<real>0.003097</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceSign2()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.008337</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceSin1()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.002143</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPeformanceSin2()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.007024</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions MatftDemo/MatftDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ViewController: UIViewController {

// reverse
arr = arr[~<<-1]
arr = arr.conv_order(mforder: .Row)
arr = arr.to_contiguous(mforder: .Row)

arr.withDataUnsafeMBPtrT(datatype: Float.self){
srcptr in
Expand Down Expand Up @@ -83,7 +83,7 @@ class ViewController: UIViewController {

// reverse
arr = arr[0~<, 0~<, ~<<-1]
arr = arr.conv_order(mforder: .Row)
arr = arr.to_contiguous(mforder: .Row)

arr.withDataUnsafeMBPtrT(datatype: Float.self){
srcptr in
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Below is Matft's function list. As I mentioned above, almost functions are simil
| *Matft.expand_dims | *numpy.expand_dims |
| *Matft.squeeze | *numpy.squeeze |
| *Matft.broadcast_to | *numpy.broadcast_to |
| *Matft.conv_order | *numpy.ascontiguousarray |
| *Matft.to_contiguous| *numpy.ascontiguousarray |
| *Matft.flatten | *numpy.flatten |
| *Matft.flip | *numpy.flip |
| *Matft.clip | *numpy.clip |
Expand Down Expand Up @@ -588,7 +588,7 @@ func reverse(){

// reverse
arr = arr[~<<-1]
arr = arr.conv_order(mforder: .Row)
arr = arr.to_contiguous(mforder: .Row)

// MfArray to UIImage
arr.withDataUnsafeMBPtrT(datatype: Float.self){
Expand Down Expand Up @@ -643,33 +643,33 @@ posb = a > 0

| Matft | time | Numpy | time |
| ------------------------ | ----------------- | ----------------- |----------------- |
| `let _ = a+aneg` | `863μs` | `a+aneg` | `1.04ms` |
| `let _ = b+aT` | `4.47ms` | `b+aT` | `4.31ms` |
| `let _ = c+aT` | `5.30ms` | `c+aT` | `2.92ms` |
| `let _ = a+aneg` | `596μs` | `a+aneg` | `1.04ms` |
| `let _ = b+aT` | `4.46ms` | `b+aT` | `4.31ms` |
| `let _ = c+aT` | `5.31ms` | `c+aT` | `2.92ms` |

- Math test

| Matft | time | Numpy | time |
| ------------------------ | ----------------- | ----------------- |----------------- |
| `let _ = Matft.math.sin(a)` | `1.80ms` | `np.sin(a)` | `14.7ms` |
| `let _ = Matft.math.sin(b)` | `8.24ms` | `np.sin(b)` | `15.8ms` |
| `let _ = Matft.math.sign(a)` | `3.20ms` | `np.sign(a)` | `1.37ms` |
| `let _ = Matft.math.sign(b)` | `2.78ms` | `np.sign(b)` | `1.42ms` |
| `let _ = Matft.math.sin(a)` | `2.14ms` | `np.sin(a)` | `14.7ms` |
| `let _ = Matft.math.sin(b)` | `7.02ms` | `np.sin(b)` | `15.8ms` |
| `let _ = Matft.math.sign(a)` | `3.09ms` | `np.sign(a)` | `1.37ms` |
| `let _ = Matft.math.sign(b)` | `8.33ms` | `np.sign(b)` | `1.42ms` |

- Bool test

| Matft | time | Numpy | time |
| ------------------------ | ----------------- | ----------------- |----------------- |
| `let _ = a > 0` | `5.01ms` | `a > 0` | `855μs` |
| `let _ = a > b` | `13.3ms` | `a > b` | `1.83ms` |
| `let _ = a === 0` | `9.91ms` | `a == 0` | `603μs` |
| `let _ = a === b` | `17.9ms` | `a == b` | `1.78ms` |
| `let _ = a > 0` | `4.63ms` | `a > 0` | `855μs` |
| `let _ = a > b` | `17.8ms` | `a > b` | `1.83ms` |
| `let _ = a === 0` | `4.65ms` | `a == 0` | `603μs` |
| `let _ = a === b` | `19.7ms` | `a == b` | `1.78ms` |

- Indexing test

| Matft | time | Numpy | time |
| ------------------------ | ----------------- | ----------------- |----------------- |
| `let _ = a[posb]` | `1.07ms` | `a[posb]` | `1.29ms` |
| `let _ = a[posb]` | `1.21ms` | `a[posb]` | `1.29ms` |


Matft achieved almost same performance as Numpy!!!
Expand Down
32 changes: 30 additions & 2 deletions Sources/Matft/core/general/print.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,39 @@ fileprivate func _clousure_number(mfarray: MfArray, indices: inout [Int]) -> Int
return clousureNum
}

extension MfData: CustomStringConvertible{
public var description: String{
var ret = ""

ret += "Original Type\t: \(self.mftype)\n"
ret += "Stored Type\t\t: \(self.storedType)\n"
ret += "Raw Data:\n"
switch self.storedType{
case .Float:
let ptrF = self.data.bindMemory(to: Float.self, capacity: self.storedSize)
ret += "\(Array(UnsafeMutableBufferPointer(start: ptrF, count: self.storedSize)))\n"
case .Double:
let ptrD = self.data.bindMemory(to: Double.self, capacity: self.storedSize)
ret += "\(Array(UnsafeMutableBufferPointer(start: ptrD, count: self.storedSize)))\n"
}

ret += "\n"

ret += "isView\t: \(self._isView)\n"
ret += "offset\t: \(self.offset)\n"

return ret
}
}


extension MfFlags: CustomStringConvertible{
extension MfStructure: CustomStringConvertible{
public var description: String{
var ret = ""
ret += "shape\t: \(self.shape)\n"
ret += "strides\t: \(self.strides)\n"

ret += "\n"

ret += "Row contiguous\t\t: \(self.row_contiguous)\n"
ret += "Column contiguous\t: \(self.column_contiguous)\n"
return ret
Expand Down
Loading

0 comments on commit 5c6e15c

Please sign in to comment.