vector.hpp 699 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef VECTOR_HPP
  2. #define VECTOR_HPP
  3. #include <iostream>
  4. #include <cassert>
  5. #include <cstring>
  6. #include "math.hpp"
  7. using namespace std;
  8. class Vector{
  9. public:
  10. size_t n;
  11. double* data;
  12. Vector();
  13. Vector(const Vector& u);
  14. Vector(size_t n);
  15. ~Vector();
  16. const Vector& operator=(const Vector& u);
  17. void resize(size_t s);
  18. size_t argmax() const;
  19. void softmax();
  20. void clear();
  21. friend ostream& operator<<(ostream& os,const Vector& v);
  22. };
  23. ostream& operator<<(ostream& os,const Vector&);
  24. inline
  25. Vector::Vector(){
  26. n=0;
  27. data=nullptr;
  28. }
  29. inline
  30. Vector::Vector(size_t _n){
  31. n=_n;
  32. data=new double[n];
  33. }
  34. inline
  35. Vector::~Vector(){
  36. if(data!=nullptr){
  37. delete[] data;
  38. }
  39. }
  40. #endif