【发布时间】:2019-02-27 00:29:15
【问题描述】:
我正在尝试让一些稀疏矩阵运算在 Tensorflow 中工作。我要处理的第一个是稀疏行列式,通过稀疏 Cholesky 分解。 Eigen 有一个稀疏的 Cholesky,所以我的想法是把它包装起来。
我已经取得了一些进展,但现在有点卡住了。我知道 Tensorflow 中的 SparseTensor 由三部分组成:indices、values 和 shape。复制类似的操作,我选择了以下REGISTER_OP 声明:
REGISTER_OP("SparseLogDet")
.Input("a_indices: int64")
.Input("a_values: float32")
.Input("a_shape: int64")
.Output("determinant: float32")
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
shape_inference::ShapeHandle h;
c->set_output(0, h);
return Status::OK();
});
这编译得很好,但是当我使用一些示例代码运行它时:
import tensorflow as tf
log_det_op = tf.load_op_library('./sparse_log_det_op.so')
with tf.Session(''):
t = tf.SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2],
dense_shape=[3, 4])
print(log_det_op.sparse_log_det(t).eval().shape)
print(log_det_op.sparse_log_det(t).eval())
它抱怨说:
TypeError: sparse_log_det() missing 2 required positional arguments: 'a_values' and 'a_shape'
这对我来说很有意义,因为它期待其他参数。但是,我真的只想传递稀疏张量,而不是将其分解为组件!有谁知道这是如何处理其他稀疏操作的?
谢谢!
【问题讨论】:
标签: c++ tensorflow