-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to contribute - have some small numpy / scipy vDSP implementations #43
Labels
good first issue
Good for newcomers
Comments
@vade
internal typealias vDSP_convert_func<T, U> = (UnsafePointer<T>, vDSP_Stride, UnsafeMutablePointer<U>, vDSP_Stride, vDSP_Length) -> Void Note:
/// Wrapper of vDSP conversion function
/// - Parameters:
/// - srcptr: A source pointer
/// - srcStride: A source stride
/// - dstptr: A destination pointer
/// - dstStride: A destination stride
/// - size: A size to be copied
/// - vDSP_func: The vDSP conversion function
@inline(__always)
internal func wrap_vDSP_convert<T, U>(_ size: Int, _ srcptr: UnsafePointer<T>, _ srcStride: Int, _ dstptr: UnsafeMutablePointer<U>, _ dstStride: Int, _ vDSP_func: vDSP_convert_func<T, U>){
vDSP_func(srcptr, vDSP_Stride(srcStride), dstptr, vDSP_Stride(dstStride), vDSP_Length(size))
}
/// Pre operation mfarray by vDSP
/// - Parameters:
/// - mfarray: An input mfarray
/// - vDSP_func: vDSP_convert_func
/// - Returns: Pre operated mfarray
internal func preop_by_vDSP<T: MfStorable>(_ mfarray: MfArray, _ vDSP_func: vDSP_convert_func<T, T>) -> MfArray{
//return mfarray must be either row or column major
var mfarray = mfarray
//print(mfarray)
mfarray = check_contiguous(mfarray)
//print(mfarray)
//print(mfarray.strides)
let newdata = MfData(size: mfarray.storedSize, mftype: mfarray.mftype)
newdata.withUnsafeMutableStartPointer(datatype: T.self){
dstptrT in
mfarray.withUnsafeMutableStartPointer(datatype: T.self){
[unowned mfarray] in
wrap_vDSP_convert(mfarray.storedSize, $0, 1, dstptrT, 1, vDSP_func)
//vDSP_func($0.baseAddress!, vDSP_Stride(1), dstptrT, vDSP_Stride(1), vDSP_Length(mfarray.storedSize))
}
}
let newstructure = MfStructure(shape: mfarray.shape, strides: mfarray.strides)
return MfArray(mfdata: newdata, mfstructure: newstructure)
}
/**
Element-wise negativity
- parameters:
- mfarray: mfarray
*/
public static func neg(_ mfarray: MfArray) -> MfArray{
switch mfarray.storedType{
case .Float:
return preop_by_vDSP(mfarray, vDSP_vneg)
case .Double:
return preop_by_vDSP(mfarray, vDSP_vnegD)
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there
Ive got a few minor implementations of some numpy / scipy functions on vectors in vDSP along with associated XCTests that I think would make good contributions to Matft.
I'm curious how to best / properly implement these into Matft, as it seems like having a single home for them makes sense, and your code seems very well organized.
I'm not entirely sure of the code structure / best place to implement the logic in a generic way that leverages Matfts existing code base.
Do you have any suggestions?
numpy.allclose()
as an extension to Array (without NaN equality)scipy.spatial.distance.cosine
and
scipy.ndimage.gaussian_filter_1d
as array extensions allowing one to cache the computed gaussian kernel.Note I only really implement the default padding of reflect so far.
The text was updated successfully, but these errors were encountered: