[DAPHNE-#520] map() on entire row/column #973
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR extends the functionality of the
map()kernel to support row- and column-wise mapping in addition to the existing element-wise mapping. This means that now, UDFs that operate on entire rows/columns are supported. If the input of the UDF is a row matrix, the output can be a row or a scalar; if the input is a column matrix, the output can be a column or a scalar.Changes to DaphneDSL parser
Introduced two additional optional parameters:
axis(int64_t) andudfReturnsScalar(bool). By leaving out these parameters, the existing element-wise map operation can be performed unchanged. For a row-wise map, axis must be set to0, and for a column-wise map to1. Additionally, if the UDF returns a scalar and not a matrix, it is required to setudfReturnsScalar = true. Per default this is false. If this value does not match the UDFs output type, an error will be thrown during lowering of the UDF.Changes to DAPHNE compiler and IR
The shape of the result matrix is no longer always the same as the input matrix, but now depends on both
axisand the output type of the UDF (matrix or scalar). During the shape inference pass, the correct shape is set. This means, for an element-wise map the shape from the input matrix is preserved, while for a row- or column wise map one dimension stays the same while the other is unknown. Later, once the UDFs output type is known, the unknown dimension is set to1if the return type is a scalar (SeeSpecializeGenericFunctionsPass.cpp).Testing
Extensive test cases were added for row- and column-wise mapping, covering both matrices and scalars as possible UDF outputs. These test cases also show how the shape of the result matrix can shrink/grow compared to the input matrix. Some tests expect an error, e.g. if
axisorudfReturnsScalarhas the wrong value. All new tests can be found undertest/api/cli/secondorder, as well astest/runtime/local/kernels/MapTest.cpp.Limitations
DataObjectFactory::destroy(), due to the fact that this leads to the result matrix becoming a view and consequently a segmentation fault if the result is printed.Matrix(Map<Matrix<VTRes>, Matrix<VTArg>>) currently does not support column-wise mapping, if the UDF result is a matrix. This is because the functionappend()works only on strictly increasing coordinates.axisandudfReturnsScalarhave to be set explicitly and cannot be inferred.