sparse_inputTensor() does not accept an empty list of indices
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 701
- PR merge metrics
- No merged PRs in 30d
Description
In Python, the function `sparse_inputTensor()` does not accept an empty list of index/value pairs. However, it seems reasonable to have `sparse_inputTensor()` return a list consisting entirely of default values in this case. To illustrate:
```
>>> import dynet
[dynet] random seed: 982600208
[dynet] allocating memory: 512MB
[dynet] memory allocation done.
>>> dynet.sparse_inputTensor([[5]], [1], (10,)).value() # Works just fine
[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
>>> dynet.sparse_inputTensor([[]], [], (10,)) # Doesn't work
Traceback (most recent call last):
File "", line 1, in
File "_dynet.pyx", line 2305, in _dynet.sparse_inputTensor
TypeError: Iterator operand 0 dtype could not be cast from dtype('float64') to dtype('int64') according to the rule 'same_kind'
```
The expected output of the second line would be an expression with the value `[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]`.
This happens both on CPU and GPU.
DyNet version: 2.0.3
Python version: 3.6.4
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the Python binding entry point shown in _dynet.pyx around line 2305 and reproduce the empty-index call from the issue. Verify that sparse_inputTensor([[]], [], (10,)) works on CPU and GPU and returns an expression whose value contains ten default zeros.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100