package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the Scale operation on arrays. <br>
   See {@link Operator} for a description of the available I/O Modes.
   @author  Auto-Generated
   @see     Operator
*/
@SuppressWarnings("cast")
public final class Scale extends Operator implements Constants {

  /** Create a new instance. */
  public Scale() {
    super();
  }

  /** Create a new instance.
      @param flags The processing flags to use.
   */
  public Scale (int flags) {
    super(flags);
  }

  /** Create a new instance.
      @param scale The scale factor to use.
   */
  public Scale (double scale) {
    super(scale);
  }

  /** Create a new instance.
      @param flags The processing flags to use.
      @param scale The scale factor to use.
   */
  public Scale (int flags, double scale) {
    super(flags,scale);
  }

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case SS: return n;
      case CC: return n;
      case VV: return n;
      default: return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void SS (double[] a, double[] b, int n, double scale) {
    double s=(double)scale;
      for (int i=0; i<n; i++) {
        b[i]=s*a[i];
      }
  }

  /** Apply this operator to mode {@link Operator#CC} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void CC (double[] a, double[] b, int n, double scale) {
    double s=(double)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[j]=s*a[j]; b[j+1]=s*a[j+1];
      }
  }

  /** Apply this operator to mode {@link Operator#VV} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void VV (double[] a, double[] b, int n, double scale) {
    double s=(double)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[k]=s*a[k]; b[k+1]=s*a[k+1]; b[k+2]=s*a[k+2];
      }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (float[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void SS (float[] a, float[] b, int n, double scale) {
    float s=(float)scale;
      for (int i=0; i<n; i++) {
        b[i]=s*a[i];
      }
  }

  /** Apply this operator to mode {@link Operator#CC} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void CC (float[] a, float[] b, int n, double scale) {
    float s=(float)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[j]=s*a[j]; b[j+1]=s*a[j+1];
      }
  }

  /** Apply this operator to mode {@link Operator#VV} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void VV (float[] a, float[] b, int n, double scale) {
    float s=(float)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[k]=s*a[k]; b[k+1]=s*a[k+1]; b[k+2]=s*a[k+2];
      }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (int[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CC: CC(v[0],v[1],n, scale); return n;
      case VV: VV(v[0],v[1],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void SS (int[] a, int[] b, int n, double scale) {
    int s=(int)scale;
      for (int i=0; i<n; i++) {
        b[i]=s*a[i];
      }
  }

  /** Apply this operator to mode {@link Operator#CC} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void CC (int[] a, int[] b, int n, double scale) {
    int s=(int)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[j]=s*a[j]; b[j+1]=s*a[j+1];
      }
  }

  /** Apply this operator to mode {@link Operator#VV} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void VV (int[] a, int[] b, int n, double scale) {
    int s=(int)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[k]=s*a[k]; b[k+1]=s*a[k+1]; b[k+2]=s*a[k+2];
      }
  }

  public int getInputs() { return 1; }
  public int getOutputs() { return 1; }
}
