@@ -734,73 +734,139 @@ impl<T: Numeric<T>> Div<T> for &Sprs<T> {
734734 }
735735}
736736
737- // Implementing operators for `T` and `Sprs<T>` types
738-
739- // impl <T: Numeric<T>> Add<Sprs<T>> for T {
740- // type Output = Sprs<T>;
741-
742- // /// Overloads the `+` operator. Adds an `T` value to all elements of a
743- // /// sparse matrix
744- // ///
745- // fn add(self, other: Sprs<T>) -> Sprs<T> {
746- // scpmat(self, &other)
747- // }
748- // }
749-
750- // impl <T: Numeric<T>> Add<&Sprs<T>> for T {
751- // type Output = Sprs<T>;
752-
753- // /// Overloads the `+` operator. Adds an `T` value to all elements of a
754- // /// sparse matrix
755- // ///
756- // fn add(self, other: &Sprs<T>) -> Sprs<T> {
757- // scpmat(self, other)
758- // }
759- // }
760-
761- // impl <T: Numeric<T>> Sub<Sprs<T>> for T {
762- // type Output = Sprs<T>;
763-
764- // /// Overloads the `-` operator. Subtracts an `T` value to all elements of
765- // /// a sparse matrix
766- // ///
767- // fn sub(self, other: Sprs<T>) -> Sprs<T> {
768- // scpmat(self, &scxmat(-1., &other))
769- // }
770- // }
771-
772- // impl <T: Numeric<T>> Sub<&Sprs<T>> for T {
773- // type Output = Sprs<T>;
774-
775- // /// Overloads the `-` operator. Subtracts an `T` value to all elements of
776- // /// a sparse matrix
777- // ///
778- // fn sub(self, other: &Sprs<T>) -> Sprs<T> {
779- // scpmat(self, &scxmat(-1., other))
780- // }
781- // }
782-
783- // impl <T: Numeric<T>> Mul<Sprs<T>> for T {
784- // type Output = Sprs<T>;
785-
786- // /// Overloads the `*` operator. Multiplies an `T` value to all elements of
787- // /// a sparse matrix
788- // ///
789- // fn mul(self, other: Sprs<T>) -> Sprs<T> {
790- // scxmat(self, &other)
791- // }
792- // }
793-
794- // impl <T: Numeric<T>> Mul<&Sprs<T>> for T {
795- // type Output = Sprs<T>;
796-
797- // /// Overloads the `*` operator. Multiplies an `T` value to all elements of
798- // /// a sparse matrix
799- // ///
800- // fn mul(self, other: &Sprs<T>) -> Sprs<T> {
801- // scxmat(self, other)
802- // }
803- // }
737+ // Implementing operators for `T` (f32, f64) and `Sprs<T>` types
738+
739+ impl Add < Sprs < f32 > > for f32 {
740+ type Output = Sprs < f32 > ;
741+
742+ /// Overloads the `+` operator. Adds an `f64` value to all elements of a
743+ /// sparse matrix
744+ ///
745+ fn add ( self , other : Sprs < f32 > ) -> Sprs < f32 > {
746+ scpmat ( self , & other)
747+ }
748+ }
749+
750+ impl Add < Sprs < f64 > > for f64 {
751+ type Output = Sprs < f64 > ;
752+
753+ /// Overloads the `+` operator. Adds an `f64` value to all elements of a
754+ /// sparse matrix
755+ ///
756+ fn add ( self , other : Sprs < f64 > ) -> Sprs < f64 > {
757+ scpmat ( self , & other)
758+ }
759+ }
760+
761+ impl Add < & Sprs < f32 > > for f32 {
762+ type Output = Sprs < f32 > ;
763+
764+ /// Overloads the `+` operator. Adds an `f32` value to all elements of a
765+ /// sparse matrix
766+ ///
767+ fn add ( self , other : & Sprs < f32 > ) -> Sprs < f32 > {
768+ scpmat ( self , other)
769+ }
770+ }
771+
772+ impl Add < & Sprs < f64 > > for f64 {
773+ type Output = Sprs < f64 > ;
774+
775+ /// Overloads the `+` operator. Adds an `f64` value to all elements of a
776+ /// sparse matrix
777+ ///
778+ fn add ( self , other : & Sprs < f64 > ) -> Sprs < f64 > {
779+ scpmat ( self , other)
780+ }
781+ }
782+
783+ impl Sub < Sprs < f32 > > for f32 {
784+ type Output = Sprs < f32 > ;
785+
786+ /// Overloads the `-` operator. Subtracts an `f32` value to all elements of
787+ /// a sparse matrix
788+ ///
789+ fn sub ( self , other : Sprs < f32 > ) -> Sprs < f32 > {
790+ scpmat ( self , & scxmat ( -1. , & other) )
791+ }
792+ }
793+
794+ impl Sub < Sprs < f64 > > for f64 {
795+ type Output = Sprs < f64 > ;
796+
797+ /// Overloads the `-` operator. Subtracts an `f64` value to all elements of
798+ /// a sparse matrix
799+ ///
800+ fn sub ( self , other : Sprs < f64 > ) -> Sprs < f64 > {
801+ scpmat ( self , & scxmat ( -1. , & other) )
802+ }
803+ }
804+
805+ impl Sub < & Sprs < f32 > > for f32 {
806+ type Output = Sprs < f32 > ;
807+
808+ /// Overloads the `-` operator. Subtracts an `f32` value to all elements of
809+ /// a sparse matrix
810+ ///
811+ fn sub ( self , other : & Sprs < f32 > ) -> Sprs < f32 > {
812+ scpmat ( self , & scxmat ( -1. , other) )
813+ }
814+ }
815+
816+ impl Sub < & Sprs < f64 > > for f64 {
817+ type Output = Sprs < f64 > ;
818+
819+ /// Overloads the `-` operator. Subtracts an `f64` value to all elements of
820+ /// a sparse matrix
821+ ///
822+ fn sub ( self , other : & Sprs < f64 > ) -> Sprs < f64 > {
823+ scpmat ( self , & scxmat ( -1. , other) )
824+ }
825+ }
826+
827+ impl Mul < Sprs < f32 > > for f32 {
828+ type Output = Sprs < f32 > ;
829+
830+ /// Overloads the `*` operator. Multiplies an `f32` value to all elements of
831+ /// a sparse matrix
832+ ///
833+ fn mul ( self , other : Sprs < f32 > ) -> Sprs < f32 > {
834+ scxmat ( self , & other)
835+ }
836+ }
837+
838+ impl Mul < Sprs < f64 > > for f64 {
839+ type Output = Sprs < f64 > ;
840+
841+ /// Overloads the `*` operator. Multiplies an `f64` value to all elements of
842+ /// a sparse matrix
843+ ///
844+ fn mul ( self , other : Sprs < f64 > ) -> Sprs < f64 > {
845+ scxmat ( self , & other)
846+ }
847+ }
848+
849+ impl Mul < & Sprs < f32 > > for f32 {
850+ type Output = Sprs < f32 > ;
851+
852+ /// Overloads the `*` operator. Multiplies an `f32` value to all elements of
853+ /// a sparse matrix
854+ ///
855+ fn mul ( self , other : & Sprs < f32 > ) -> Sprs < f32 > {
856+ scxmat ( self , other)
857+ }
858+ }
859+
860+ impl Mul < & Sprs < f64 > > for f64 {
861+ type Output = Sprs < f64 > ;
862+
863+ /// Overloads the `*` operator. Multiplies an `f64` value to all elements of
864+ /// a sparse matrix
865+ ///
866+ fn mul ( self , other : & Sprs < f64 > ) -> Sprs < f64 > {
867+ scxmat ( self , other)
868+ }
869+ }
804870
805871/// Matrix in triplet format
806872///
0 commit comments