1use crate::prelude_dev::*;
4use core::mem::ManuallyDrop;
5use num::complex::{Complex32, Complex64};
6
7pub trait AsArrayAPI<Inp> {
12 type Out;
13
14 fn asarray_f(self) -> Result<Self::Out>;
15
16 fn asarray(self) -> Self::Out
17 where
18 Self: Sized,
19 {
20 Self::asarray_f(self).rstsr_unwrap()
21 }
22}
23
24pub fn asarray<Args, Inp>(param: Args) -> Args::Out
301where
302 Args: AsArrayAPI<Inp>,
303{
304 return AsArrayAPI::asarray(param);
305}
306
307pub fn asarray_f<Args, Inp>(param: Args) -> Result<Args::Out>
313where
314 Args: AsArrayAPI<Inp>,
315{
316 return AsArrayAPI::asarray_f(param);
317}
318
319impl<R, T, B, D> AsArrayAPI<()> for (&TensorAny<R, T, B, D>, TensorIterOrder)
322where
323 R: DataAPI<Data = <B as DeviceRawAPI<T>>::Raw>,
324 T: Clone,
325 D: DimAPI,
326 B: DeviceAPI<T> + DeviceRawAPI<MaybeUninit<T>> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
327{
328 type Out = Tensor<T, B, D>;
329
330 fn asarray_f(self) -> Result<Self::Out> {
331 let (input, order) = self;
332 let device = input.device();
333 let layout_a = input.layout();
334 let layout_c = layout_for_array_copy(layout_a, order)?;
335 let mut storage_c = device.uninit_impl(layout_c.size())?;
336 device.assign_uninit(storage_c.raw_mut(), &layout_c, input.raw(), layout_a)?;
337 let storage_c = unsafe { B::assume_init_impl(storage_c) }?;
338 let tensor = Tensor::new_f(storage_c, layout_c)?;
339 return Ok(tensor);
340 }
341}
342
343impl<R, T, B, D> AsArrayAPI<()> for &TensorAny<R, T, B, D>
344where
345 R: DataAPI<Data = <B as DeviceRawAPI<T>>::Raw>,
346 T: Clone,
347 D: DimAPI,
348 B: DeviceAPI<T> + DeviceRawAPI<MaybeUninit<T>> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
349{
350 type Out = Tensor<T, B, D>;
351
352 fn asarray_f(self) -> Result<Self::Out> {
353 asarray_f((self, TensorIterOrder::default()))
354 }
355}
356
357impl<T, B, D> AsArrayAPI<()> for (Tensor<T, B, D>, TensorIterOrder)
358where
359 T: Clone,
360 D: DimAPI,
361 B: DeviceAPI<T> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
362{
363 type Out = Tensor<T, B, D>;
364
365 fn asarray_f(self) -> Result<Self::Out> {
366 let (input, order) = self;
367 let storage_a = input.storage();
368 let layout_a = input.layout();
369 let device = storage_a.device();
370 let layout_c = layout_for_array_copy(layout_a, order)?;
371 if layout_c == *layout_a {
372 return Ok(input);
373 } else {
374 let mut storage_c = device.uninit_impl(layout_c.size())?;
375 device.assign_uninit(storage_c.raw_mut(), &layout_c, storage_a.raw(), layout_a)?;
376 let storage_c = unsafe { B::assume_init_impl(storage_c) }?;
377 let tensor = Tensor::new_f(storage_c, layout_c)?;
378 return Ok(tensor);
379 }
380 }
381}
382
383impl<T, B, D> AsArrayAPI<()> for Tensor<T, B, D>
384where
385 T: Clone,
386 D: DimAPI,
387 B: DeviceAPI<T> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
388{
389 type Out = Tensor<T, B, D>;
390
391 fn asarray_f(self) -> Result<Self::Out> {
392 asarray_f((self, TensorIterOrder::default()))
393 }
394}
395
396impl<T, B, D> AsArrayAPI<()> for (TensorView<'_, T, B, D>, TensorIterOrder)
397where
398 T: Clone,
399 D: DimAPI,
400 B: DeviceAPI<T> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
401{
402 type Out = Tensor<T, B, D>;
403
404 fn asarray_f(self) -> Result<Self::Out> {
405 let (input, order) = self;
406 asarray_f((&input, order))
407 }
408}
409
410impl<T, B, D> AsArrayAPI<()> for TensorView<'_, T, B, D>
411where
412 T: Clone,
413 D: DimAPI,
414 B: DeviceAPI<T> + DeviceCreationAnyAPI<T> + OpAssignAPI<T, D>,
415{
416 type Out = Tensor<T, B, D>;
417
418 fn asarray_f(self) -> Result<Self::Out> {
419 asarray_f((self, TensorIterOrder::default()))
420 }
421}
422
423impl<T, B> AsArrayAPI<()> for (Vec<T>, &B)
428where
429 B: DeviceAPI<T> + DeviceCreationAnyAPI<T>,
430{
431 type Out = Tensor<T, B, IxD>;
432
433 fn asarray_f(self) -> Result<Self::Out> {
434 let (input, device) = self;
435 let layout = vec![input.len()].c();
436 let storage = device.outof_cpu_vec(input)?;
437 let tensor = Tensor::new_f(storage, layout)?;
438 return Ok(tensor);
439 }
440}
441
442impl<T, B, D> AsArrayAPI<D> for (Vec<T>, Layout<D>, &B)
443where
444 D: DimAPI,
445 B: DeviceAPI<T> + DeviceCreationAnyAPI<T>,
446{
447 type Out = Tensor<T, B, IxD>;
448
449 fn asarray_f(self) -> Result<Self::Out> {
450 let (input, layout, device) = self;
451 rstsr_assert_eq!(
452 layout.bounds_index()?,
453 (0, layout.size()),
454 InvalidLayout,
455 "This constructor assumes compact memory layout."
456 )?;
457 rstsr_assert_eq!(
458 layout.size(),
459 input.len(),
460 InvalidLayout,
461 "This constructor assumes that the layout size is equal to the input size."
462 )?;
463 let storage = device.outof_cpu_vec(input)?;
464 let tensor = Tensor::new_f(storage, layout.into_dim()?)?;
465 return Ok(tensor);
466 }
467}
468
469impl<T, B, D> AsArrayAPI<D> for (Vec<T>, D, &B)
470where
471 D: DimAPI,
472 B: DeviceAPI<T> + DeviceCreationAnyAPI<T>,
473{
474 type Out = Tensor<T, B, IxD>;
475
476 fn asarray_f(self) -> Result<Self::Out> {
477 let (input, shape, device) = self;
478 let default_order = device.default_order();
479 let layout = match default_order {
480 RowMajor => shape.c(),
481 ColMajor => shape.f(),
482 };
483 asarray_f((input, layout, device))
484 }
485}
486
487impl<T> AsArrayAPI<()> for Vec<T>
488where
489 T: Clone,
490{
491 type Out = Tensor<T, DeviceCpu, IxD>;
492
493 fn asarray_f(self) -> Result<Self::Out> {
494 asarray_f((self, &DeviceCpu::default()))
495 }
496}
497
498#[duplicate_item(L; [D]; [Layout<D>])]
499impl<T, D> AsArrayAPI<D> for (Vec<T>, L)
500where
501 T: Clone,
502 D: DimAPI,
503{
504 type Out = Tensor<T, DeviceCpu, IxD>;
505
506 fn asarray_f(self) -> Result<Self::Out> {
507 let (input, layout) = self;
508 asarray_f((input, layout, &DeviceCpu::default()))
509 }
510}
511
512impl<T> From<Vec<T>> for Tensor<T, DeviceCpu, IxD>
513where
514 T: Clone,
515{
516 fn from(input: Vec<T>) -> Self {
517 asarray_f(input).rstsr_unwrap()
518 }
519}
520
521impl<'a, T, B, D> AsArrayAPI<D> for (&'a [T], Layout<D>, &B)
526where
527 T: Clone,
528 B: DeviceAPI<T, Raw = Vec<T>>,
529 D: DimAPI,
530{
531 type Out = TensorView<'a, T, B, IxD>;
532
533 fn asarray_f(self) -> Result<Self::Out> {
534 let (input, layout, device) = self;
535 let ptr = input.as_ptr();
536 let len = input.len();
537 let raw = unsafe {
538 let ptr = ptr as *mut T;
539 Vec::from_raw_parts(ptr, len, len)
540 };
541 let device = device.clone();
542 let data = DataRef::from_manually_drop(ManuallyDrop::new(raw));
543 let storage = Storage::new(data, device);
544 let tensor = TensorView::new_f(storage, layout.into_dim()?)?;
545 return Ok(tensor);
546 }
547}
548
549impl<'a, T, B, D> AsArrayAPI<D> for (&'a [T], D, &B)
550where
551 T: Clone,
552 B: DeviceAPI<T, Raw = Vec<T>>,
553 D: DimAPI,
554{
555 type Out = TensorView<'a, T, B, IxD>;
556
557 fn asarray_f(self) -> Result<Self::Out> {
558 let (input, shape, device) = self;
559 let default_order = device.default_order();
560 let layout = match default_order {
561 RowMajor => shape.c(),
562 ColMajor => shape.f(),
563 };
564 asarray_f((input, layout, device))
565 }
566}
567
568impl<'a, T, B> AsArrayAPI<()> for (&'a [T], &B)
569where
570 T: Clone,
571 B: DeviceAPI<T, Raw = Vec<T>>,
572{
573 type Out = TensorView<'a, T, B, IxD>;
574
575 fn asarray_f(self) -> Result<Self::Out> {
576 let (input, device) = self;
577 let layout = vec![input.len()].c();
578 let device = device.clone();
579
580 let ptr = input.as_ptr();
581 let len = input.len();
582 let raw = unsafe {
583 let ptr = ptr as *mut T;
584 Vec::from_raw_parts(ptr, len, len)
585 };
586 let data = DataRef::from_manually_drop(ManuallyDrop::new(raw));
587 let storage = Storage::new(data, device);
588 let tensor = TensorView::new_f(storage, layout)?;
589 return Ok(tensor);
590 }
591}
592
593#[duplicate_item(L; [D]; [Layout<D>])]
594impl<'a, T, D> AsArrayAPI<D> for (&'a [T], L)
595where
596 T: Clone,
597 D: DimAPI,
598{
599 type Out = TensorView<'a, T, DeviceCpu, IxD>;
600
601 fn asarray_f(self) -> Result<Self::Out> {
602 let (input, layout) = self;
603 asarray_f((input, layout, &DeviceCpu::default()))
604 }
605}
606
607impl<'a, T> AsArrayAPI<()> for &'a [T]
608where
609 T: Clone,
610{
611 type Out = TensorView<'a, T, DeviceCpu, IxD>;
612
613 fn asarray_f(self) -> Result<Self::Out> {
614 asarray_f((self, &DeviceCpu::default()))
615 }
616}
617
618#[duplicate_item(L; [D]; [Layout<D>])]
619impl<'a, T, B, D> AsArrayAPI<D> for (&'a Vec<T>, L, &B)
620where
621 T: Clone,
622 B: DeviceAPI<T, Raw = Vec<T>> + 'a,
623 D: DimAPI,
624{
625 type Out = TensorView<'a, T, B, IxD>;
626
627 fn asarray_f(self) -> Result<Self::Out> {
628 let (input, layout, device) = self;
629 asarray_f((input.as_slice(), layout, device))
630 }
631}
632
633impl<'a, T, B> AsArrayAPI<()> for (&'a Vec<T>, &B)
634where
635 T: Clone,
636 B: DeviceAPI<T, Raw = Vec<T>>,
637{
638 type Out = TensorView<'a, T, B, IxD>;
639
640 fn asarray_f(self) -> Result<Self::Out> {
641 let (input, device) = self;
642 asarray_f((input.as_slice(), device))
643 }
644}
645
646#[duplicate_item(L; [D]; [Layout<D>])]
647impl<'a, T, D> AsArrayAPI<D> for (&'a Vec<T>, L)
648where
649 T: Clone,
650 D: DimAPI,
651{
652 type Out = TensorView<'a, T, DeviceCpu, IxD>;
653
654 fn asarray_f(self) -> Result<Self::Out> {
655 let (input, layout) = self;
656 asarray_f((input.as_slice(), layout, &DeviceCpu::default()))
657 }
658}
659
660impl<'a, T> AsArrayAPI<()> for &'a Vec<T>
661where
662 T: Clone,
663{
664 type Out = TensorView<'a, T, DeviceCpu, IxD>;
665
666 fn asarray_f(self) -> Result<Self::Out> {
667 asarray_f((self.as_slice(), &DeviceCpu::default()))
668 }
669}
670
671impl<'a, T> From<&'a [T]> for TensorView<'a, T, DeviceCpu, IxD>
672where
673 T: Clone,
674{
675 fn from(input: &'a [T]) -> Self {
676 asarray(input)
677 }
678}
679
680impl<'a, T> From<&'a Vec<T>> for TensorView<'a, T, DeviceCpu, IxD>
681where
682 T: Clone,
683{
684 fn from(input: &'a Vec<T>) -> Self {
685 asarray(input)
686 }
687}
688
689impl<'a, T, B, D> AsArrayAPI<D> for (&'a mut [T], Layout<D>, &B)
694where
695 T: Clone,
696 B: DeviceAPI<T, Raw = Vec<T>>,
697 D: DimAPI,
698{
699 type Out = TensorMut<'a, T, B, IxD>;
700
701 fn asarray_f(self) -> Result<Self::Out> {
702 let (input, layout, device) = self;
703 let ptr = input.as_ptr();
704 let len = input.len();
705 let raw = unsafe {
706 let ptr = ptr as *mut T;
707 Vec::from_raw_parts(ptr, len, len)
708 };
709 let device = device.clone();
710 let data = DataMut::from_manually_drop(ManuallyDrop::new(raw));
711 let storage = Storage::new(data, device);
712 let tensor = TensorMut::new_f(storage, layout.into_dim()?)?;
713 return Ok(tensor);
714 }
715}
716
717impl<'a, T, B, D> AsArrayAPI<D> for (&'a mut [T], D, &B)
718where
719 T: Clone,
720 B: DeviceAPI<T, Raw = Vec<T>>,
721 D: DimAPI,
722{
723 type Out = TensorMut<'a, T, B, IxD>;
724
725 fn asarray_f(self) -> Result<Self::Out> {
726 let (input, shape, device) = self;
727 let default_order = device.default_order();
728 let layout = match default_order {
729 RowMajor => shape.c(),
730 ColMajor => shape.f(),
731 };
732 asarray_f((input, layout, device))
733 }
734}
735
736impl<'a, T, B> AsArrayAPI<()> for (&'a mut [T], &B)
737where
738 T: Clone,
739 B: DeviceAPI<T, Raw = Vec<T>>,
740{
741 type Out = TensorMut<'a, T, B, IxD>;
742
743 fn asarray_f(self) -> Result<Self::Out> {
744 let (input, device) = self;
745 let layout = [input.len()].c();
746 let device = device.clone();
747
748 let ptr = input.as_ptr();
749 let len = input.len();
750 let raw = unsafe {
751 let ptr = ptr as *mut T;
752 Vec::from_raw_parts(ptr, len, len)
753 };
754 let data = DataMut::from_manually_drop(ManuallyDrop::new(raw));
755 let storage = Storage::new(data, device);
756 let tensor = TensorMut::new_f(storage, layout.into_dim()?)?;
757 return Ok(tensor);
758 }
759}
760
761#[duplicate_item(L; [D]; [Layout<D>])]
762impl<'a, T, D> AsArrayAPI<D> for (&'a mut [T], L)
763where
764 T: Clone,
765 D: DimAPI,
766{
767 type Out = TensorMut<'a, T, DeviceCpu, IxD>;
768
769 fn asarray_f(self) -> Result<Self::Out> {
770 let (input, layout) = self;
771 asarray_f((input, layout, &DeviceCpu::default()))
772 }
773}
774
775impl<'a, T> AsArrayAPI<()> for &'a mut [T]
776where
777 T: Clone,
778{
779 type Out = TensorMut<'a, T, DeviceCpu, IxD>;
780
781 fn asarray_f(self) -> Result<Self::Out> {
782 asarray_f((self, &DeviceCpu::default()))
783 }
784}
785
786#[duplicate_item(L; [D]; [Layout<D>])]
787impl<'a, T, B, D> AsArrayAPI<D> for (&'a mut Vec<T>, L, &B)
788where
789 T: Clone,
790 B: DeviceAPI<T, Raw = Vec<T>>,
791 D: DimAPI,
792{
793 type Out = TensorMut<'a, T, B, IxD>;
794
795 fn asarray_f(self) -> Result<Self::Out> {
796 let (input, layout, device) = self;
797 asarray_f((input.as_mut_slice(), layout, device))
798 }
799}
800
801impl<'a, T, B> AsArrayAPI<()> for (&'a mut Vec<T>, &B)
802where
803 T: Clone,
804 B: DeviceAPI<T, Raw = Vec<T>>,
805{
806 type Out = TensorMut<'a, T, B, IxD>;
807
808 fn asarray_f(self) -> Result<Self::Out> {
809 let (input, device) = self;
810 asarray_f((input.as_mut_slice(), device))
811 }
812}
813
814#[duplicate_item(L; [D]; [Layout<D>])]
815impl<'a, T, D> AsArrayAPI<D> for (&'a mut Vec<T>, L)
816where
817 T: Clone,
818 D: DimAPI,
819{
820 type Out = TensorMut<'a, T, DeviceCpu, IxD>;
821
822 fn asarray_f(self) -> Result<Self::Out> {
823 let (input, layout) = self;
824 asarray_f((input.as_mut_slice(), layout, &DeviceCpu::default()))
825 }
826}
827
828impl<'a, T> AsArrayAPI<()> for &'a mut Vec<T>
829where
830 T: Clone,
831{
832 type Out = TensorMut<'a, T, DeviceCpu, IxD>;
833
834 fn asarray_f(self) -> Result<Self::Out> {
835 asarray_f((self.as_mut_slice(), &DeviceCpu::default()))
836 }
837}
838
839impl<'a, T> From<&'a mut [T]> for TensorMut<'a, T, DeviceCpu, IxD>
840where
841 T: Clone,
842{
843 fn from(input: &'a mut [T]) -> Self {
844 asarray(input)
845 }
846}
847
848impl<'a, T> From<&'a mut Vec<T>> for TensorMut<'a, T, DeviceCpu, IxD>
849where
850 T: Clone,
851{
852 fn from(input: &'a mut Vec<T>) -> Self {
853 asarray(input)
854 }
855}
856
857macro_rules! impl_asarray_scalar {
862 ($($t:ty),*) => {
863 $(
864 impl<B> AsArrayAPI<()> for ($t, &B)
865 where
866 B: DeviceAPI<$t> + DeviceCreationAnyAPI<$t>,
867 {
868 type Out = Tensor<$t, B, IxD>;
869
870 fn asarray_f(self) -> Result<Self::Out> {
871 let (input, device) = self;
872 let layout = Layout::new(vec![], vec![], 0)?;
873 let storage = device.outof_cpu_vec(vec![input])?;
874 let tensor = unsafe { Tensor::new_unchecked(storage, layout) };
875 return Ok(tensor);
876 }
877 }
878
879 impl AsArrayAPI<()> for $t {
880 type Out = Tensor<$t, DeviceCpu, IxD>;
881
882 fn asarray_f(self) -> Result<Self::Out> {
883 asarray_f((self, &DeviceCpu::default()))
884 }
885 }
886 )*
887 };
888}
889
890impl_asarray_scalar!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64, Complex32, Complex64);
891
892#[cfg(test)]
895mod tests {
896 use super::*;
897
898 #[test]
899 fn test_asarray() {
900 let input = vec![1, 2, 3];
901 let tensor = asarray_f(input).unwrap();
902 println!("{tensor:?}");
903 let input = [1, 2, 3];
904 let tensor = asarray_f(input.as_ref()).unwrap();
905 println!("{tensor:?}");
906
907 let input = vec![1, 2, 3];
908 let tensor = asarray_f(&input).unwrap();
909 println!("{:?}", tensor.raw().as_ptr());
910 println!("{tensor:?}");
911
912 let tensor = asarray_f((&tensor, TensorIterOrder::K)).unwrap();
913 println!("{tensor:?}");
914
915 let tensor = asarray_f((tensor, TensorIterOrder::K)).unwrap();
916 println!("{tensor:?}");
917 }
918
919 #[test]
920 fn test_asarray_scalar() {
921 let tensor = asarray_f(1).unwrap();
922 println!("{tensor:?}");
923 let tensor = asarray_f((Complex64::new(0., 1.), &DeviceCpuSerial::default())).unwrap();
924 println!("{tensor:?}");
925 }
926
927 #[test]
928 fn doc_asarray() {
929 use rstsr::prelude::*;
930 let mut device = DeviceCpu::default();
931 device.set_default_order(RowMajor);
932
933 let input = vec![1, 2, 3, 4, 5, 6];
935 let a = rt::asarray((input, [2, 3], &device));
936 println!("{a:?}");
937 let expected = rt::tensor_from_nested!([[1, 2, 3], [4, 5, 6]], &device);
941 assert!(rt::allclose(&a, &expected, None));
942
943 let input = vec![1, 2, 3, 4, 5, 6];
945 let a = rt::asarray((input, [2, 3].f(), &device));
946 println!("{a:?}");
947 let expected = rt::tensor_from_nested!([[1, 3, 5], [2, 4, 6]], &device);
951 assert!(rt::allclose(&a, &expected, None));
952
953 device.set_default_order(ColMajor);
955 let input = vec![1, 2, 3, 4, 5, 6];
956 let a = rt::asarray((input, [2, 3], &device));
957 println!("{a:?}");
958 let expected = rt::tensor_from_nested!([[1, 3, 5], [2, 4, 6]], &device);
962 assert!(rt::allclose(&a, &expected, None));
963
964 let input = vec![1, 2, 3, 4, 5, 6];
966 let a = rt::asarray(input);
967 println!("{a:?}");
968 let expected = rt::tensor_from_nested!([1, 2, 3, 4, 5, 6]);
971 assert!(rt::allclose(&a, &expected, None));
972
973 device.set_default_order(RowMajor);
975 let input = &[1, 2, 3, 4, 5, 6];
976 let a = rt::asarray((input.as_ref(), [2, 3].c(), &device));
977 println!("{a:?}");
978 let expected = rt::tensor_from_nested!([[1, 2, 3], [4, 5, 6]], &device);
981 assert!(rt::allclose(&a, &expected, None));
982
983 let mut input = vec![1, 2, 3, 4, 5, 6];
985 let mut a = rt::asarray((&mut input, [2, 3].c(), &device));
986 a[[0, 0]] = 10;
988 println!("{a:2?}");
989 let expected = rt::tensor_from_nested!([[10, 2, 3], [4, 5, 6]], &device);
992 assert!(rt::allclose(&a, &expected, None));
993 println!("{input:?}");
994 assert_eq!(input, vec![10, 2, 3, 4, 5, 6]);
996
997 let input = (0..30).collect::<Vec<i32>>();
999 let layout = Layout::new([3, 2], [2, 7], 5).unwrap();
1000 let a = rt::asarray((&input, layout, &device));
1001 println!("{a:2?}");
1002 let expected = rt::tensor_from_nested!([[5, 12], [7, 14], [9, 16]], &device);
1006 assert!(rt::allclose(&a, &expected, None));
1007
1008 let a = rt::asarray((42, &device));
1010 println!("{a:?}");
1011 }
1014
1015 #[test]
1016 fn doc_asarray_from_tensor() {
1017 use rstsr::prelude::*;
1018 let mut device = DeviceCpu::default();
1019 device.set_default_order(RowMajor);
1020
1021 let a_raw = rt::arange((96, &device)).into_shape([4, 6, 4]);
1023 let a = a_raw.i((..2, slice!(2, 6, 2), 2..)).into_transpose([1, 0, 2]);
1024 println!("{a:2?}");
1025 let expected = rt::tensor_from_nested!([[[10, 11], [34, 35]], [[18, 19], [42, 43]]], &device);
1028 assert!(rt::allclose(&a, &expected, None));
1029 let b = rt::asarray((&a, TensorIterOrder::K));
1030 println!("{b:2?}");
1031 assert!(rt::allclose(&b, &expected, None));
1033 assert_eq!(b.stride(), &[2, 4, 1]);
1034 let b = rt::asarray((&a, TensorIterOrder::C));
1035 println!("{b:2?}");
1036 assert!(rt::allclose(&b, &expected, None));
1038 assert_eq!(b.stride(), &[4, 2, 1]);
1039 let b = rt::asarray((&a, TensorIterOrder::F));
1040 println!("{b:2?}");
1041 assert!(rt::allclose(&b, &expected, None));
1043 assert_eq!(b.stride(), &[1, 2, 4]);
1044 }
1045}