1e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower#
3e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# Licensed under the Apache License, Version 2.0 (the "License");
4e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# you may not use this file except in compliance with the License.
5e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# You may obtain a copy of the License at
6e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower#
7e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower#     http://www.apache.org/licenses/LICENSE-2.0
8e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower#
9e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# Unless required by applicable law or agreed to in writing, software
10e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# distributed under the License is distributed on an "AS IS" BASIS,
11e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# See the License for the specific language governing permissions and
13e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# limitations under the License.
14e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower# ==============================================================================
15e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower"""Libsvm decoder."""
16e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom __future__ import absolute_import
17e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom __future__ import division
18e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom __future__ import print_function
19e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
20e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom tensorflow.contrib.libsvm.ops import gen_libsvm_ops
21e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom tensorflow.contrib.util import loader
22e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom tensorflow.python.framework import ops
23e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom tensorflow.python.framework import sparse_tensor
24e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerfrom tensorflow.python.platform import resource_loader
25e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
26e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
27e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower_libsvm_ops_so = loader.load_op_library(
28e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    resource_loader.get_path_to_datafile("_libsvm_ops.so"))
29e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
30e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
31e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerdef decode_libsvm(content, num_features, dtype=None, label_dtype=None):
32e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  """Convert Libsvm records to a tensor of label and a tensor of feature.
33e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
34e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  Args:
35e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    content: A `Tensor` of type `string`. Each string is a record/row in
36e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower      the Libsvm format.
37e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    num_features: The number of features.
38e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    dtype: The type of the output feature tensor. Default to tf.float32.
39e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    label_dtype: The type of the output label tensor. Default to tf.int64.
40e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
41e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  Returns:
42e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    features: A `SparseTensor` of the shape `[input_shape, num_features]`.
43e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower    labels: A `Tensor` of the same shape as content.
44e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  """
45e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  labels, indices, values, shape = gen_libsvm_ops.decode_libsvm(
46e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower      content, num_features, dtype=dtype, label_dtype=label_dtype)
47e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower  return sparse_tensor.SparseTensor(indices, values, shape), labels
48e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
49e4532d20973c4c00854492362665317551661c18A. Unique TensorFlower
50e4532d20973c4c00854492362665317551661c18A. Unique TensorFlowerops.NotDifferentiable("DecodeLibSVM")
51