daphne-project / daphne-project/daphne

DaphneDSL map() on entire row/column

Open
#520 0 comments 0 reactions 0 assignees View on GitHub
AMLS summer 2023 AMLS summer 2024 AMLS summer 2025 student project
Dominant language
C++
Stars
81
Forks
83
PR merge metrics
No merged PRs in 30d

Description

**Motivation:** DaphneDSL supports the second-order function `map()`, which is well-known from other programming languages. Given a matrix and a user-defined function written in DaphneDSL, `map()` applies the given function to each element of the given matrix. For instance, the following script
```
def timesTwo(x) {return x*2;}
X = reshape([1, 2, 3, 4], 2, 2);
print(map(X, timesTwo));
```
results in the following output
```
DenseMatrix(2x2, int64_t)
2 4
6 8
```
Currently, `map()` supports only the mapping of individual cells of a matrix. For more expressiveness, it would be desirable to be able to map an entire row (or column) of the input matrix to an entire row (or column) of the output matrix. Custom row/column-wise aggregations would be one special case.

**Task:** This project is to extend the current implementation of `map()`, such that UDFs 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. This requires changes to the DaphneDSL parser, the DAPHNE compiler, and the `map()`-kernel. Implementation in C++.

**Hints:**
- Some example uses of `map()` that should be enabled:
```
# Returns the top-three elements of the
# given column matrix (column to column).
def topThree(col) {
return order(col)[:3];
}

print(map(X, top3));
```
```
# Returns the sum of the first and last element
# of the given row matrix (row to scalar).
def sumOfFirstAndLast(row) {
return as.scalar(row[0, 0]) + as.scalar(row[0, ncol(row) – 1]);
}

print(map(X, sumOfFirstAndLast));
```
Note that these are just simplified examples to demonstrate the idea.
Make sure you understand the existing `map()` implementation first.

Contributor guide

Open the contributing guide

Research direction

Start by understanding the existing map() implementation, then trace how DaphneDSL parsing and compilation represent user-defined functions and matrix dimensions. Update the parser, DAPHNE compiler, and map() kernel so row-to-row, column-to-column, and row/column-to-scalar mappings work, and validate the behavior with the top-three and first-and-last aggregation examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.