Skip to content

Tensor

Tensor

softneuro.core.Tensor(*args, **kwargs)

Tensor class.Tensors are n-dimensional arrays.

This is a private class of softneuro, instance can not be constructed directly, users can get Tensor instance using Dnn.find_tensor().

Attributes

  • data : Pointer to the tensor data in memory whose data type is numpy.ndarray.
  • dtype : Tensor data type, one of float32, uint8, int8, int32, int64, qint8, qint32.
  • name : Tensor name.
  • qaxis : Quantization axis.
  • quants : Quantizers whose data type is softneuro.core.DnnList.
  • rank : Tensor rank (how many dimensions).
  • shape : Tensor shape.

areDTypeAndBatchShapeOf

Tensor.areDTypeAndBatchShapeOf(i_dtype, i_shape)

Verifies if the tensor dtype and shape per batch match the arguments.

Returns True if DType and shape per batch match, False otherwise.

Arguments

  • i_dtype (softneuro.DType): DType to be matched.
  • i_shape (tuple): Shape to be matched.

Returns

type : bool, true if the tensor dtype and shape per batch match the arguments else false.


areDTypeAndShapeOf

Tensor.areDTypeAndShapeOf(i_dtype, i_shape)

Verifies if the tensor dtype and shape match the arguments.

Returns True if DType and shape match, False otherwise.

Arguments

  • i_dtype (softneuro.DType): DType to be matched.
  • i_shape (tuple): Shape to be matched.

Returns

type : bool, true if the tensor dtype and shape match the arguments else false.


copy

Tensor.copy(val)

Copy data into the tensor.

Arguments

  • val (numpy.ndarray or list): Data to be copied.

copy_batch

Tensor.copy_batch(val, batch)

Copy data into the given batch index.

Arguments

  • val (numpy.ndarray or list): Data to be copied.
  • batch (int): Batch index.

format

Tensor.format(dtype, shape)

Sets the tensor dtype and shape.

Arguments

  • dtype (Softneuro.DType): Target data type.
  • shape (tuple): Target tensor shape.

getDType

Tensor.getDType()

Returns the tensor DType.

Returns

type : DType, DType of tensor.


getHash

Tensor.getHash()

Returns hash of tensor.

Returns

type : int, hash of tensor.


getName

Tensor.getName()

Returns name of tensor.

Returns

type : string, name of tensor.


getRank

Tensor.getRank()

Returns the tensor rank.

Returns

type : int, rank of tensor.


getShape

Tensor.getShape()

Returns the tensor shape.

Returns

type : tuple , int, shape of tensor.


getQAxis

Tensor.getQAxis()

Returns the quantization axis.

Returns

type : int, QAxis of tensor.


getQuant

Tensor.getQuant(i_index)

Returns the quant at the given index.

Arguments

  • i_index (int): Index of the quant to be return.

Returns

type : Quant, quants of tensor.


getQuantNum

Tensor.getQuantNum()

Returns the number of quants.

Returns

type : int, number of quants of tensor.


init_quant

Tensor.init_quant(qmode, qaxis)

Initializes the quantizers with qmode over qaxis. Returns an error if the tensor dtype isn't qint8 (not supported yet).

Arguments

  • i_qmode (Softneuro.qmode): Quantization mode.
  • i_qaxis (int): Quantization axis.

isFormatted

Tensor.isFormatted()

Returns True if the tensor was formatted, False otherwise.


normalize

Tensor.normalize()

Normalizes the tensor.

Returns True if the tensor was normalized, False otherwise.

Returns

type : bool, true if success else false.