Class SparseNdArray<T,​U extends NdArray<T>>

    • Constructor Detail

      • SparseNdArray

        protected SparseNdArray​(Class<T> type,
                                LongNdArray indices,
                                U values,
                                T defaultValue,
                                DimensionalSpace dimensions)
        Creates a SparseNdArray
        Parameters:
        indices - A 2-D LongNdArray of shape [N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example, indices=[[1,3], [2,4]] specifies that the elements with indexes of [1,3] and [2,4] have non-default values.
        values - A 1-D NdArray of Boolean type and shape [N], which supplies the values for each element in indices. For example, given indices=[[1,3], [2,4]], the parameter values=[18, 3.6] specifies that element [1,3] of the sparse NdArray has a value of 18, and element [2,4] of the NdArray has a value of 3.6.
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        dimensions - the dimensional space for the dense object represented by this sparse array,
    • Method Detail

      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     LongNdArray indices,
                                                                                     U values,
                                                                                     DimensionalSpace dimensions)
        Creates a new SparseNdArray
        Parameters:
        indices - A 2-D LongNdArray of shape [N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example, indices=[[1,3], [2,4]] specifies that the elements with indexes of [1,3] and [2,4] have non-default values.
        values - A 1-D NdArray of any type and shape [N], which supplies the values for each element in indices. For example, given indices=[[1,3], [2,4]], the parameter values=[18, 3.6] specifies that element [1,3] of the sparse NdArray has a value of 18, and element [2,4] of the NdArray has a value of 3.6.
        dimensions - the dimensional space for the dense object represented by this sparse array.
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     LongNdArray indices,
                                                                                     U values,
                                                                                     T defaultValue,
                                                                                     DimensionalSpace dimensions)
        Creates a new SparseNdArray
        Parameters:
        indices - A 2-D LongNdArray of shape [N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example, indices=[[1,3], [2,4]] specifies that the elements with indexes of [1,3] and [2,4] have non-default values.
        values - A 1-D NdArray of any type and shape [N], which supplies the values for each element in indices. For example, given indices=[[1,3], [2,4]], the parameter values=[18, 3.6] specifies that element [1,3] of the sparse NdArray has a value of 18, and element [2,4] of the NdArray has a value of 3.6.
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        dimensions - the dimensional space for the dense object represented by this sparse array.
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     DataBuffer<T> dataBuffer,
                                                                                     DimensionalSpace dimensions)
        Creates a new SparseNdArray from a data buffer
        Parameters:
        dataBuffer - the databuffer containing the dense array
        dimensions - the dimensional space for the sparse array
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     DataBuffer<T> dataBuffer,
                                                                                     T defaultValue,
                                                                                     DimensionalSpace dimensions)
        Creates a new SparseNdArray from a data buffer
        Parameters:
        dataBuffer - the databuffer containing the dense array
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        dimensions - the dimensional space for the sparse array
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     DimensionalSpace dimensions)
        Creates a new empty SparseNdArray from a data buffer
        Parameters:
        dimensions - the dimensions array
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     T defaultValue,
                                                                                     DimensionalSpace dimensions)
        Creates a new empty SparseNdArray from a data buffer
        Parameters:
        dimensions - the dimensions array
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     DataBuffer<T> buffer,
                                                                                     Shape shape)
        Creates a new empty SparseNdArray from a float data buffer
        Parameters:
        buffer - the data buffer
        shape - the shape of the sparse array.
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     DataBuffer<T> buffer,
                                                                                     T defaultValue,
                                                                                     Shape shape)
        Creates a new empty SparseNdArray from a float data buffer
        Parameters:
        buffer - the data buffer
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        shape - the shape of the sparse array.
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     U src)
        Creates a new SparseNdArray from a NdArray
        Parameters:
        src - the NdArray
        Returns:
        the new Sparse Array
      • create

        public static <T,​U extends NdArray<T>> SparseNdArray<T,​U> create​(Class<T> type,
                                                                                     U src,
                                                                                     T defaultValue)
        Creates a new SparseNdArray from a NdArray
        Parameters:
        defaultValue - Scalar value to set for indices not specified in AbstractSparseNdArray.getIndices()
        src - the NdArray
        Returns:
        the new Sparse Array
      • createDefaultArray

        public U createDefaultArray()
        Creates the NdArray with the default value as a scalar
        Specified by:
        createDefaultArray in class AbstractSparseNdArray<T,​U extends NdArray<T>>
        Returns:
        the default NdArray of the default value as a scalar
      • createValues

        public U createValues​(Shape shape)
        Creates a NdArray of the specified shape
        Specified by:
        createValues in class AbstractSparseNdArray<T,​U extends NdArray<T>>
        Parameters:
        shape - the shape of the dense array.
        Returns:
        a NdArray of the specified shape
      • slice

        public U slice​(long position,
                       DimensionalSpace sliceDimensions)
        Specified by:
        slice in class org.tensorflow.ndarray.impl.AbstractNdArray<T,​U extends NdArray<T>>
      • read

        public NdArray<T> read​(DataBuffer<T> dst)
        Read the content of this N-dimensional array into the destination buffer.

        The size of the buffer must be equal or greater to the Shaped.size() of this array, or an exception is thrown. After the copy, content of the buffer and of the array can be altered independently, without affecting each other.

        Specified by:
        read in interface NdArray<T>
        Parameters:
        dst - the destination buffer
        Returns:
        this array
        See Also:
        DataBuffer.size()
      • write

        public NdArray<T> write​(DataBuffer<T> src)
        Write the content of this N-dimensional array from the source buffer.

        The size of the buffer must be equal or greater to the Shaped.size() of this array, or an exception is thrown. After the copy, content of the buffer and of the array can be altered independently, without affecting each other.

        Specified by:
        write in interface NdArray<T>
        Parameters:
        src - the source buffer
        Returns:
        this array
        See Also:
        DataBuffer.size()
      • fromDense

        public NdArray<T> fromDense​(NdArray<T> src)
        Populates this sparse array from a dense array
        Parameters:
        src - the dense array
        Returns:
        this sparse array
      • getType

        public Class<T> getType()
        Gets the class type for this sparse array
        Returns:
        the class type for this sparse array.
      • toString

        public String toString()
        A String showing the type, default value, number of elements and the dense shape of this sparse ndarray.
        Overrides:
        toString in class AbstractSparseNdArray<T,​U extends NdArray<T>>
        Returns:
        A string containing the type, default value, number of elements and shape.