@@ -147,6 +147,69 @@ Tensor Tensor::operator/(const float c) const{
147147 }
148148 return result;
149149}
150+ Tensor Tensor::operator >=(const Tensor &tensor_other) const {
151+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
152+ Tensor result (shape_);
153+ for (size_t i = 0 ; i < size (); ++i) {
154+ result.data_ [i] = data_[i] >= tensor_other.data_ [i];
155+ }
156+ return result;
157+ }
158+ Tensor Tensor::operator <=(const Tensor &tensor_other) const {
159+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
160+ Tensor result (shape_);
161+ for (size_t i = 0 ; i < size (); ++i) {
162+ result.data_ [i] = data_[i] <= tensor_other.data_ [i];
163+ }
164+ return result;
165+ }
166+ Tensor Tensor::operator >(const Tensor &tensor_other) const {
167+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
168+ Tensor result (shape_);
169+ for (size_t i = 0 ; i < size (); ++i) {
170+ result.data_ [i] = data_[i] > tensor_other.data_ [i];
171+ }
172+ return result;
173+ }
174+ Tensor Tensor::operator <(const Tensor &tensor_other) const {
175+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
176+ Tensor result (shape_);
177+ for (size_t i = 0 ; i < size (); ++i) {
178+ result.data_ [i] = data_[i] < tensor_other.data_ [i];
179+ }
180+ return result;
181+ }
182+ Tensor Tensor::operator ==(const Tensor &tensor_other) const {
183+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
184+ Tensor result (shape_);
185+ for (size_t i = 0 ; i < size (); ++i) {
186+ result.data_ [i] = data_[i] == tensor_other.data_ [i];
187+ }
188+ return result;
189+ }
190+ Tensor Tensor::operator !=(const Tensor &tensor_other) const {
191+ if (shape_ != tensor_other.shape ()) throw std::invalid_argument (" Tensor shapes must match for comparison." );
192+ Tensor result (shape_);
193+ for (size_t i = 0 ; i < size (); ++i) {
194+ result.data_ [i] = data_[i] != tensor_other.data_ [i];
195+ }
196+ return result;
197+ }
198+
199+ // boolean operands with constants I AM NOT IMPLEMENTING ALL THIS RIGHT NOW <============================================ THIS IS YOUR PROBLEM
200+ // Tensor operator>=(const float c) const;
201+ // Tensor operator<=(const float c) const;
202+ Tensor Tensor::operator >(const float c) const {
203+ Tensor result (shape_);
204+ for (size_t i = 0 ; i < size (); ++i) {
205+ result.data_ [i] = data_[i] > c;
206+ }
207+ return result;
208+ }
209+ // Tensor operator<(const float c) const;
210+ // Tensor operator==(const float cr) const;
211+ // Tensor operator!=(const float c) const;
212+
150213 // other operators
151214Tensor Tensor::matmul (const Tensor& tensor_other) const {
152215 // error check
@@ -169,6 +232,16 @@ Tensor Tensor::matmul(const Tensor& tensor_other) const{
169232 }
170233 return result;
171234}
235+
236+ float Tensor::sum () const {
237+ float total = 0 .0f ;
238+ for (float num : data_){
239+ total += num;
240+ }
241+ return total;
242+ }
243+
244+
172245Tensor Tensor::transpose () const {
173246 if (dim () != 2 ) throw std::invalid_argument (" Matrix Transpose only supports 2d rn :/" );
174247 // 2d only
0 commit comments