Hi Phil,

> What exactly *is* it and what are the use cases?

Just a method to multiply each element in an array by a number and return 
either a copy of the array or do it in place.  Maybe there can be one method 
for either way:

public static double[] scale(double val, final double[] arr) {
        double[] newArr = new double[arr.length];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i] * val;
        }
        return newArr;
    }
    
    public static void scaleInPlace(double val, final double[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= val;
        }
    }

>...use cases

I imagine they are pretty varied.  These methods could be used any time you 
want to multiply all elements in an array by a number without writing a loop 
each time.  I am using this in some optimization code that I am submitting but 
figured it would be broadly applicable enough to just be put in the MathArrays 
class.

Jared

-----Original Message-----
From: Phil Steitz [mailto:phil.ste...@gmail.com] 
Sent: Sunday, March 10, 2013 2:19 PM
To: Commons Developers List
Subject: Re: [math] Scaling arrays. .

On 3/8/13 12:14 PM, Becksfort, Jared wrote:
> Hello,
>
> I may be missing it somewhere, but I am surprised there is no function for 
> scaling arrays in MathArrays.java or somewhere else.
>
> -          Am I stupidly missing it?

Probably not.  Closest thing is probably normalize in MathArrays.
>
> -          Is there a reason it is not in there?

Probably no; though you will find that most vector / array algebraic operations 
are implemented on the objects in the linear package, rather than directly on 
double[]s.
>
> -          Shall I add it?

What exactly *is* it and what are the use cases?

Phil
>
> Thanks,
> Jared
>
> ________________________________
> Email Disclaimer: www.stjude.org/emaildisclaimer Consultation 
> Disclaimer: www.stjude.org/consultationdisclaimer
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to