Is there an example of range related operation
Jzow opened this issue · comments
James Zow commented
this is my code
fn tf_ops_range() {
// Create a range op that produces [0, 1, 2, 3, 4, 5]
let mut scope = tensorflow::Scope::new_root_scope();
let start = tensorflow::ops::constant(0_i32, &mut scope);
let limit = tensorflow::ops::constant(6_i32, &mut scope);
let delta = tensorflow::ops::constant(1_i32, &mut scope);
let range_op = tensorflow::ops::range(start, limit, delta, &mut scope).unwrap();
}
// test tf_ops_range
#[test]
fn test_tf_ops_range() {
tf_ops_range();
}
report error:
let range_op = tensorflow::ops::range(start, limit, delta, &mut scope).unwrap();
| ---------------------- ^^^^^ the trait `From<Result<Operation, Status>>` is not implemented for `tensorflow::Output`
| |
| required by a bound introduced by this call
|
= help: the trait `From<Operation>` is implemented for `tensorflow::Output`
= note: required for `Result<Operation, Status>` to implement `Into<tensorflow::Output>`
I looked through the relevant documents, including the source code, but unfortunately I didn't see an example of how to use range
Shorthand for Range::new().build(start, limit, delta, scope)
.
James Zow commented
When I changed to the following code, he output the results as I expected. range -> constant
use tensorflow::{Scope as scope, Tensor};
fn tf_ops_range() {
let mut scope = scope::new_root_scope();
let x = tensorflow::ops::constant(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11][..], &mut scope).unwrap();
println!("x type: {:?}", x.get_attr_type("dtype").unwrap());
let value: Tensor<i32> = x.get_attr_tensor("value").unwrap();
println!("x value: {:?}", value);
}
// test tf_ops_range
#[test]
fn test_tf_ops_range() {
tf_ops_range();
}
I want to create a line vector x. The row vector contains the first 12 integers starting at 0, which are created by default as integers, for python example
import tensorflow as tf
x = tf.range(12)
println(x)
<tf.Tensor: shape=(12,), dtype=int32, numpy=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype=int32)>