Tensor

public struct Tensor<Element> : AnyTensor where Element : TensorNumeric
extension Tensor: CustomStringConvertible

Basic tensor type.

  • Undocumented

    Declaration

    Swift

    public private(set) var storage: AnyTensorStorage { get }
  • Undocumented

    Declaration

    Swift

    public var cTensor: UnsafeMutablePointer<ccv_nnc_tensor_t> { get }
  • Create a typed tensor from a type-erased tensor.

    Declaration

    Swift

    public init(_ tensor: AnyTensor)

    Parameters

    tensor

    A type-erased tensor.

  • Undocumented

    Declaration

    Swift

    public init(_ kind: DeviceKind, format: TensorFormat, dimensions: [Int])
  • Create a new uninitialized tensor.

    Declaration

    Swift

    public init(_ kind: DeviceKind, _ dimensionFormat: TensorDimensionFormat)

    Parameters

    kind

    Which device this new tensor is on.

    dimensionFormat

    The format and dimensions of the new tensor.

  • Undocumented

    Declaration

    Swift

    public init<S: Sequence>(_ sequence: S, format: TensorFormat, dimensions: [Int])
    where S.Element == Element
  • Create a new tensor and initialize with content from a sequence.

    Declaration

    Swift

    public init<S: Sequence>(_ sequence: S, _ dimensionFormat: TensorDimensionFormat)
    where S.Element == Element

    Parameters

    sequence

    The sequence to initialize the new tensor with.

    dimensionFormat

    The format and dimensions of the new tensor.

  • Undocumented

    Declaration

    Swift

    public init(
      _ kind: DeviceKind, format: TensorFormat, dimensions: [Int],
      unsafeMutablePointer: UnsafeMutablePointer<Element>, keepAlive: Any
    )
  • Undocumented

    Declaration

    Swift

    public subscript(indices: Int...) -> Element { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(ranges: Range<Int>...) -> Tensor<Element> { get set }
  • Undocumented

    Declaration

    Swift

    public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R
  • Undocumented

    Declaration

    Swift

    public subscript(range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, i2: Int, range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, i2: Int, i3: Int, range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, i2: Int, i3: Int, i4: Int, range: Range<Int>) -> [Element] { get set }
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, i2: Int, i3: Int, i4: Int, i5: Int, range: Range<Int>)
      -> [Element]
  • Undocumented

    Declaration

    Swift

    public subscript(i0: Int, i1: Int, i2: Int, i3: Int, i4: Int, i5: Int, i6: Int, range: Range<Int>)
      -> [Element]
  • Move this tensor from CPU to GPU.

    Declaration

    Swift

    public func toGPU(_ ordinal: Int = 0, streamContext: StreamContext? = nil) -> Tensor<Element>

    Parameters

    ordinal

    Which GPU the new tensor will reside.

    streamContext

    Run the operation on the given stream context.

    Return Value

    A new tensor on GPU.

  • Move this tensor from GPU to CPU.

    Declaration

    Swift

    public func toCPU(streamContext: StreamContext? = nil) -> Tensor<Element>

    Parameters

    streamContext

    Run the operation on the given stream context.

    Return Value

    A new tensor on CPU.

  • Undocumented

    Declaration

    Swift

    public func reshape(
      format: TensorFormat, dimensions: [Int], offset: [Int]? = nil, increments: [Int]? = nil
    ) -> Self
  • Create a new tensor pointing to the same memory region but with different sizes.

    Declaration

    Swift

    public func reshape(
      _ dimensionFormat: TensorDimensionFormat, offset: [Int]? = nil, increments: [Int]? = nil
    ) -> Self

    Parameters

    dimensionFormat

    New format and dimensions for the tensor.

    offset

    Whether offset on each dimensions.

    increments

    The step on each dimensions.

    Return Value

    The new tensor with different format but the same memory content.

  • Declaration

    Swift

    public var description: String { get }

Available where Element: NumpyScalarCompatible

  • Initialize a tensor from numpy object.

    Declaration

    Swift

    public init?(numpy numpyArray: PythonObject)
  • Make a numpy object from a typed tensor.

    Declaration

    Swift

    public func makeNumpyArray() -> PythonObject