Contents

resolvingDynamicDimensions(_:)

Returns a new descriptor with all dynamic dimensions replaced by concrete values.

Declaration

func resolvingDynamicDimensions(_ newShape: [Int]) -> NDArrayDescriptor

Discussion

If the original model contained ndArray arguments with dynamic shapes, then the NDArrayDescriptor returned for that argument from the InferenceFunctionDescriptor will contain the value -1 in the dimensions with dynamic sizes.

This method allows you to provide a resolved shape and obtain a new descriptor with that adjusted shape.

let functionDescriptor = model.functionDescriptor(for: "main")
guard case .ndArray(let ndArrayDescriptor) = functionDescriptor.inputDescriptor(of: "dynamic_shape_input") else {
  // Handle input not found or not ndArray
}

// The 'dynamic_shape_input' argument is a rank 3 ndArray with a dynamic shape for the final dimension.
// ndArrayDescriptor.shape == [128, 128, -1]

// Make a resolved descriptor which fills in the -1 dimension with the concrete value 10
let resolvedDescriptor = ndArrayDescriptor.resolvingDynamicDimensions([128, 128, 10])