clab/dynet

sparse_inputTensor() does not accept an empty list of indices

Open

#1,327 创建于 2018年3月26日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)C++ (701 fork)github user discovery
enhancementgood first issue

仓库指标

Star
 (3,433 star)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南