tr8dr / .Net-Bridge

.NET Bridge allowing Python and R to access .NET libraries, running either locally or remotely
Apache License 2.0
28 stars 16 forks source link

Valued returned by reference #5

Open amalagoli opened 6 years ago

amalagoli commented 6 years ago

Will it be possible to access results returned as a reference in the function call argument, like here: MathNet.Numerics.Distributions.Normal.Samples(System.Double[],System.Double,System.Double)

        <summary>
        Fills an array with samples generated from the distribution.
        </summary>
        <param name="values">The array to fill with the samples.</param>
        <param name="mean">The mean (μ) of the normal distribution.</param>
        <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
        <returns>a sequence of samples from the distribution.</returns>
    </member>
tr8dr commented 6 years ago

There is no support for return by reference. The code assumes a function returns either an object, primitive, or void. When I have a function that may operate in-memory on an array or vector, such as:

void samplesFor (double sd, samples: double[]) { ... }

I adjust this as follows:

double[] samplesFor (souble sd, samples[]) { ... return samples; }

In that way you can get the result as a function return value even though you are passing in the array to be filled. I would go further to default the array to null and then create one internally if not passed in (though would need a length in the parameters).

returning args with out or reference is understandable for performance, but can be homogenized with a more traditional return value as demonstrated above.

On Sun, Jun 3, 2018 at 5:45 PM amalagoli notifications@github.com wrote:

Will it be possible to access results returned as a reference in the function call argument, like here:

Fills an array with samples generated from the distribution.

The array to fill with the samples. The mean (μ) of the normal distribution. The standard deviation (σ) of the normal distribution. Range: σ ≥ 0. a sequence of samples from the distribution.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tr8dr/.Net-Bridge/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/ADG0Ul96W52sB96V7UR5X10Q9fTiVejnks5t5Fj-gaJpZM4UYQMv .

amalagoli commented 6 years ago

Thanks, I thought this much. It is not a problem for my own functions, but it will take some extra work to write wrappers for external libraries like in the example. Not a big deal anyway. Thanks again.