ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

derived Debug for Iter and IterMut

Open biskwikman opened this issue 2 years ago • 2 comments

My attempt to implement Debug for Iter, I also did so for IterMut. #1204

Example:

input:

fn main() {
    let foo = ndarray::Array1::<f64>::zeros(10);
    println!("{:?}", std::iter::zip(0..foo.len(), &foo));
}

output:

Zip { a: 0..10, b: Iter { inner: Slice(Iter([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])) } }

biskwikman avatar Jan 29 '24 05:01 biskwikman

Update the description with one output example. Also, you left several lines of commented code.

nilgoyette avatar Jan 29 '24 14:01 nilgoyette

I see 2 problems:

  • Please also add the output of a 2D arrays so we know how it will be printed
  • Iter { inner: Slice(Iter([...])) } } is uselessly descriptive. The user doesn't want to know the technical architecture of ndarray, he simply wants to print the values in the iterator. I think you will be forced to code the function instead of using #[derive(Debug)] in order to control what you print.

nilgoyette avatar Jan 30 '24 15:01 nilgoyette

Rebased. It can be prettier and more logical but it's just a Debug fmt, so it can change later. Thanks, this is a good start for this.

bluss avatar Mar 10 '24 08:03 bluss