Commit 00d660b1 authored by maria victoria zolezzi's avatar maria victoria zolezzi
Browse files

Subo el trabajo

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
tp2
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/entrega_tp3.iml" filepath="$PROJECT_DIR$/.idea/entrega_tp3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
cmake_minimum_required(VERSION 2.8.12)
project(tp2)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug mode")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O0")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
ENDIF()
IF(CMAKE_BUILD_TYPE MATCHES Release)
message("Release mode")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
ENDIF()
# si se usa un virtual environment setearlo aca
#set(PYTHON_EXECUTABLE "/path/to/bin/python")
#set(PYTHON_LIBRARY "/path/to/lib/libpytho.so")
# Prender y apagar este flag para soporte OpenMP
#set(USE_OpenMP ON)
# Script cmake ``multi-plataforma`` (testeado en MacOS y Ubuntu)
#include(cmake/OpenMP.cmake)
include_directories(eigen)
add_subdirectory(pybind11)
pybind11_add_module(metnum
src/metnum.cpp
src/linear_regression.cpp)
# Por cada módulo que use OpenMP ponerlo como dependencia de esta forma
#target_link_libraries(metnum LINK_PUBLIC OpenMP::OpenMP_CXX)
# Esta variable se usa para fijar el directorio de instalación
set(CMAKE_INSTALL_PREFIX
${PROJECT_SOURCE_DIR}
CACHE PATH "Python custom modules directory" FORCE)
message(CMAKE_INSTALL_PREFIX = "${CMAKE_INSTALL_PREFIX}")
install(TARGETS metnum DESTINATION ${CMAKE_INSTALL_PREFIX}/notebooks)
# Crear un binario para testing manteniendo las dependencias de python por separado
add_executable(tp3
src/main.cpp
src/linear_regression.cpp)
# si se quiere hacer un ejecutable "tp2" que incluya pybind11, utilizar las
# siguientes 3 instrucciones de cmake.
#include_directories(pybind11/include)
#add_executable(tp2_pybind
# src/main_pybind.cpp
# src/knn.cpp
# src/pca.cpp
# src/eigen.cpp)
#
#target_link_libraries(tp2_pybind PRIVATE pybind11::embed)
# NOTE(fragofer): based on Example CMakeLists.txt from project CryFS to automatically find OpenMP https://github.com/cryfs/cryfs/blob/08ed96680876c960d5aab0aabebb25206f0bda06/vendor/cryptopp/CMakeLists.txt
if(USE_OpenMP)
if (MSVC)
message(WARNING "MSVC does not support the OpenMP 4.0 standard used by Crypto++. Disabling OpenMP. This can cause degraded performance.")
else()
find_package(OpenMP)
if (OPENMP_FOUND OR OPENMP_CXX_FOUND)
message(STATUS "Found libomp without any special flags")
endif()
# If OpenMP wasn't found, try if we can find it in the default Macports location
if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND) AND EXISTS "/opt/local/lib/libomp/libomp.dylib") # older cmake uses OPENMP_FOUND, newer cmake also sets OPENMP_CXX_FOUND, homebrew installations seem only to get the latter set.
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/local/include/libomp/")
set(OpenMP_CXX_LIB_NAMES omp)
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
find_package(OpenMP)
if (OPENMP_FOUND OR OPENMP_CXX_FOUND)
message(STATUS "Found libomp in macports default location.")
else()
message(FATAL_ERROR "Didn't find libomp. Tried macports default location but also didn't find it.")
endif()
endif()
# If OpenMP wasn't found, try if we can find it in the default Homebrew location
if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND) AND EXISTS "/usr/local/opt/libomp/lib/libomp.dylib")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
set(OpenMP_CXX_LIB_NAMES omp)
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
find_package(OpenMP)
if (OPENMP_FOUND OR OPENMP_CXX_FOUND)
message(STATUS "Found libomp in homebrew default location.")
else()
message(FATAL_ERROR "Didn't find libomp. Tried homebrew default location but also didn't find it.")
endif()
endif()
set(Additional_OpenMP_Libraries_Workaround "")
# Workaround because older cmake on apple doesn't support FindOpenMP
if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND))
if((APPLE AND ((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")))
AND ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0") AND (CMAKE_VERSION VERSION_LESS "3.12.0")))
message(STATUS "Applying workaround for OSX OpenMP with old cmake that doesn't have FindOpenMP")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(Additional_OpenMP_Libraries_Workaround "-lomp")
else()
message(FATAL_ERROR "Did not find OpenMP. Build with -DDISABLE_OPENMP=ON if you want to allow this and are willing to take the performance hit.")
endif()
endif()
if(NOT TARGET OpenMP::OpenMP_CXX)
# We're on cmake < 3.9, handle behavior of the old FindOpenMP implementation
message(STATUS "Applying workaround for old CMake that doesn't define FindOpenMP using targets")
add_library(OpenMP_TARGET INTERFACE)
add_library(OpenMP::OpenMP_CXX ALIAS OpenMP_TARGET)
target_compile_options(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS}) # add to all targets depending on this
find_package(Threads REQUIRED)
target_link_libraries(OpenMP_TARGET INTERFACE Threads::Threads)
target_link_libraries(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS} ${Additional_OpenMP_Libraries_Workaround})
endif()
endif()
else()
# message(WARNING "OpenMP is disabled. This can cause degraded performance.")
set(OpenMP_FOUND OFF)
endif()
#if (NOT OpenMP_FOUND)
# message("OpenMP not found. Ignoring unknown pragmas during compile-time.")
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
#
# add_library(OpenMP_TARGET INTERFACE)
# add_library(OpenMP::OpenMP_CXX ALIAS OpenMP_TARGET)
# target_compile_options(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS}) # add to all targets depending on this
## find_package(Threads REQUIRED)
## target_link_libraries(OpenMP_TARGET INTERFACE Threads::Threads)
## target_link_libraries(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS} ${Additional_OpenMP_Libraries_Workaround})
#endif()
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
jupyterlab
numpy==1.18.2
scikit-learn==0.23.1
pandas==1.0.3
matplotlib==3.2.1
seaborn==0.11.0
#include <algorithm>
//#include <chrono>
//#include <pybind11/pybind11.h>
#include <iostream>
#include <exception>
#include "linear_regression.h"
using namespace std;
//namespace py=pybind11;
LinearRegression::LinearRegression(): _AtA(), _Atb(){}
MatrixXd LinearRegression::get_AtA() {
return _AtA;
}
MatrixXd LinearRegression::get_coef() {
return _coef;
}
void LinearRegression::fit(Matrix X, Matrix y)
{
_AtA=X.transpose()*X;
_Atb=X.transpose()*y;
_coef = _AtA.fullPivHouseholderQr().solve(_Atb);
cout<<"AtA: "<<_AtA<<"\n"<<"Atb: "<<_Atb<<endl;
}
Matrix LinearRegression::predict(Matrix X)
{
// auto ret = MatrixXd::Zero(X.rows(), 1);
return X*_coef;
}
#pragma once
#include "types.h"
class LinearRegression {
public:
LinearRegression();
void fit(Matrix X, Matrix y);
MatrixXd get_AtA(void);
MatrixXd get_coef(void);
Matrix predict(Matrix X);
private:
MatrixXd _AtA;
MatrixXd _Atb;
MatrixXd _coef;
};
\ No newline at end of file
//
// Created by pachi on 5/6/19.
//
#include <iostream>
#include "linear_regression.h"
int main(int argc, char** argv){
std::cout << "Hola mundo!" << std::endl;
return 0;
}
//
// Created by pachi on 5/6/19.
// Ejemplo basado en la pregunta de stackoverflow:
// https://stackoverflow.com/questions/47762543/segfault-when-using-pybind11-wrappers-in-c
#include <iostream>
#include "pca.h"
#include "eigen.h"
#include <pybind11/embed.h>
namespace py = pybind11;
int main(int argc, char** argv){
py::scoped_interpreter guard{};
py::print("Hola pybind!");
return 0;
}
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include "linear_regression.h"
namespace py=pybind11;
// el primer argumento es el nombre...
PYBIND11_MODULE(metnum, m) {
py::class_<LinearRegression>(m, "LinearRegression")
.def(py::init<>())
.def("get_AtA", &LinearRegression::get_AtA)
.def("get_coef", &LinearRegression::get_coef)
.def("fit", &LinearRegression::fit)
.def("predict", &LinearRegression::predict);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment