dmlc / dmlc/dgl

fn.copy_u fails for bool and int type, but user-defined function works

Open
#3,717 2 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

`fn.copy_u` leads to `DGLError: Feature data must be float type` for `bool` and `int` arrays. But equivalent UDF works fine.

I encouter this problem when trying to pass boolean mask from node to edge -- to mark special edges for later use.

## To Reproduce

```python
import dgl
import dgl.function as fn
import torch

g = dgl.graph(([0, 0, 1, 5], [1, 2, 2, 0]))
node_mask = torch.tensor([1, 0, 0, 1, 0, 1], dtype=torch.bool)
g.ndata['node_mask'] = node_mask

g.apply_edges(lambda edges: {'edge_mask' : edges.src['node_mask']})
print(g.edata['edge_mask']) # tensor([ True, True, False, True])

g.apply_edges(fn.copy_u('node_mask', 'edge_mask')) # DGLError
```

The error message:
```
/opt/dgl/src/array/kernel.cc:126: Check failed: (out->dtype).code == kDLFloat ( vs. 2) : Feature data must be float type
```

Should this be considered as a bug, or expected? `fn.copy_u` should better facilitate fused optimizations than custom lambda, and such optimized kernels might require float type?

## Environment

- DGL 0.7.2
- PyTorch 1.10.1 (cpu backend)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.