Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# ---------------------------------
# Flags de compilação (warnings + otimização)
# ---------------------------------
if (MSVC)
# Warnings fortes no MSVC
set(COMMON_FLAGS /W4 /permissive- /O2)
else()
# GCC/Clang: warnings + performance
set(COMMON_FLAGS -Wall -Wextra -Wpedantic -O3 -march=native)
endif()

# Aplica a todos os targets
add_compile_options(${COMMON_FLAGS})

# -------------------------------
# Biblioteca mlcpppy
# -------------------------------
Expand All @@ -16,7 +30,7 @@ add_library(mlcpppy SHARED ${MLCPP_SOURCES})
target_include_directories(mlcpppy PUBLIC ${PROJECT_SOURCE_DIR}/include)

# -------------------------------
# Executável de exemplo
# Executáveis de exemplo
# -------------------------------
add_executable(example_main examples/main.cpp)
add_executable(example_instance examples/atributes_usage.cpp)
Expand Down
2 changes: 1 addition & 1 deletion examples/atributes_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "mlcpppy/instances/instances.h"

int main(int argc, char const *argv[]) {
int main() {
// Exemplo de uso da classe atribute, instances e instance
Instance a(Attribute(1), Attribute(2.5), Attribute("Pedro"));
Instance b(Attribute(1), Attribute(2.5), Attribute("Pedro"));
Expand Down
2 changes: 1 addition & 1 deletion examples/example_binary_tree.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "mlcpppy/data_structures/binary_tree.h"

int main(int argc, char const* argv[]) {
int main() {
BinaryTree<int>* binary_tree = new BinaryTree<int>();
// Isso deixa desbalanceado
// 20, 8, 22, 4, 12, 10, 14
Expand Down
46 changes: 22 additions & 24 deletions include/mlcpppy/classifiers/neighbors/kdtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,17 @@ class KDTree : public NearestNeighbor<T, N> {
Point<T, N> point_;
int depth_;

explicit Node() {}
explicit Node(Point<T, N> point, Node* left, Node* right)
: point_(point), left_(left), right_(right) {}
explicit Node(Point<T, N> point, Node* left, Node* right,
int depth)
: point_(point),
left_(left),
right_(right),
depth_(depth) {}
explicit Node(Point<T, N> point) : point_(point) {
this->left_ = nullptr;
this->right_ = nullptr;
}
explicit Node(Point<T, N> point, int depth)
: point_(point), depth_(depth) {
this->left_ = nullptr;
this->right_ = nullptr;
}
explicit Node() {}
explicit Node(Node* left, Node* right, Point<T, N> point) : left_(left), right_(right), point_(point) {}
explicit Node(Node* left, Node* right, Point<T, N> point, int depth) : left_(left), right_(right), point_(point), depth_(depth) {}
explicit Node(Point<T, N> point) : point_(point) {
this->left_ = nullptr;
this->right_ = nullptr;
}
explicit Node(Point<T, N> point, int depth) : point_(point), depth_(depth) {
this->left_ = nullptr;
this->right_ = nullptr;
}

~Node() {
delete left_;
Expand All @@ -59,7 +52,7 @@ class KDTree : public NearestNeighbor<T, N> {
};

Node* root_;
int K_;
size_t K_;
std::priority_queue<std::pair<double, Node*>> bests_;

Node* Build(std::vector<Point<T, N>> points, int depth) {
Expand All @@ -80,10 +73,15 @@ class KDTree : public NearestNeighbor<T, N> {
std::vector<Point<T, N>> points_right(
points.begin() + median + 1, points.end());

return new Node(points.at(median),
Build(points_left, depth + 1),
Build(points_right, depth + 1), depth);
}

return new Node(
Build(points_left, depth + 1),
Build(points_right, depth + 1),
points.at(median),
depth
);
}


Node* NearestNeighbor(Node* root, Point<T, N>& target, int depth) {
if (root == nullptr) return nullptr;
Expand Down Expand Up @@ -251,7 +249,7 @@ class KDTree : public NearestNeighbor<T, N> {
return;
}

int initial_size = points.at(0).size();
size_t initial_size = points.at(0).size();

for (auto& point : points) {
if (point.data().empty()) {
Expand Down
4 changes: 3 additions & 1 deletion include/mlcpppy/classifiers/neighbors/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Point {
std::copy(list.begin(), list.end(), data_.begin());
}
const std::array<T, N> &data() const { return data_; }
const size_t size() const { return data_.size(); }
size_t size() const {
return data_.size();
}
};

#endif // POINT_H