Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return parameter passing in Julia

If a Julia function returns an array, is the reference returned or a copy?

function pass(A::Matrix)
   return A
end

A real example is reshape:

reshape(A, dims) Create an array with the same data as the given array, but with different dimensions. An implementation for a particular type of array may choose whether the data is copied or shared.

How does the implementation determine whether data is copied or shared?

like image 915
user25004 Avatar asked Mar 16 '23 00:03

user25004


1 Answers

The pass function above returns by reference, http://julia.readthedocs.org/en/latest/manual/arrays/ .

There is a bit more to the reshape example. For full arrays the reshaped array is a new array object that shares the same data. But keep in mind that there are plenty of specialized array types. The docs warn you not to rely on that because for example for a future implementation of immutable fixed sized arrays a different reshape mechanism could be used.

like image 194
mschauer Avatar answered Mar 24 '23 19:03

mschauer