From 988d546b76b0a783d3775d3f56dd5938c5f03631 Mon Sep 17 00:00:00 2001 From: jjjkkkjjj Date: Sat, 6 Feb 2021 23:04:37 +0900 Subject: [PATCH] slightly improved (#18) --- .../xcschemes/ReleaseTest.xcscheme | 57 +++++++++++++++++++ Sources/Matft/util/library/vDSP.swift | 15 +++-- Tests/PerformanceTests/IndexingPefTests.swift | 4 +- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/ReleaseTest.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/ReleaseTest.xcscheme index 7146668..7519ca9 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/ReleaseTest.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/ReleaseTest.xcscheme @@ -21,6 +21,63 @@ BlueprintName = "MatftTests" ReferencedContainer = "container:"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Matft/util/library/vDSP.swift b/Sources/Matft/util/library/vDSP.swift index f5195b5..0a7543d 100644 --- a/Sources/Matft/util/library/vDSP.swift +++ b/Sources/Matft/util/library/vDSP.swift @@ -420,11 +420,11 @@ internal func boolget_by_vDSP(_ mfarray: MfArray, _ indices: MfAr let indicesT: MfArray switch mfarray.storedType { case .Float: - indicesT = check_contiguous(indices.astype(.Float), .Row) + indicesT = indices // indices must have float raw values case .Double: - indicesT = check_contiguous(indices.astype(.Double), .Row) + indicesT = indices.astype(.Double) } - let mfarray = check_contiguous(mfarray, .Row) + //let mfarray = check_contiguous(mfarray, .Row) let lastShape = Array(mfarray.shape.suffix(mfarray.ndim - orig_ind_dim)) @@ -436,11 +436,16 @@ internal func boolget_by_vDSP(_ mfarray: MfArray, _ indices: MfAr let dstptrT = dstptr.bindMemory(to: T.self, capacity: retSize) indicesT.withDataUnsafeMBPtrT(datatype: T.self){ - [unowned indicesT](indptr) in + //[unowned indicesT](indptr) in + indptr in // note that indices and mfarray is row contiguous mfarray.withDataUnsafeMBPtrT(datatype: T.self){ srcptr in - vDSP_func(srcptr.baseAddress!, vDSP_Stride(1), indptr.baseAddress!, vDSP_Stride(1), dstptrT, vDSP_Stride(1), vDSP_Length(indicesT.size)) + + for vDSPPrams in OptOffsetParams_mfarray(bigger_mfarray: indicesT, smaller_mfarray: mfarray){ + vDSP_func(srcptr.baseAddress! + vDSPPrams.s_offset, vDSP_Stride(vDSPPrams.s_stride), indptr.baseAddress! + vDSPPrams.b_offset, vDSP_Stride(vDSPPrams.b_stride), dstptrT + vDSPPrams.b_offset, vDSP_Stride(vDSPPrams.b_stride), vDSP_Length(vDSPPrams.blocksize)) + } + //vDSP_func(srcptr.baseAddress!, vDSP_Stride(1), indptr.baseAddress!, vDSP_Stride(1), dstptrT, vDSP_Stride(1), vDSP_Length(indicesT.size)) } } } diff --git a/Tests/PerformanceTests/IndexingPefTests.swift b/Tests/PerformanceTests/IndexingPefTests.swift index 6d6b873..0b857dd 100644 --- a/Tests/PerformanceTests/IndexingPefTests.swift +++ b/Tests/PerformanceTests/IndexingPefTests.swift @@ -12,8 +12,8 @@ final class IndexingPefTests: XCTestCase { let _ = a[a>0] } /* - '-[PerformanceTests.IndexingPefTests testPeformanceBooleanIndexing1]' measured [Time, seconds] average: 0.007, relative standard deviation: 17.050%, values: [0.010224, 0.007128, 0.006454, 0.007535, 0.006929, 0.006481, 0.006221, 0.006312, 0.006142, 0.006018] - 7ms + '-[PerformanceTests.IndexingPefTests testPeformanceBooleanIndexing1]' measured [Time, seconds] average: 0.005, relative standard deviation: 37.720%, values: [0.010294, 0.004666, 0.004402, 0.004150, 0.004102, 0.004048, 0.004186, 0.004013, 0.004319, 0.004240] + 4.84ms */ } }