clab/dynet

sparse_inputTensor() does not accept an empty list of indices

Open

#1,327 opened on 2018年3月26日

GitHub で見る
 (3 comments) (0 reactions) (0 assignees)C++ (701 forks)github user discovery
enhancementgood first issue

Repository metrics

Stars
 (3,433 stars)
PR merge metrics
 (PR metrics pending)

説明

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 "<stdin>", line 1, in <module>
  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

コントリビューターガイド