@@ -612,12 +612,43 @@ impl<S, A, D> ArrayBase<S, D>
612
612
}
613
613
}
614
614
615
+ /// Create an array with copies of `elem`, dimension `dim` and fortran
616
+ /// ordering.
617
+ ///
618
+ /// ```
619
+ /// use ndarray::Array;
620
+ /// use ndarray::arr3;
621
+ ///
622
+ /// let a = Array::from_elem_f((2, 2, 2), 1.);
623
+ ///
624
+ /// assert!(
625
+ /// a == arr3(&[[[1., 1.],
626
+ /// [1., 1.]],
627
+ /// [[1., 1.],
628
+ /// [1., 1.]]])
629
+ /// );
630
+ /// assert!(a.strides() == &[1, 2, 4]);
631
+ /// ```
632
+ pub fn from_elem_f ( dim : D , elem : A ) -> ArrayBase < S , D > where A : Clone
633
+ {
634
+ let v = vec ! [ elem; dim. size( ) ] ;
635
+ unsafe {
636
+ Self :: from_vec_dim_f ( dim, v)
637
+ }
638
+ }
639
+
615
640
/// Create an array with zeros, dimension `dim`.
616
641
pub fn zeros ( dim : D ) -> ArrayBase < S , D > where A : Clone + libnum:: Zero
617
642
{
618
643
Self :: from_elem ( dim, libnum:: zero ( ) )
619
644
}
620
645
646
+ /// Create an array with zeros, dimension `dim` and fortran ordering.
647
+ pub fn zeros_f ( dim : D ) -> ArrayBase < S , D > where A : Clone + libnum:: Zero
648
+ {
649
+ Self :: from_elem_f ( dim, libnum:: zero ( ) )
650
+ }
651
+
621
652
/// Create an array with default values, dimension `dim`.
622
653
pub fn default ( dim : D ) -> ArrayBase < S , D >
623
654
where A : Default
@@ -642,6 +673,22 @@ impl<S, A, D> ArrayBase<S, D>
642
673
}
643
674
}
644
675
676
+ /// Create an array from a vector (with no allocation needed),
677
+ /// using fortran ordering to interpret the data.
678
+ ///
679
+ /// Unsafe because dimension is unchecked, and must be correct.
680
+ pub unsafe fn from_vec_dim_f ( dim : D , mut v : Vec < A > ) -> ArrayBase < S , D >
681
+ {
682
+ debug_assert ! ( dim. size( ) == v. len( ) ) ;
683
+ ArrayBase {
684
+ ptr : v. as_mut_ptr ( ) ,
685
+ data : DataOwned :: new ( v) ,
686
+ strides : dim. fortran_strides ( ) ,
687
+ dim : dim
688
+ }
689
+ }
690
+
691
+
645
692
/// Create an array from a vector and interpret it according to the
646
693
/// provided dimensions and strides. No allocation needed.
647
694
///
0 commit comments