Computed Shape for MPSGraph.reshape

I need to reshape a tensor A to shape S that is not available at the compile time. I would like to compute the shape S inside the graph and then reshape the tensor A to the shape S. Is this even possible with MPS?

Hi, we'd appreciate it if you could file a request via feedback assistant (https://developer.apple.com/bug-reporting/) and link the number here. Thanks

Accepted Answer

You should use:

/*!

 *  @abstract   Create Reshape op and return the result tensor

 *  @discussion Reshape the input tensor to the target shapeTensor

 *              The shape must be compatible with the input tensor shape

 *              shapeTensor is allowed to contain dynamic dimensions (-1) when the result type can be inferred unambiguously

 *

 *  @param      tensor                  Tensor to be reshaped.

 *  @param      shapeTensor       1D Int32 or Int64 tensor. The result tensor shape

 *  @param      name                      The name for the operation

 *

 *  @return     A valid MPSGraphTensor object

 */

-(MPSGraphTensor *) reshapeTensor:(MPSGraphTensor *) tensor

                  withShapeTensor:(MPSGraphTensor *) shapeTensor

                             name:(NSString * _Nullable) name

MPS_CLASS_AVAILABLE_STARTING(macos(12.0), ios(15.0), tvos(15.0))

MPS_SWIFT_NAME( reshape(_:shapeTensor:name:) );
Computed Shape for MPSGraph.reshape
 
 
Q