<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraph/Context/allocateTensor(forFunction:argument:fillKnownDynamicShapes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7ContextC14allocateTensor11forFunction8argument22fillKnownDynamicShapesSo10BNNSTensoraSgSSSg_SSSbtF"
  },
  "title" : "allocateTensor(forFunction:argument:fillKnownDynamicShapes:)"
}
-->

# allocateTensor(forFunction:argument:fillKnownDynamicShapes:)

Returns an allocated tensor for a given function argument.

```
func allocateTensor(forFunction function: String? = nil, argument: String, fillKnownDynamicShapes: Bool) -> BNNSTensor?
```

## Parameters

`function`

The specific function to create the tensor for. You may set this to `nil` if there is only one function.

`argument`

The argument to create the tensor for.

`fillKnownDynamicShapes`

if `true`, the function replaces any dynamic shapes
with shapes that will be used on next execution of `Context`, either drawn from default shapes in the `.mlmodelc`
function or supplied by a preceding call to
`setDynamicShapes(_:forFunction:)` or `setBatchSize(_:forFunction:)`.
Otherwise the function represents dynamically-sized dimensions with a value of `-1` in either shape or stride as appropriate.

## Discussion> Note: This function supports `Float`, `Float16`, `Bool`, and `Int32` datatypes only and returns `nil` for other types.

> SeeAlso: `BNNSGraphContextGetTensor`

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)