In the example below, solve is a non-mutating func within struct type
Matrix, that uses an Array<T> to store its values.

This function mutates self, even though it's declared as non-mutating.

My understanding is that the compiler doesn't make a real copy in the acopy
=  self instruction, and then provides that contents to the mx_gels_
function which modifies the memory contents.


public func solve(rhs b: Matrix<T>) -> Matrix<T>? {

// ...

var acopy = self

// ...


T.mx_gels_(&trans, &m, &n, &nrhs, UnsafeMutablePointer<T>(acopy.values),
&lda, UnsafeMutablePointer<T>(x.values), &ldb,
UnsafeMutablePointer<T>(workspace),
&lwork, &status);

// ...

}



Is this expected? I mean, I can force a real copy of course, but value
semantics would suggest the code above is correct and wouldn't need that.
Shouldn't the cast trigger the copy somehow? Or is there a better way of
expressing this operation? Thx.

Raphael
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to