Contents

withUnsafeMutableBytes(_:)

Invokes the provided closure with the backing data and memory layout of this view.

Declaration

@export(implementation) consuming func withUnsafeMutableBytes<R, E>(_ body: (UnsafeMutableRawPointer, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R where E : Error

Return Value

The value returned by the closure.

Discussion

  • body: The closure to be invoked with a mutable raw pointer to the first element, as well as shape and strides of the view.

You are responsible for reading the strides passed in when indexing the backing data. If the view has an interleaveLayout, the strides for that dimension are block strides and must be interpreted accordingly — see NDArray.InterleaveLayout.