AnyTensor
public class AnyTensor
extension DynamicGraph.AnyTensor: CustomStringConvertible
extension DynamicGraph.AnyTensor: CustomDebugStringConvertible
extension DynamicGraph.AnyTensor: DynamicGraph_Any
extension DynamicGraph.AnyTensor: DynamicGraph.AnyTensorGroup
A type-erased tensor variable.
-
Declaration
Swift
public var grad: AnyTensor?
-
Declaration
Swift
public var graph: DynamicGraph { get }
-
Declaration
Swift
public var requiresGrad: Bool { get set }
-
Declaration
Swift
public required init(_ tensor: AnyTensor)
-
Declaration
Swift
public var shape: TensorShape { get }
-
Declaration
Swift
public var kind: DeviceKind { get }
-
Declaration
Swift
public var format: TensorFormat { get }
-
Declaration
Swift
public var strides: TensorShape { get }
-
A constant tensor can only be used as input, you cannot compute gradients for a constant tensor.
Declaration
Swift
public var isConstant: Bool { get }
-
Whether this tensor is contiguous in memory.
Declaration
Swift
public var isContiguous: Bool { get }
-
Compute gradients from this tensor to the source tensors.
Declaration
Swift
public func backward<S: Sequence>(to tensors: S, streamContext: StreamContext? = nil) where S.Element: DynamicGraph.AnyTensor
Parameters
to
The source tensors to this tensor.
streamContext
The stream context to perform such operation.
-
Compute gradients from this tensor to the source tensor.
Declaration
Swift
public func backward(to tensor: DynamicGraph.AnyTensor, streamContext: StreamContext? = nil)
Parameters
to
The source tensor to this tensor.
streamContext
The stream context to perform such operation.
-
Create a new tensor variable with dimensions permuted.
Declaration
Swift
public func permuted(_ indices: Int...) -> Self
Parameters
indices
The indices for dimensions from the original tensor. For example, a [2, 3, 4] tensor with [2, 0, 1] indices will permute to a [4, 2, 3] tensor.
Return Value
The new tensor variable with dimensions permuted.
-
Declaration
Swift
public func reshaped( format: TensorFormat, shape: TensorShape, offset: TensorShape? = nil, strides: TensorShape? = nil ) -> Self
-
Create a new tensor representing the same variable but with different sizes.
Declaration
Swift
public func reshaped( _ shapeFormat: TensorShapeFormat, offset: TensorShape? = nil, strides: TensorShape? = nil ) -> Self
Parameters
shapeFormat
New format and shape for the tensor.
offset
Whether offset on each shape.
strides
The stride on each shape.
Return Value
The new tensor with different format but the same underlying variable.
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
-
Explicitly cast the underlying storage to a specific type. It is a helper function than doing DynamicGraph.Tensor
(something). Less code change required if we change this from tensor to group. Declaration
Swift
public func `as`<Element>(of: Element.Type) -> DynamicGraph.Tensor<Element> where Element : TensorNumeric
-
Declaration
Swift
public var isNaN: Bool { get }
-
Declaration
Swift
public var untyped: [DynamicGraph.AnyTensor] { get }
-
Declaration
Swift
public typealias AnyTensor = DynamicGraph.AnyTensor
-
Declaration
Swift
public static func exec( cmd: ccv_nnc_cmd_t, hint: ccv_nnc_hint_t, inputs: [DynamicGraph_Any?], outputSize: Int32, streamContext: StreamContext? ) -> [AnyTensor]
-
Declaration
Swift
public static func exec( cmd: ccv_nnc_cmd_t, hint: ccv_nnc_hint_t, inputs: [DynamicGraph_Any?], outputs: [DynamicGraph_Any], streamContext: StreamContext? )
-
Declaration
Swift
public static func evaluate( model: OpaquePointer, testing: Bool, dataParallel: inout Int?, inputs: [DynamicGraph_Any?], outputSize: Int32, streamContext: StreamContext? ) -> [AnyTensor]