package nxm.sys.libm;

import nxm.sys.inc.Constants;

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

  /* Parameter declarations. */
  static final double eps$double=Double.MIN_VALUE, eps$float=Float.MIN_VALUE, eps$int=Float.MIN_VALUE;

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

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

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

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

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case SS: return n;
      case CS: return n;
      case VS: 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 CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 final void SS (double[] a, double[] b, int n, double scale) {
      for (int i=0; i<n; i++) {
        b[i]=(double)(scale*Math.log(Math.abs(a[i])+eps$double));
      }
  }

  /** Apply this operator to mode {@link Operator#CS} 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 final void CS (double[] a, double[] b, int n, double scale) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=(double)(scale*Math.log((a[j]*a[j]+a[j+1]*a[j+1])+eps$double));
      }
  }

  /** Apply this operator to mode {@link Operator#VS} 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 final void VS (double[] a, double[] b, int n, double scale) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[i]=(double)(scale*Math.log((a[k]*a[k]+a[k+1]*a[k+1]+a[k+2]*a[k+2])+eps$double));
      }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 final void SS (float[] a, float[] b, int n, double scale) {
      for (int i=0; i<n; i++) {
        b[i]=(float)(scale*Math.log(Math.abs(a[i])+eps$float));
      }
  }

  /** Apply this operator to mode {@link Operator#CS} 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 final void CS (float[] a, float[] b, int n, double scale) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=(float)(scale*Math.log((a[j]*a[j]+a[j+1]*a[j+1])+eps$float));
      }
  }

  /** Apply this operator to mode {@link Operator#VS} 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 final void VS (float[] a, float[] b, int n, double scale) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[i]=(float)(scale*Math.log((a[k]*a[k]+a[k+1]*a[k+1]+a[k+2]*a[k+2])+eps$float));
      }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case SS: SS(v[0],v[1],n, scale); return n;
      case CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 CS: CS(v[0],v[1],n, scale); return n;
      case VS: VS(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 final void SS (int[] a, int[] b, int n, double scale) {
      for (int i=0; i<n; i++) {
        b[i]=(int)(scale*Math.log(Math.abs(a[i])+eps$int));
      }
  }

  /** Apply this operator to mode {@link Operator#CS} 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 final void CS (int[] a, int[] b, int n, double scale) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=(int)(scale*Math.log((a[j]*a[j]+a[j+1]*a[j+1])+eps$int));
      }
  }

  /** Apply this operator to mode {@link Operator#VS} 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 final void VS (int[] a, int[] b, int n, double scale) {
      for (int i=0,k=0; i<n; i++,k+=3) {
        b[i]=(int)(scale*Math.log((a[k]*a[k]+a[k+1]*a[k+1]+a[k+2]*a[k+2])+eps$int));
      }
  }

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