Skip to content

Commit

Permalink
Fixed bug in node in command-line ONNX parser (#858)
Browse files Browse the repository at this point in the history
* Fixed bug in node in command-line ONNX parser

* Fix formatting issues
  • Loading branch information
MatthewDaggitt authored Jan 28, 2025
1 parent 9cf8189 commit 391e7ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Release
- Adding incremental infrastructure which allows pushing and popping constraints to/from the InputQuery.
- Dropped support for parsing Tensorflow network format. Newest Marabou version that supports Tensorflow is at commit 190555573e4702.
- Fixed bug in the parsing of `transpose` nodes in command line C++ parser.

## Version 2.0.0

Expand Down
2 changes: 1 addition & 1 deletion src/input_parsers/TensorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ calculatePaddingNeeded( int inputSize, int filterSize, int stride, bool padFront
Permutation reversePermutation( unsigned int size )
{
Permutation result;
for ( unsigned int i = size - 1; i-- > 0; )
for ( unsigned int i = size; i-- > 0; )
{
result.append( i );
}
Expand Down
16 changes: 9 additions & 7 deletions src/input_parsers/TensorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ TensorIndices unpackIndex( TensorShape shape, PackedTensorIndices packedIndex );

PackedTensorIndices packIndex( TensorShape shape, TensorIndices indices );

unsigned int tensorSize( TensorShape shape );

template <typename T> T tensorLookup( Vector<T> tensor, TensorShape shape, TensorIndices indices )
{
return tensor[packIndex( shape, indices )];
Expand All @@ -77,20 +79,20 @@ Vector<T> transposeTensor( Vector<T> tensor, TensorShape shape, Permutation perm
// NOTE this implementation is *very* inefficient. Eventually we might want to
// switch to a similar implementation as NumPy arrays with internal strides etc.
ASSERT( shape.size() == permutation.size() );
ASSERT( tensorSize( shape ) == tensor.size() );

TensorShape transposedShape = transposeVector( shape, permutation );
Vector<T> result( tensor.size() );
for ( PackedTensorIndices rawOutputIndex = 0; rawOutputIndex < tensor.size(); rawOutputIndex++ )
for ( PackedTensorIndices rawInputIndex = 0; rawInputIndex < tensor.size(); rawInputIndex++ )
{
TensorIndices outputIndex = unpackIndex( transposedShape, rawOutputIndex );
TensorIndices inputIndex = transposeVector( outputIndex, permutation );
T value = tensorLookup( tensor, shape, inputIndex );
result[rawOutputIndex] = value;
TensorIndices inputIndex = unpackIndex( shape, rawInputIndex );
TensorIndices outputIndex = transposeVector( inputIndex, permutation );
int rawOutputIndex = packIndex( transposedShape, outputIndex );
result[rawOutputIndex] = tensor[rawInputIndex];
}
return result;
}

unsigned int tensorSize( TensorShape shape );

// See https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md#multidirectional-broadcasting
TensorShape getMultidirectionalBroadcastShape( TensorShape shape1, TensorShape shape2 );

Expand Down

0 comments on commit 391e7ec

Please sign in to comment.