Fix error messages; tensor creation method names with type (#26219)

Summary:
After offline discussion with dzhulgakov :
 - In future we will introduce creation of byte signed and byte unsigned dtype tensors, but java has only signed byte - we will have to add some separation for it in method names ( java types and tensor types  can not be clearly mapped) => Returning type in method names

- fixes in error messages

- non-static method Tensor.numel()

- Change Tensor toString() to be more consistent with python

Update on Sep 16:

Type renaming on java side to uint8, int8, int32, float32, int64, float64
```
public abstract class Tensor {
  public static final int DTYPE_UINT8 = 1;
  public static final int DTYPE_INT8 = 2;
  public static final int DTYPE_INT32 = 3;
  public static final int DTYPE_FLOAT32 = 4;
  public static final int DTYPE_INT64 = 5;
  public static final int DTYPE_FLOAT64 = 6;
```
```
  public static Tensor newUInt8Tensor(long[] shape, byte[] data)
  public static Tensor newInt8Tensor(long[] shape, byte[] data)
  public static Tensor newInt32Tensor(long[] shape, int[] data)
  public static Tensor newFloat32Tensor(long[] shape, float[] data)
  public static Tensor newInt64Tensor(long[] shape, long[] data)
  public static Tensor newFloat64Tensor(long[] shape, double[] data)
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26219

Differential Revision: D17406467

Pulled By: IvanKobzarev

fbshipit-source-id: a0d7d44dc8ce8a562da1a18bd873db762975b184
This commit is contained in:
Ivan Kobzarev
2019-09-16 18:25:17 -07:00
committed by Facebook Github Bot
parent 448c53747a
commit b07991f7f5
4 changed files with 173 additions and 82 deletions

View File

@ -40,7 +40,7 @@ public final class TensorImageUtils {
floatArray[offset_b + i] = (b - NORM_MEAN_B) / NORM_STD_B;
}
final long shape[] = new long[] {1, 3, height, width};
return Tensor.newTensor(shape, floatArray);
return Tensor.newFloat32Tensor(shape, floatArray);
}
public static Tensor imageYUV420CenterCropToFloatTensorTorchVisionForm(
@ -131,7 +131,7 @@ public final class TensorImageUtils {
}
}
final long shape[] = new long[] {1, 3, tensorHeight, tensorHeight};
return Tensor.newTensor(shape, floatArray);
return Tensor.newFloat32Tensor(shape, floatArray);
}
private static final int clamp(int c, int min, int max) {