internal static (NdArray <T1>, NdArray <T2>, NdArray <T3>) ApplyLayoutFn <T1, T2, T3>(Func <int[], Layout[], Layout[]> fn, int[] dims, NdArray <T1> src1, NdArray <T2> src2, NdArray <T3> src3)
        {
            var layouts    = new[] { src1.Layout, src2.Layout, src3.Layout };
            var newLayouts = fn(dims, layouts);

            if (newLayouts.Length == 3 && newLayouts[0] != null && newLayouts[1] != null && newLayouts[2] != null)
            {
                return(src1.Relayout(newLayouts[0]), src2.Relayout(newLayouts[1]), src3.Relayout(newLayouts[2]));
            }

            throw new InvalidOperationException("unexpected layout function result");
        }
Beispiel #2
0
 /// <summary>
 /// Returns a view of the diagonal along the given axes.
 /// </summary>
 /// <param name="ax1">The first dimension of the diagonal.</param>
 /// <param name="ax2">The seconds dimension of the diagonal.</param>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>A NdArray where dimension <paramref name="ax1"/> is the diagonal and dimension
 public static NdArray <T> DiagAxis(int ax1, int ax2, NdArray <T> source)
 {
     return(source.Relayout(Layout.DiagAxis(ax1, ax2, source.Layout)));
 }
Beispiel #3
0
 /// <summary>
 /// Transpose of a matrix.
 /// </summary>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The result of this operation.</returns>
 public static NdArray <T> Transpos(NdArray <T> source)
 {
     return(source.Relayout(Layout.Transpos(source.Layout)));
 }
 /// <summary>
 /// Broadcast a dimension to a specified size.
 /// </summary>
 /// <param name="dim">The size-one dimension to broadcast.</param>
 /// <param name="size">The size to broadcast to.</param>
 /// <param name="a">The NdArray to operate on.</param>
 /// <returns>The resulting NdArray.</returns>
 public static NdArray <T> BroadCastDim(int dim, int size, NdArray <T> source)
 {
     return(source.Relayout(Layout.BroadcastDim(dim, size, source.Layout)));
 }
 /// <summary>
 /// Reverses the elements in the specified dimension.
 /// </summary>
 /// <param name="axis">The axis to reverse.</param>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The NdArray with the dimensions Reversed.</returns>
 public static NdArray <T> ReverseAxis(int axis, NdArray <T> source)
 {
     return(source.Relayout(Layout.ReverseAxis(axis, source.Layout)));
 }
 /// <summary>
 /// Swaps the specified dimensions of the NdArray.
 /// </summary>
 /// <param name="axis1">The dimension to swap.</param>
 /// <param name="axis2">The dimension to swap with.</param>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The NdArray with the dimensions swapped.</returns>
 public static NdArray <T> SwapDim(int axis1, int axis2, NdArray <T> source)
 {
     return(source.Relayout(Layout.SwapDim(axis1, axis2, source.Layout)));
 }
 /// <summary>
 /// Permutes the axes as specified.
 /// </summary>
 /// <param name="permut">The permutation to apply to the dimensions of NdArray.</param>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The NdArray with the dimensions permuted.</returns>
 public static NdArray <T> PermuteAxes(int[] permut, NdArray <T> source)
 {
     return(source.Relayout(Layout.PermuteAxes(permut, source.Layout)));
 }
 /// <summary>
 /// Append a dimension of size one after the last dimension.
 /// </summary>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The resulting NdArray.</returns>
 public static NdArray <T> PadRight(NdArray <T> source)
 {
     return(source.Relayout(Layout.PadRight(source.Layout)));
 }
 /// <summary>
 /// Insert a dimension of size one before the specifed dimension.
 /// </summary>
 /// <param name="axis">The dimension to insert before.</param>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The resulting NdArray.</returns>
 public static NdArray <T> InsertAxis(int axis, NdArray <T> source)
 {
     return(source.Relayout(Layout.InsertAxis(axis, source.Layout)));
 }
 /// <summary>
 /// Removes the first dimension.
 /// </summary>
 /// <param name="source">The NdArray to operate on.</param>
 /// <returns>The resulting NdArray.</returns>
 public static NdArray <T> CutLeft(NdArray <T> source)
 {
     return(source.Relayout(Layout.CutLeft(source.Layout)));
 }
        /// <summary>
        /// Broadcasts the specified NdArray to the specified shape.
        /// </summary>
        /// <param name="shp">The target shape.</param>
        /// <param name="source">The NdArray to operate on.</param>
        /// <returns>NdArray of shape <paramref name="shp"/>.</returns>
        public static NdArray <T> BroadCastTo(int[] shp, NdArray <T> source)
        {
            var layout = Layout.BroadcastToShape(shp, source.Layout);

            return(source.Relayout(layout));
        }