@@ -76,60 +76,61 @@ public static TFTensor CreateScalar<T>(T data)
76
76
/// </summary>
77
77
/// <typeparam name="T[]">.NET type of tensor to create</typeparam>
78
78
/// <param name="data">value of tensor</param>
79
+ /// <param name="count">The number of elements in the tensor</param>
79
80
/// <param name="shape">shape of tensor</param>
80
- public static TFTensor Create < T > ( T [ ] data , TFShape shape )
81
+ public static TFTensor Create < T > ( T [ ] data , int count , TFShape shape )
81
82
{
82
83
if ( typeof ( T ) == typeof ( System . Boolean ) )
83
84
{
84
- return new TFTensor ( SetupTensor ( TFDataType . Bool , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 4 ) ) ;
85
+ return new TFTensor ( SetupTensor ( TFDataType . Bool , shape , ( Array ) ( object ) data , 0 , count , 4 ) ) ;
85
86
}
86
87
else if ( typeof ( T ) == typeof ( System . Byte ) )
87
88
{
88
- return new TFTensor ( SetupTensor ( TFDataType . UInt8 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 1 ) ) ;
89
+ return new TFTensor ( SetupTensor ( TFDataType . UInt8 , shape , ( Array ) ( object ) data , 0 , count , 1 ) ) ;
89
90
}
90
91
else if ( typeof ( T ) == typeof ( System . Char ) )
91
92
{
92
- return new TFTensor ( SetupTensor ( TFDataType . UInt8 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 1 ) ) ;
93
+ return new TFTensor ( SetupTensor ( TFDataType . UInt8 , shape , ( Array ) ( object ) data , 0 , count , 1 ) ) ;
93
94
}
94
95
else if ( typeof ( T ) == typeof ( System . Numerics . Complex ) )
95
96
{
96
- return new TFTensor ( SetupTensor ( TFDataType . Complex128 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 16 ) ) ;
97
+ return new TFTensor ( SetupTensor ( TFDataType . Complex128 , shape , ( Array ) ( object ) data , 0 , count , 16 ) ) ;
97
98
}
98
99
else if ( typeof ( T ) == typeof ( System . Double ) )
99
100
{
100
- return new TFTensor ( SetupTensor ( TFDataType . Double , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 8 ) ) ;
101
+ return new TFTensor ( SetupTensor ( TFDataType . Double , shape , ( Array ) ( object ) data , 0 , count , 8 ) ) ;
101
102
}
102
103
else if ( typeof ( T ) == typeof ( System . Single ) )
103
104
{
104
- return new TFTensor ( SetupTensor ( TFDataType . Float , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 4 ) ) ;
105
+ return new TFTensor ( SetupTensor ( TFDataType . Float , shape , ( Array ) ( object ) data , 0 , count , 4 ) ) ;
105
106
}
106
107
else if ( typeof ( T ) == typeof ( System . Int32 ) )
107
108
{
108
- return new TFTensor ( SetupTensor ( TFDataType . Int32 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 4 ) ) ;
109
+ return new TFTensor ( SetupTensor ( TFDataType . Int32 , shape , ( Array ) ( object ) data , 0 , count , 4 ) ) ;
109
110
}
110
111
else if ( typeof ( T ) == typeof ( System . Int64 ) )
111
112
{
112
- return new TFTensor ( SetupTensor ( TFDataType . Int64 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 8 ) ) ;
113
+ return new TFTensor ( SetupTensor ( TFDataType . Int64 , shape , ( Array ) ( object ) data , 0 , count , 8 ) ) ;
113
114
}
114
115
else if ( typeof ( T ) == typeof ( System . SByte ) )
115
116
{
116
- return new TFTensor ( SetupTensor ( TFDataType . Int8 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 1 ) ) ;
117
+ return new TFTensor ( SetupTensor ( TFDataType . Int8 , shape , ( Array ) ( object ) data , 0 , count , 1 ) ) ;
117
118
}
118
119
else if ( typeof ( T ) == typeof ( System . Int16 ) )
119
120
{
120
- return new TFTensor ( SetupTensor ( TFDataType . Int16 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 2 ) ) ;
121
+ return new TFTensor ( SetupTensor ( TFDataType . Int16 , shape , ( Array ) ( object ) data , 0 , count , 2 ) ) ;
121
122
}
122
123
else if ( typeof ( T ) == typeof ( System . UInt32 ) )
123
124
{
124
- return new TFTensor ( SetupTensor ( TFDataType . UInt32 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 4 ) ) ;
125
+ return new TFTensor ( SetupTensor ( TFDataType . UInt32 , shape , ( Array ) ( object ) data , 0 , count , 4 ) ) ;
125
126
}
126
127
else if ( typeof ( T ) == typeof ( System . UInt64 ) )
127
128
{
128
- return new TFTensor ( SetupTensor ( TFDataType . UInt64 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 8 ) ) ;
129
+ return new TFTensor ( SetupTensor ( TFDataType . UInt64 , shape , ( Array ) ( object ) data , 0 , count , 8 ) ) ;
129
130
}
130
131
else if ( typeof ( T ) == typeof ( System . UInt16 ) )
131
132
{
132
- return new TFTensor ( SetupTensor ( TFDataType . UInt16 , shape , ( Array ) ( object ) data , 0 , ( ( Array ) ( object ) data ) . Length , 2 ) ) ;
133
+ return new TFTensor ( SetupTensor ( TFDataType . UInt16 , shape , ( Array ) ( object ) data , 0 , count , 2 ) ) ;
133
134
}
134
135
// note that we will get here for jagged arrays, which is intententional since we'd need to copy them.
135
136
throw new NotSupportedException ( $ "Unsupported type { typeof ( T ) } ") ;
0 commit comments