forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.ReShape.cs
More file actions
134 lines (123 loc) · 8.71 KB
/
NdArray.ReShape.cs
File metadata and controls
134 lines (123 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System.Diagnostics.CodeAnalysis;
namespace NumSharp
{
public partial class NDArray
{
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newShape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape(Shape newShape)
{
return reshape(ref newShape);
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newShape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape(ref Shape newShape)
{
var ret = Storage.Alias();
ret.Reshape(ref newShape, false);
return new NDArray(ret) {TensorEngine = TensorEngine};
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="shape">The new shape should be compatible with the original shape. If an integer, then the result will be a
/// 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array
/// and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the
/// memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape(params int[] shape)
{
var ret = Storage.Alias();
ret.Reshape(shape, false);
return new NDArray(ret) {TensorEngine = TensorEngine};
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="shape">The new shape should be compatible with the original shape. If an integer, then the result will be a
/// 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array
/// and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the
/// memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
[SuppressMessage("ReSharper", "ParameterHidesMember")]
protected internal NDArray reshape_broadcast(int[] shape, Shape? original)
{
var ret = Storage.Alias();
var newShape = new Shape(shape);
ret.ReshapeBroadcastedUnsafe(ref newShape, false, original);
return new NDArray(ret) {TensorEngine = TensorEngine};
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newshape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape_unsafe(Shape newshape)
{
return reshape_unsafe(ref newshape);
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newshape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <param name="originalUnbroadcasted"></param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape_unsafe(Shape newshape, Shape originalUnbroadcasted)
{
return reshape_broadcast(newshape.dimensions, originalUnbroadcasted);
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newshape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <param name="originalUnbroadcasted"></param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape_unsafe(int[] dimensions, Shape originalUnbroadcasted)
{
return reshape_broadcast(dimensions, originalUnbroadcasted);
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="newshape">The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
public NDArray reshape_unsafe(ref Shape newshape)
{
var ret = Storage.Alias();
ret.ReshapeBroadcastedUnsafe(ref newshape, false, newshape.BroadcastInfo?.OriginalShape);
return new NDArray(ret) {TensorEngine = TensorEngine};
}
/// <summary>
/// Gives a new shape to an array without changing its data.
/// </summary>
/// <param name="shape">The new shape should be compatible with the original shape. If an integer, then the result will be a
/// 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array
/// and remaining dimensions.</param>
/// <returns>This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the
/// memory layout (C- or Fortran- contiguous) of the returned array.</returns>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html</remarks>
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape_unsafe(params int[] shape)
{
var ret = Storage.Alias();
var newShape = new Shape(shape);
ret.ReshapeBroadcastedUnsafe(ref newShape, false);
return new NDArray(ret) {TensorEngine = TensorEngine};
}
}
}