Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an example of range related operation #420

Open
Jzow opened this issue Dec 26, 2023 · 1 comment
Open

Is there an example of range related operation #420

Jzow opened this issue Dec 26, 2023 · 1 comment

Comments

@Jzow
Copy link

Jzow commented Dec 26, 2023

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).

@Jzow
Copy link
Author

Jzow commented Dec 26, 2023

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)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant