diff --git a/CHANGELOG.md b/CHANGELOG.md index cb8bd09ef..8ecc8e54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/input_parsers/TensorUtils.cpp b/src/input_parsers/TensorUtils.cpp index eab6aae7f..865a1419c 100644 --- a/src/input_parsers/TensorUtils.cpp +++ b/src/input_parsers/TensorUtils.cpp @@ -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 ); } diff --git a/src/input_parsers/TensorUtils.h b/src/input_parsers/TensorUtils.h index 295f8aac6..3d4607485 100644 --- a/src/input_parsers/TensorUtils.h +++ b/src/input_parsers/TensorUtils.h @@ -55,6 +55,8 @@ TensorIndices unpackIndex( TensorShape shape, PackedTensorIndices packedIndex ); PackedTensorIndices packIndex( TensorShape shape, TensorIndices indices ); +unsigned int tensorSize( TensorShape shape ); + template T tensorLookup( Vector tensor, TensorShape shape, TensorIndices indices ) { return tensor[packIndex( shape, indices )]; @@ -77,20 +79,20 @@ Vector transposeTensor( Vector 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 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 );