Contents

init(_:)

An MLMultiArray constructed with the FixedWidthInteger elements of the collection converted to Int32.

Declaration

convenience init<C>(_ data: C) throws where C : Collection, C.Element : FixedWidthInteger

Discussion

let v:[Int32] = [3, 2, 1]
let m = try MLMultiArray(v)
print(m)
Int32 3 vector
[3,2,1]

This initializer will trap if called with data containing FixedWidthInteger elements that cannot be safely converted to Int32, but it is safe to use with wider types so long as the actual data is within range.

let a = try MLMultiArray([Int.max]) // trap!
let b = try MLMultiArray([Int(Int32.max), Int(Int32.min)]) // This is fine.

See Also

Creating a multiarray