package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the VMux 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 VMux extends Operator implements Constants {

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

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

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

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

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

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case SSSV: SSSV(v[0],v[1],v[2],v[3],n); return n;
      default:  return NOSUPPORT;
    }
  }

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

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

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case SSSV: SSSV(v[0],v[1],v[2],v[3],n); return n;
      default:  return NOSUPPORT;
    }
  }

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

  /** Apply this operator to mode {@link Operator#SSSV} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param d     The fourth  operand.
      @param n     The number of elements to operate on.
      @see #process(float[][],int,int)
   */
  public static final void SSSV (float[] a, float[] b, float[] c, float[] d, int n) {
    if ((c.length == 1) && (b.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[0]; d[k+2]=c[0];
      }
    } else if ((c.length == 1) && (a.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[i]; d[k+2]=c[0];
      }
    } else if (c.length == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[i]; d[k+2]=c[0];
      }
    } else if ((b.length  == 1) && (a.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[0]; d[k+2]=c[i];
      }
    } else if (b.length  == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[0]; d[k+2]=c[i];
      }
    } else if (a.length == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[i]; d[k+2]=c[i];
      }
    } else {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[i]; d[k+2]=c[i];
      }
    }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case SSSV: SSSV(v[0],v[1],v[2],v[3],n); return n;
      default:  return NOSUPPORT;
    }
  }

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

  /** Apply this operator to mode {@link Operator#SSSV} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param d     The fourth  operand.
      @param n     The number of elements to operate on.
      @see #process(int[][],int,int)
   */
  public static final void SSSV (int[] a, int[] b, int[] c, int[] d, int n) {
    if ((c.length == 1) && (b.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[0]; d[k+2]=c[0];
      }
    } else if ((c.length == 1) && (a.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[i]; d[k+2]=c[0];
      }
    } else if (c.length == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[i]; d[k+2]=c[0];
      }
    } else if ((b.length  == 1) && (a.length == 1)) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[0]; d[k+2]=c[i];
      }
    } else if (b.length  == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[0]; d[k+2]=c[i];
      }
    } else if (a.length == 1) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[0]; d[k+1]=b[i]; d[k+2]=c[i];
      }
    } else {
      for (int i=0,k=0; i<n; i++,k+=3) {
        d[k]=a[i]; d[k+1]=b[i]; d[k+2]=c[i];
      }
    }
  }

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