---
title: GetOptionalInputShape
description: "根据算子原型定义中的输入索引获取对应的可选输入shape指针。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/maintenref/basicdataapi/atlasopapi_07_00097.html
sourcePath: /source/zh/canncommercial/900/maintenref/basicdataapi/atlasopapi_07_00097.html
indexId: b6590b63373913da6f35de2d1392215e40b28e8ed7aebed96ee6a8bd4f79ac1778
---
# GetOptionalInputShape

#### 函数功能

根据算子原型定义中的输入索引获取对应的可选输入shape指针。


#### 函数原型

```
const Shape *GetOptionalInputShape(const size_t ir_index) const
```


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| ir\_index | 输入 | 算子IR原型定义中的输入索引，从0开始计数。 |


#### 返回值说明

返回输入shape的指针，输入ir_index非法，或该输入没有实例化时，返回空指针。

关于Shape类型的定义，请参见Shape。


#### 约束说明

无。


#### 调用示例

```
ge::graphStatus InferShapeForXXX(InferShapeContext *context) {
  auto in_shape = context->GetOptionalInputShape(2);
  // ...
}
```
