44
55namespace Ouroboros {
66template <typename T>
7- Tensor<T> operator -(const Tensor<T>& a){
7+ __always_inline Tensor<T> operator -(const Tensor<T>& a){
88 Tensor<T> result (a.shape ());
99 for (std::size_t i=0 ;i<a.size ();i++){
1010 result[i]=-a[i];
@@ -13,31 +13,31 @@ Tensor<T> operator-(const Tensor<T>& a){
1313}
1414
1515template <typename T>
16- Tensor<T> operator +(const Tensor<T>& a,const Tensor<T>& b){
16+ __always_inline Tensor<T> operator +(const Tensor<T>& a,const Tensor<T>& b){
1717 Tensor<T> result (a.shape ());
1818 for (std::size_t i=0 ;i<a.size ();i++){
1919 result[i]=a[i]+b[i];
2020 }
2121 return result;
2222}
2323template <typename T>
24- Tensor<T> operator -(const Tensor<T>& a,const Tensor<T>& b){
24+ __always_inline Tensor<T> operator -(const Tensor<T>& a,const Tensor<T>& b){
2525 Tensor<T> result (a.shape ());
2626 for (std::size_t i=0 ;i<a.size ();i++){
2727 result[i]=a[i]-b[i];
2828 }
2929 return result;
3030}
3131template <typename T>
32- Tensor<T> operator *(const Tensor<T>& a,const Tensor<T>& b){
32+ __always_inline Tensor<T> operator *(const Tensor<T>& a,const Tensor<T>& b){
3333 Tensor<T> result (a.shape ());
3434 for (std::size_t i=0 ;i<a.size ();i++){
3535 result[i]=a[i]*b[i];
3636 }
3737 return result;
3838}
3939template <typename T>
40- Tensor<T> operator /(const Tensor<T>& a,const Tensor<T>& b){
40+ __always_inline Tensor<T> operator /(const Tensor<T>& a,const Tensor<T>& b){
4141 Tensor<T> result (a.shape ());
4242 for (std::size_t i=0 ;i<a.size ();i++){
4343 result[i]=a[i]/b[i];
@@ -46,48 +46,48 @@ Tensor<T> operator/(const Tensor<T>& a,const Tensor<T>& b){
4646}
4747
4848template <typename T>
49- Tensor<T> operator +(const Tensor<T>& a,T b){
49+ __always_inline Tensor<T> operator +(const Tensor<T>& a,T b){
5050 Tensor<T> result (a.shape ());
5151 for (std::size_t i=0 ;i<a.size ();i++){
5252 result[i]=a[i]+b;
5353 }
5454 return result;
5555}
5656template <typename T>
57- Tensor<T> operator -(const Tensor<T>& a,T b){
57+ __always_inline Tensor<T> operator -(const Tensor<T>& a,T b){
5858 return a+(-b);
5959}
6060template <typename T>
61- Tensor<T> operator *(const Tensor<T>& a,T b){
61+ __always_inline Tensor<T> operator *(const Tensor<T>& a,T b){
6262 Tensor<T> result (a.shape ());
6363 for (std::size_t i=0 ;i<a.size ();i++){
6464 result[i]=a[i]*b;
6565 }
6666 return result;
6767}
6868template <typename T>
69- Tensor<T> operator /(const Tensor<T>& a,T b){
69+ __always_inline Tensor<T> operator /(const Tensor<T>& a,T b){
7070 return a*((T)1 /b);
7171}
7272
7373template <typename T>
74- Tensor<T> operator +(T a,const Tensor<T>& b){
74+ __always_inline Tensor<T> operator +(T a,const Tensor<T>& b){
7575 return b+a;
7676}
7777template <typename T>
78- Tensor<T> operator -(T a,const Tensor<T>& b){
78+ __always_inline Tensor<T> operator -(T a,const Tensor<T>& b){
7979 Tensor<T> result (b.shape ());
8080 for (std::size_t i=0 ;i<b.size ();i++){
8181 result[i]=a-b[i];
8282 }
8383 return result;
8484}
8585template <typename T>
86- Tensor<T> operator *(T a,const Tensor<T>& b){
86+ __always_inline Tensor<T> operator *(T a,const Tensor<T>& b){
8787 return b*a;
8888}
8989template <typename T>
90- Tensor<T> operator /(T a,const Tensor<T>& b){
90+ __always_inline Tensor<T> operator /(T a,const Tensor<T>& b){
9191 Tensor<T> result (b.shape ());
9292 for (std::size_t i=0 ;i<b.size ();i++){
9393 result[i]=a/b[i];
@@ -96,53 +96,53 @@ Tensor<T> operator/(T a,const Tensor<T>& b){
9696}
9797
9898template <typename T>
99- void operator +=(Tensor<T>& a,const Tensor<T>& b){
99+ __always_inline void operator +=(Tensor<T>& a,const Tensor<T>& b){
100100 for (std::size_t i=0 ;i<a.size ();i++){
101101 a[i]+=b[i];
102102 }
103103}
104104template <typename T>
105- void operator -=(Tensor<T>& a,const Tensor<T>& b){
105+ __always_inline void operator -=(Tensor<T>& a,const Tensor<T>& b){
106106 for (std::size_t i=0 ;i<a.size ();i++){
107107 a[i]-=b[i];
108108 }
109109}
110110template <typename T>
111- void operator *=(Tensor<T>& a,const Tensor<T>& b){
111+ __always_inline void operator *=(Tensor<T>& a,const Tensor<T>& b){
112112 for (std::size_t i=0 ;i<a.size ();i++){
113113 a[i]*=b[i];
114114 }
115115}
116116template <typename T>
117- void operator /=(Tensor<T>& a,const Tensor<T>& b){
117+ __always_inline void operator /=(Tensor<T>& a,const Tensor<T>& b){
118118 for (std::size_t i=0 ;i<a.size ();i++){
119119 a[i]/=b[i];
120120 }
121121}
122122
123123template <typename T>
124- void operator +=(Tensor<T>& a,T b){
124+ __always_inline void operator +=(Tensor<T>& a,T b){
125125 for (std::size_t i=0 ;i<a.size ();i++){
126126 a[i]+=b;
127127 }
128128}
129129template <typename T>
130- void operator -=(Tensor<T>& a,T b){
130+ __always_inline void operator -=(Tensor<T>& a,T b){
131131 a+=(-b);
132132}
133133template <typename T>
134- void operator *=(Tensor<T>& a,T b){
134+ __always_inline void operator *=(Tensor<T>& a,T b){
135135 for (std::size_t i=0 ;i<a.size ();i++){
136136 a[i]*=b;
137137 }
138138}
139139template <typename T>
140- void operator /=(Tensor<T>& a,T b){
140+ __always_inline void operator /=(Tensor<T>& a,T b){
141141 a*=((T)1 /b);
142142}
143143
144144template <typename T>
145- Tensor<T> matmul (const Tensor<T>& a,const Tensor<T>& b){
145+ __always_inline Tensor<T> matmul (const Tensor<T>& a,const Tensor<T>& b){
146146 Shape result_shape={a.shape ()[0 ],b.shape ()[1 ]};
147147 Tensor<T> result (result_shape);
148148 // Choose the right cblas function based on type T
@@ -167,7 +167,7 @@ Tensor<T> matmul(const Tensor<T>& a,const Tensor<T>& b){
167167 return result;
168168}
169169template <typename T>
170- Tensor<T> matvecmul (const Tensor<T>& a,const Tensor<T>& b){
170+ __always_inline Tensor<T> matvecmul (const Tensor<T>& a,const Tensor<T>& b){
171171 Shape result_shape={a.shape ()[0 ]};
172172 Tensor<T> result (result_shape);
173173 // Choose the right cblas function based on type T
0 commit comments