package com.intel.analytics.zoo.pipeline.inference;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class JTensor {
  private float[] data;
  private int[] shape;

  public JTensor() {
  }

  public JTensor(List<Float> data, List<Integer> shape) {
    this.data = new float[data.size()];
    for (int i = 0; i < data.size(); i++){
      this.data[i] = data.get(i);
    }
    this.shape = new int[shape.size()];
    for (int i = 0; i < shape.size(); i++){
      this.shape[i] = shape.get(i);
    }
  }

  public JTensor(List<Float> data, Integer[] shape) {
    this.data = new float[data.size()];
    for (int i = 0; i < data.size(); i++){
      this.data[i] = data.get(i);
    }
    this.shape = new int[shape.length];
    for (int i = 0; i < shape.length; i++){
      this.shape[i] = shape[i];
    }
  }

  public JTensor(List<Float> data, int[] shape) {
    this.data = new float[data.size()];
    for (int i = 0; i < data.size(); i++){
      this.data[i] = data.get(i);
    }
    this.shape = new int[shape.length];
    for (int i = 0; i < shape.length; i++){
      this.shape[i] = shape[i];
    }
  }

  public JTensor(float[] data, List<Integer> shape) {
    this.data = new float[data.length];
    for (int i = 0; i < data.length; i++){
      this.data[i] = data[i];
    }
    this.shape = new int[shape.size()];
    for (int i = 0; i < shape.size(); i++){
      this.shape[i] = shape.get(i);
    }
  }

  public JTensor(float[] data, Integer[] shape) {
    this.data = new float[data.length];
    for (int i = 0; i < data.length; i++){
      this.data[i] = data[i];
    }
    this.shape = new int[shape.length];
    for (int i = 0; i < shape.length; i++){
      this.shape[i] = shape[i];
    }
  }

  public JTensor(float[] data, int[] shape) {
    this.data = new float[data.length];
    for (int i = 0; i < data.length; i++){
      this.data[i] = data[i];
    }
    this.shape = new int[shape.length];
    for (int i = 0; i < shape.length; i++){
      this.shape[i] = shape[i];
    }
  }

  public JTensor(float[] data, int[] shape, boolean copy){
    if (copy) {
      this.data = new float[data.length];
      for (int i = 0; i < data.length; i++){
        this.data[i] = data[i];
      }
      this.shape = new int[shape.length];
      for (int i = 0; i < shape.length; i++){
        this.shape[i] = shape[i];
      }
    }
    else {
      this.data = data;
      this.shape = shape;
    }
  }

  public float[] getData() {
    return data;
  }

  public void setData(float[] data) {
    this.data = data;
  }

  public int[] getShape() {
    return shape;
  }

  public void setShape(int[] shape) {
    this.shape = shape;
  }

  @Override
  public String toString() {
    return "JTensor{" +
            "data=" + data +
            ", shape=" + shape +
            '}';
  }
}
@@ -2672,16 +2672,968 @@
 e;%0A  %7D%0A%0A
+  public static String toString(int%5B%5D a) %7B%0A    if (a == null)%0A      return %22null%22;%0A    int iMax = a.length - 1;%0A    if (iMax == -1)%0A      return %22%5B%5D%22;%0A%0A    int max = Math.min(500, iMax);%0A%0A    StringBuilder b = new StringBuilder();%0A    b.append('%5B');%0A    for (int i = 0; ; i++) %7B%0A      b.append(a%5Bi%5D);%0A      if (i == max && i %3C iMax)%0A        return b.append(%22, ... %5D%22).toString();%0A      if (i == iMax)%0A        return b.append('%5D').toString();%0A      b.append(%22, %22);%0A    %7D%0A  %7D%0A%0A  public static String toString(float%5B%5D a) %7B%0A    if (a == null)%0A      return %22null%22;%0A    int iMax = a.length - 1;%0A    if (iMax == -1)%0A      return %22%5B%5D%22;%0A%0A    int max = Math.min(500, iMax);%0A%0A    StringBuilder b = new StringBuilder();%0A    b.append('%5B');%0A    for (int i = 0; ; i++) %7B%0A      b.append(a%5Bi%5D);%0A      if (i == max && i %3C iMax)%0A        return b.append(%22, ... %5D%22).toString();%0A      if (i == iMax)%0A        return b.append('%5D').toString();%0A      b.append(%22, %22);%0A    %7D%0A  %7D%0A%0A
   @Overr
@@ -3711,20 +3711,30 @@
 ata=%22 + 
+toString(
 data
+)
  +%0A     
@@ -3753,21 +3753,31 @@
 ape=%22 + 
+toString(
 shape
+)
  +%0A     

add JTensor toString (#609)