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

Commit 57cc29e

Browse files
committed
Shorten trait bounds in arith, data modules
1 parent 17ca34b commit 57cc29e

File tree

3 files changed

+60
-83
lines changed

3 files changed

+60
-83
lines changed

‎src/core/arith.rs‎

Lines changed: 43 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,8 @@ macro_rules! binary_func {
287287
/// - Only one element in `lhs` or `rhs` along a given dimension/axis
288288
pub fn $fn_name<A, B>(lhs: &Array<A>, rhs: &Array<B>, batch: bool) -> Array<A::Output>
289289
where
290-
A: HasAfEnum + ImplicitPromote<B>,
291-
B: HasAfEnum + ImplicitPromote<A>,
292-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
290+
A: ImplicitPromote<B>,
291+
B: ImplicitPromote<A>,
293292
{
294293
unsafe {
295294
let mut temp: af_array = std::ptr::null_mut();
@@ -378,8 +377,7 @@ pub trait Convertable {
378377

379378
impl<T> Convertable for T
380379
where
381-
T: Clone + HasAfEnum + ConstGenerator<OutType = T>,
382-
<T as ConstGenerator>::OutType: HasAfEnum,
380+
T: Clone + ConstGenerator<OutType = T>,
383381
{
384382
type OutType = T;
385383

@@ -400,9 +398,8 @@ macro_rules! overloaded_binary_func {
400398
($doc_str: expr, $fn_name: ident, $help_name: ident, $ffi_name: ident) => {
401399
fn $help_name<A, B>(lhs: &Array<A>, rhs: &Array<B>, batch: bool) -> Array<A::Output>
402400
where
403-
A: HasAfEnum + ImplicitPromote<B>,
404-
B: HasAfEnum + ImplicitPromote<A>,
405-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
401+
A: ImplicitPromote<B>,
402+
B: ImplicitPromote<A>,
406403
{
407404
unsafe {
408405
let mut temp: af_array = std::ptr::null_mut();
@@ -453,10 +450,8 @@ macro_rules! overloaded_binary_func {
453450
where
454451
T: Convertable,
455452
U: Convertable,
456-
<T as Convertable>::OutType: HasAfEnum + ImplicitPromote<<U as Convertable>::OutType>,
457-
<U as Convertable>::OutType: HasAfEnum + ImplicitPromote<<T as Convertable>::OutType>,
458-
<<T as Convertable>::OutType as ImplicitPromote<<U as Convertable>::OutType>>::Output:
459-
HasAfEnum,
453+
<T as Convertable>::OutType: ImplicitPromote<<U as Convertable>::OutType>,
454+
<U as Convertable>::OutType: ImplicitPromote<<T as Convertable>::OutType>,
460455
{
461456
let lhs = arg1.convert(); // Convert to Array<T>
462457
let rhs = arg2.convert(); // Convert to Array<T>
@@ -507,8 +502,8 @@ macro_rules! overloaded_compare_func {
507502
($doc_str: expr, $fn_name: ident, $help_name: ident, $ffi_name: ident) => {
508503
fn $help_name<A, B>(lhs: &Array<A>, rhs: &Array<B>, batch: bool) -> Array<bool>
509504
where
510-
A: HasAfEnum + ImplicitPromote<B>,
511-
B: HasAfEnum + ImplicitPromote<A>,
505+
A: ImplicitPromote<B>,
506+
B: ImplicitPromote<A>,
512507
{
513508
unsafe {
514509
let mut temp: af_array = std::ptr::null_mut();
@@ -557,8 +552,8 @@ macro_rules! overloaded_compare_func {
557552
where
558553
T: Convertable,
559554
U: Convertable,
560-
<T as Convertable>::OutType: HasAfEnum + ImplicitPromote<<U as Convertable>::OutType>,
561-
<U as Convertable>::OutType: HasAfEnum + ImplicitPromote<<T as Convertable>::OutType>,
555+
<T as Convertable>::OutType: ImplicitPromote<<U as Convertable>::OutType>,
556+
<U as Convertable>::OutType: ImplicitPromote<<T as Convertable>::OutType>,
562557
{
563558
let lhs = arg1.convert(); // Convert to Array<T>
564559
let rhs = arg2.convert(); // Convert to Array<T>
@@ -615,9 +610,8 @@ fn clamp_helper<X, Y>(
615610
batch: bool,
616611
) -> Array<<X as ImplicitPromote<Y>>::Output>
617612
where
618-
X: HasAfEnum + ImplicitPromote<Y>,
619-
Y: HasAfEnum + ImplicitPromote<X>,
620-
<X as ImplicitPromote<Y>>::Output: HasAfEnum,
613+
X: ImplicitPromote<Y>,
614+
Y: ImplicitPromote<X>,
621615
{
622616
unsafe {
623617
let mut temp: af_array = std::ptr::null_mut();
@@ -667,10 +661,9 @@ pub fn clamp<T, C>(
667661
batch: bool,
668662
) -> Array<<T as ImplicitPromote<<C as Convertable>::OutType>>::Output>
669663
where
670-
T: HasAfEnum + ImplicitPromote<<C as Convertable>::OutType>,
664+
T: ImplicitPromote<<C as Convertable>::OutType>,
671665
C: Convertable,
672-
<C as Convertable>::OutType: HasAfEnum + ImplicitPromote<T>,
673-
<T as ImplicitPromote<<C as Convertable>::OutType>>::Output: HasAfEnum,
666+
<C as Convertable>::OutType: ImplicitPromote<T>,
674667
{
675668
let lo = arg1.convert(); // Convert to Array<T>
676669
let hi = arg2.convert(); // Convert to Array<T>
@@ -697,8 +690,8 @@ macro_rules! arith_rhs_scalar_func {
697690
// Implement (&Array<T> op_name rust_type)
698691
impl<'f, T, U> $op_name<U> for &'f Array<T>
699692
where
700-
T: HasAfEnum + ImplicitPromote<U>,
701-
U: HasAfEnum + ImplicitPromote<T> + Clone + ConstGenerator<OutType = U>,
693+
T: ImplicitPromote<U>,
694+
U: ImplicitPromote<T> + Clone + ConstGenerator<OutType = U>,
702695
{
703696
type Output = Array<<T as ImplicitPromote<U>>::Output>;
704697

@@ -711,8 +704,8 @@ macro_rules! arith_rhs_scalar_func {
711704
// Implement (Array<T> op_name rust_type)
712705
impl<T, U> $op_name<U> for Array<T>
713706
where
714-
T: HasAfEnum + ImplicitPromote<U>,
715-
U: HasAfEnum + ImplicitPromote<T> + Clone + ConstGenerator<OutType = U>,
707+
T: ImplicitPromote<U>,
708+
U: ImplicitPromote<T> + Clone + ConstGenerator<OutType = U>,
716709
{
717710
type Output = Array<<T as ImplicitPromote<U>>::Output>;
718711

@@ -729,8 +722,8 @@ macro_rules! arith_lhs_scalar_func {
729722
// Implement (rust_type op_name &Array<T>)
730723
impl<'f, T> $op_name<&'f Array<T>> for $rust_type
731724
where
732-
T: HasAfEnum + ImplicitPromote<$rust_type>,
733-
$rust_type: HasAfEnum + ImplicitPromote<T>,
725+
T: ImplicitPromote<$rust_type>,
726+
$rust_type: ImplicitPromote<T>,
734727
{
735728
type Output = Array<<$rust_type as ImplicitPromote<T>>::Output>;
736729

@@ -742,8 +735,8 @@ macro_rules! arith_lhs_scalar_func {
742735
// Implement (rust_type op_name Array<T>)
743736
impl<T> $op_name<Array<T>> for $rust_type
744737
where
745-
T: HasAfEnum + ImplicitPromote<$rust_type>,
746-
$rust_type: HasAfEnum + ImplicitPromote<T>,
738+
T: ImplicitPromote<$rust_type>,
739+
$rust_type: ImplicitPromote<T>,
747740
{
748741
type Output = Array<<$rust_type as ImplicitPromote<T>>::Output>;
749742

@@ -782,9 +775,8 @@ macro_rules! arith_func {
782775
($op_name:ident, $fn_name:ident, $delegate:ident) => {
783776
impl<A, B> $op_name<Array<B>> for Array<A>
784777
where
785-
A: HasAfEnum + ImplicitPromote<B>,
786-
B: HasAfEnum + ImplicitPromote<A>,
787-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
778+
A: ImplicitPromote<B>,
779+
B: ImplicitPromote<A>,
788780
{
789781
type Output = Array<<A as ImplicitPromote<B>>::Output>;
790782

@@ -795,9 +787,8 @@ macro_rules! arith_func {
795787

796788
impl<'a, A, B> $op_name<&'a Array<B>> for Array<A>
797789
where
798-
A: HasAfEnum + ImplicitPromote<B>,
799-
B: HasAfEnum + ImplicitPromote<A>,
800-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
790+
A: ImplicitPromote<B>,
791+
B: ImplicitPromote<A>,
801792
{
802793
type Output = Array<<A as ImplicitPromote<B>>::Output>;
803794

@@ -808,9 +799,8 @@ macro_rules! arith_func {
808799

809800
impl<'a, A, B> $op_name<Array<B>> for &'a Array<A>
810801
where
811-
A: HasAfEnum + ImplicitPromote<B>,
812-
B: HasAfEnum + ImplicitPromote<A>,
813-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
802+
A: ImplicitPromote<B>,
803+
B: ImplicitPromote<A>,
814804
{
815805
type Output = Array<<A as ImplicitPromote<B>>::Output>;
816806

@@ -821,9 +811,8 @@ macro_rules! arith_func {
821811

822812
impl<'a, 'b, A, B> $op_name<&'a Array<B>> for &'b Array<A>
823813
where
824-
A: HasAfEnum + ImplicitPromote<B>,
825-
B: HasAfEnum + ImplicitPromote<A>,
826-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
814+
A: ImplicitPromote<B>,
815+
B: ImplicitPromote<A>,
827816
{
828817
type Output = Array<<A as ImplicitPromote<B>>::Output>;
829818

@@ -849,9 +838,8 @@ macro_rules! bitshift_scalar_func {
849838
($rust_type: ty, $trait_name: ident, $op_name: ident) => {
850839
impl<T> $trait_name<$rust_type> for Array<T>
851840
where
852-
T: HasAfEnum + ImplicitPromote<$rust_type>,
853-
$rust_type: HasAfEnum + ImplicitPromote<T>,
854-
<T as ImplicitPromote<$rust_type>>::Output: HasAfEnum,
841+
T: ImplicitPromote<$rust_type>,
842+
$rust_type: ImplicitPromote<T>,
855843
{
856844
type Output = Array<<T as ImplicitPromote<$rust_type>>::Output>;
857845

@@ -862,9 +850,8 @@ macro_rules! bitshift_scalar_func {
862850
}
863851
impl<'f, T> $trait_name<$rust_type> for &'f Array<T>
864852
where
865-
T: HasAfEnum + ImplicitPromote<$rust_type>,
866-
$rust_type: HasAfEnum + ImplicitPromote<T>,
867-
<T as ImplicitPromote<$rust_type>>::Output: HasAfEnum,
853+
T: ImplicitPromote<$rust_type>,
854+
$rust_type: ImplicitPromote<T>,
868855
{
869856
type Output = Array<<T as ImplicitPromote<$rust_type>>::Output>;
870857

@@ -900,10 +887,8 @@ mod op_assign {
900887
($op_name:ident, $fn_name:ident, $func: ident) => {
901888
impl<A, B> $op_name<Array<B>> for Array<A>
902889
where
903-
A: HasAfEnum + ImplicitPromote<B>,
904-
B: HasAfEnum + ImplicitPromote<A>,
905-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
906-
<B as ImplicitPromote<A>>::Output: HasAfEnum,
890+
A: ImplicitPromote<B>,
891+
B: ImplicitPromote<A>,
907892
{
908893
fn $fn_name(&mut self, rhs: Array<B>) {
909894
let tmp_seq = Seq::<f32>::default();
@@ -930,10 +915,8 @@ mod op_assign {
930915
($rust_type:ty, $trait_name:ident, $op_name:ident, $func:ident) => {
931916
impl<T> $trait_name<$rust_type> for Array<T>
932917
where
933-
$rust_type: HasAfEnum + ImplicitPromote<T>,
934-
T: HasAfEnum
935-
+ ImplicitPromote<$rust_type>
936-
+ ImplicitPromote<$rust_type, Output = T>,
918+
$rust_type: ImplicitPromote<T>,
919+
T: ImplicitPromote<$rust_type, Output = T>,
937920
{
938921
fn $op_name(&mut self, rhs: $rust_type) {
939922
let mut temp = $func(self, &rhs, false);
@@ -959,10 +942,8 @@ mod op_assign {
959942
($op_name:ident, $fn_name:ident, $func: ident) => {
960943
impl<A, B> $op_name<Array<B>> for Array<A>
961944
where
962-
A: HasAfEnum + ImplicitPromote<B>,
963-
B: HasAfEnum + ImplicitPromote<A>,
964-
<A as ImplicitPromote<B>>::Output: HasAfEnum,
965-
<B as ImplicitPromote<A>>::Output: HasAfEnum,
945+
A: ImplicitPromote<B>,
946+
B: ImplicitPromote<A>,
966947
{
967948
fn $fn_name(&mut self, rhs: Array<B>) {
968949
let tmp_seq = Seq::<f32>::default();
@@ -985,13 +966,9 @@ mod op_assign {
985966
///Implement negation trait for Array
986967
impl<T> Neg for Array<T>
987968
where
988-
T: HasAfEnum + Zero + ConstGenerator,
989-
<T as ConstGenerator>::OutType: HasAfEnum,
990-
<T as ConstGenerator>::OutType: ImplicitPromote<T>,
991-
T: ImplicitPromote<<T as ConstGenerator>::OutType>,
992-
<<T as ConstGenerator>::OutType as ImplicitPromote<T>>::Output: HasAfEnum,
969+
T: Zero + ConstGenerator<OutType = T>,
993970
{
994-
type Output = Array<<<TasConstGenerator>::OutTypeasImplicitPromote<T>>::Output>;
971+
type Output = Array<T>;
995972

996973
fn neg(self) -> Self::Output {
997974
let cnst = constant(T::zero(), self.dims());

‎src/core/data.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ extern "C" {
124124
/// - i16
125125
/// - u16
126126
///
127-
pub trait ConstGenerator {
127+
pub trait ConstGenerator:HasAfEnum {
128128
/// The type of Array<T> object returned by generate function
129129
type OutType: HasAfEnum;
130130

@@ -286,9 +286,9 @@ cnst!(u16, 11);
286286
/// # Return Values
287287
///
288288
/// An Array of given dimensions with constant value
289-
pub fn constant<G:ConstGenerator>(cnst: G, dims: Dim4) -> Array<G::OutType>
289+
pub fn constant<T>(cnst: T, dims: Dim4) -> Array<T>
290290
where
291-
G::OutType:HasAfEnum,
291+
T:ConstGenerator<OutType = T>,
292292
{
293293
cnst.generate(dims)
294294
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /