Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd3be3e

Browse files
umar4569prady9
authored andcommitted
Additional changes for f16 type
1 parent2fff932 commitbd3be3e

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

‎src/core/arith.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::defines::AfError;
44
usesuper::dim4::Dim4;
55
usesuper::error::HANDLE_ERROR;
66
usesuper::util::{af_array,HasAfEnum,ImplicitPromote,IntegralType};
7+
8+
use half::f16;
79
use num::Zero;
810

911
use libc::c_int;
@@ -758,6 +760,7 @@ arith_scalar_spec!(Complex<f64>);
758760
arith_scalar_spec!(Complex<f32>);
759761
arith_scalar_spec!(f64);
760762
arith_scalar_spec!(f32);
763+
arith_scalar_spec!(f16);
761764
arith_scalar_spec!(u64);
762765
arith_scalar_spec!(i64);
763766
arith_scalar_spec!(u32);

‎src/core/data.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::dim4::Dim4;
44
usesuper::error::HANDLE_ERROR;
55
usesuper::util::{af_array, c32, c64, dim_t, u64_t,HasAfEnum};
66

7+
use half::f16;
78
use libc::{c_double, c_int, c_uint};
89
use std::option::Option;
910
use std::vec::Vec;
@@ -231,6 +232,25 @@ impl ConstGenerator for bool {
231232
}
232233
}
233234

235+
implConstGeneratorforf16{
236+
typeOutType =f16;
237+
238+
fngenerate(&self,dims:Dim4) ->Array<Self::OutType>{
239+
unsafe{
240+
letmut temp:af_array = std::ptr::null_mut();
241+
let err_val =af_constant(
242+
&mut tempas*mutaf_array,
243+
f16::to_f64(*self),
244+
dims.ndims()asc_uint,
245+
dims.get().as_ptr()as*constdim_t,
246+
12,
247+
);
248+
HANDLE_ERROR(AfError::from(err_val));
249+
temp.into()
250+
}
251+
}
252+
}
253+
234254
macro_rules! cnst{
235255
($rust_type:ty, $ffi_type:expr) =>{
236256
implConstGeneratorfor $rust_type{

‎src/core/num.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
pubtraitZero{
23
fnzero() ->Self;
34
}
@@ -28,6 +29,7 @@ zero_impl!(i64, 0);
2829
zero_impl!(isize,0);
2930
zero_impl!(f32,0.0);
3031
zero_impl!(f64,0.0);
32+
zero_impl!(half::f16, half::f16::from_f32(0.0));
3133

3234
macro_rules! one_impl{
3335
( $t:ident, $o:expr) =>{
@@ -51,3 +53,4 @@ one_impl!(i64, 1);
5153
one_impl!(isize,1);
5254
one_impl!(f32,1.0);
5355
one_impl!(f64,1.0);
56+
one_impl!(half::f16, half::f16::from_f32(1.0));

‎src/core/util.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl HasAfEnum for f16 {
337337
typeAbsOutType =Self;
338338
typeArgOutType =Self;
339339
typeUnaryOutType =Self;
340-
typeComplexOutType =Complex<f16>;
340+
typeComplexOutType =Complex<f32>;
341341
typeMeanOutType =Self;
342342
typeAggregateOutType =f32;
343343
typeProductOutType =f32;
@@ -678,12 +678,18 @@ impl FloatingPoint for f32 {
678678
true
679679
}
680680
}
681+
implFloatingPointforf16{
682+
fnis_real() ->bool{
683+
true
684+
}
685+
}
681686

682687
///Trait qualifier to accept real data(numbers)
683688
pubtraitRealFloating:HasAfEnum{}
684689

685690
implRealFloatingforf64{}
686691
implRealFloatingforf32{}
692+
implRealFloatingforf16{}
687693

688694
///Trait qualifier to accept complex data(numbers)
689695
pubtraitComplexFloating:HasAfEnum{}
@@ -696,6 +702,7 @@ pub trait RealNumber: HasAfEnum {}
696702

697703
implRealNumberforf64{}
698704
implRealNumberforf32{}
705+
implRealNumberforf16{}
699706
implRealNumberfori32{}
700707
implRealNumberforu32{}
701708
implRealNumberfori16{}
@@ -856,6 +863,8 @@ impl Fromf64 for u32 { fn fromf64(value: f64) -> Self { value as Self }}
856863
#[rustfmt::skip]
857864
implFromf64fori32{fnfromf64(value:f64) ->Self{ valueasSelf}}
858865
#[rustfmt::skip]
866+
implFromf64forf16{fnfromf64(value:f64) ->Self{ f16::from_f64(value)}}
867+
#[rustfmt::skip]
859868
implFromf64foru16{fnfromf64(value:f64) ->Self{ valueasSelf}}
860869
#[rustfmt::skip]
861870
implFromf64fori16{fnfromf64(value:f64) ->Self{ valueasSelf}}
@@ -873,6 +882,7 @@ impl IndexableType for u64 {}
873882
implIndexableTypeforf32{}
874883
implIndexableTypefori32{}
875884
implIndexableTypeforu32{}
885+
implIndexableTypeforf16{}
876886
implIndexableTypefori16{}
877887
implIndexableTypeforu16{}
878888
implIndexableTypeforu8{}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp