MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / HostDnVecFloat

Class HostDnVecFloat

XM/include/Utils/memory.h:792–824  ·  view source on GitHub ↗

dense vector wrapper on host: float type

Source from the content-addressed store, hash-verified

790
791// dense vector wrapper on host: float type
792class HostDnVecFloat {
793 public:
794 int size;
795 float* vals;
796
797 HostDnVecFloat(): size(0), vals(nullptr) {}
798 HostDnVecFloat(const int size, bool as_byte = false): size(size), vals(nullptr) {
799 this->allocate(size, as_byte);
800 }
801
802 inline void allocate(const int size, bool as_byte = false) {
803 if (this->vals == nullptr) {
804 if (as_byte) {
805 this->size = (size + sizeof(float) - 1) / sizeof(float);
806 } else {
807 this->size = size;
808 }
809 this->vals = (float*) malloc(sizeof(float) * this->size);
810 }
811 return;
812 }
813 inline float get_norm() {
814 return cblas_snrm2(this->size, this->vals, 1);
815 }
816
817 ~HostDnVecFloat() {
818 if (this->vals != nullptr) {
819 free(this->vals);
820 this->vals = nullptr;
821 }
822 // std::cout << "HostDnVecFloat destructor called!" << std::endl;
823 }
824};
825
826// dense vector wrapper on host: int type
827class HostDnVecInt {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected