You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Create this sample from a u32, trying to represent the same numerical value
124
126
fnfrom_u32(value:u32) -> Self;
127
+
128
+
/// Convert all values from the slice into this type.
129
+
/// This function exists to allow the compiler to perform a vectorization optimization.
130
+
/// Note that this default implementation will **not** be vectorized by the compiler automatically.
131
+
/// For maximum performance you will need to override this function and implement it via
132
+
/// an explicit batched conversion such as [`convert_to_f32_slice`](https://docs.rs/half/2.3.1/half/slice/trait.HalfFloatSliceExt.html#tymethod.convert_to_f32_slice)
133
+
#[inline]
134
+
fnfrom_f16s(from:&[f16],to:&mut[Self]){
135
+
assert_eq!(from.len(), to.len(),"slices must have the same length");
136
+
for(from, to)in from.iter().zip(to.iter_mut()){
137
+
*to = Self::from_f16(*from);
138
+
}
139
+
}
140
+
141
+
/// Convert all values from the slice into this type.
142
+
/// This function exists to allow the compiler to perform a vectorization optimization.
143
+
/// Note that this default implementation will be vectorized by the compiler automatically.
144
+
#[inline]
145
+
fnfrom_f32s(from:&[f32],to:&mut[Self]){
146
+
assert_eq!(from.len(), to.len(),"slices must have the same length");
147
+
for(from, to)in from.iter().zip(to.iter_mut()){
148
+
*to = Self::from_f32(*from);
149
+
}
150
+
}
151
+
152
+
/// Convert all values from the slice into this type.
153
+
/// This function exists to allow the compiler to perform a vectorization optimization.
154
+
/// Note that this default implementation will be vectorized by the compiler automatically,
155
+
/// provided that the CPU supports the necessary conversion instructions.
156
+
/// For example, x86_64 lacks the instructions to convert `u32` to floats,
157
+
/// so this will inevitably be slow on x86_64.
158
+
#[inline]
159
+
fnfrom_u32s(from:&[u32],to:&mut[Self]){
160
+
assert_eq!(from.len(), to.len(),"slices must have the same length");
161
+
for(from, to)in from.iter().zip(to.iter_mut()){
162
+
*to = Self::from_u32(*from);
163
+
}
164
+
}
125
165
}
126
166
127
167
// TODO haven't i implemented this exact behaviour already somewhere else in this library...??
128
168
implFromNativeSampleforf32{
129
-
fnfrom_f16(value:f16) -> Self{ value.to_f32()}
130
-
fnfrom_f32(value:f32) -> Self{ value }// this branch means that we never have to match every single sample if the file format matches the expected output
0 commit comments