Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cnpy-1.0] upload lib #4032

Merged
merged 26 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c062578
create cnpy package
hongyx11 Dec 29, 2020
222547b
change python indention
hongyx11 Dec 29, 2020
5c5289e
Update recipes/cnpy/all/test_package/CMakeLists.txt
hongyx11 Dec 30, 2020
e50dbd9
Update recipes/cnpy/all/test_package/conanfile.py
hongyx11 Dec 30, 2020
00a87d7
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
4468aa5
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
a1637d4
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
f9b830d
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
61c962f
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
0609113
Fix package version
uilianries Dec 30, 2020
0cf1083
Fix Windows build
uilianries Dec 30, 2020
41cbe90
Export all symbols
uilianries Dec 30, 2020
0452853
cnpy: Update Conan conventions
bincrafters-user Dec 30, 2020
af8ed66
Merge pull request #1 from bincrafters/package/cnpy
hongyx11 Dec 31, 2020
10b925d
fix windows problem
hongyx11 Dec 31, 2020
bc4066f
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 31, 2020
12102c0
update example test
hongyx11 Dec 31, 2020
ff276c0
Merge branch 'master' of github.com:hongyx11/conan-center-index
hongyx11 Dec 31, 2020
c4bfc6d
add new line
hongyx11 Dec 31, 2020
6195031
update remove exampletest
hongyx11 Dec 31, 2020
ff5f731
update remove exampletest
hongyx11 Dec 31, 2020
213b1f4
Update recipes/cnpy/all/test_package/conanfile.py
hongyx11 Dec 31, 2020
33a0c0e
Update recipes/cnpy/all/test_package/example1.cpp
hongyx11 Dec 31, 2020
4504142
windows
hongyx11 Dec 31, 2020
7159ae8
update
hongyx11 Dec 31, 2020
d5d8896
Update recipes/cnpy/all/conanfile.py
hongyx11 Jan 1, 2021
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
7 changes: 7 additions & 0 deletions recipes/cnpy/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15.0)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/cnpy/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0":
url: "https://github.com/hongyx11/cnpy/archive/v1.0.tar.gz"
sha256: "a61b209c268db20a00240876df9fd8314a73d3c9b4139d00a0df048fe9c8e59f"
65 changes: 65 additions & 0 deletions recipes/cnpy/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os

from conans import ConanFile, CMake, tools

class CnpyConan(ConanFile):
name = "cnpy"
description = "cnpy conan package"
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
license = "MIT License"
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
topics = ("conan", "cnpy")
homepage = "https://github.com/hongyx11/cnpy"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
settings = "os", "arch", "compiler", "build_type"
_cmake = None

options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"fPIC": True
}

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
del self.settings.compiler.libcxx
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
del self.settings.compiler.cppstd
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved

def source(self):
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
tools.get(**self.conan_data["sources"][self.version])
os.rename(self.name + "-" + self.version, self._source_subfolder)

def build(self):
cmake = self._configure_cmake()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "cnpy"
self.cpp_info.names["cmake_find_package_multi"] = "cnpy"
self.cpp_info.libs = tools.collect_libs(self)
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions recipes/cnpy/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15.0)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
set(CMAKE_CXX_STANDARD 11)
add_executable(${PROJECT_NAME} example1.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions recipes/cnpy/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
requires = [
"zlib/1.2.11"
]
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
55 changes: 55 additions & 0 deletions recipes/cnpy/all/test_package/example1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include"cnpy.h"
#include<complex>
#include<cstdlib>
#include<iostream>
#include<map>
#include<string>

const int Nx = 128;
const int Ny = 64;
const int Nz = 32;

int main()
{
//set random seed so that result is reproducible (for testing)
srand(0);
//create random data
std::vector<std::complex<double>> data(Nx*Ny*Nz);
for(int i = 0;i < Nx*Ny*Nz;i++) data[i] = std::complex<double>(rand(),rand());

//save it to file
cnpy::npy_save("arr1.npy",&data[0],{Nz,Ny,Nx},"w");

//load it into a new array
cnpy::NpyArray arr = cnpy::npy_load("arr1.npy");
std::complex<double>* loaded_data = arr.data<std::complex<double>>();

//make sure the loaded data matches the saved data
assert(arr.word_size == sizeof(std::complex<double>));
assert(arr.shape.size() == 3 && arr.shape[0] == Nz && arr.shape[1] == Ny && arr.shape[2] == Nx);
for(int i = 0; i < Nx*Ny*Nz;i++) assert(data[i] == loaded_data[i]);

//append the same data to file
//npy array on file now has shape (Nz+Nz,Ny,Nx)
cnpy::npy_save("arr1.npy",&data[0],{Nz,Ny,Nx},"a");

//now write to an npz file
//non-array variables are treated as 1D arrays with 1 element
double myVar1 = 1.2;
char myVar2 = 'a';
cnpy::npz_save("out.npz","myVar1",&myVar1,{1},"w"); //"w" overwrites any existing file
cnpy::npz_save("out.npz","myVar2",&myVar2,{1},"a"); //"a" appends to the file we created above
cnpy::npz_save("out.npz","arr1",&data[0],{Nz,Ny,Nx},"a"); //"a" appends to the file we created above

//load a single var from the npz file
cnpy::NpyArray arr2 = cnpy::npz_load("out.npz","arr1");

//load the entire npz file
cnpy::npz_t my_npz = cnpy::npz_load("out.npz");

//check that the loaded myVar1 matches myVar1
cnpy::NpyArray arr_mv1 = my_npz["myVar1"];
double* mv1 = arr_mv1.data<double>();
assert(arr_mv1.shape.size() == 1 && arr_mv1.shape[0] == 1);
assert(mv1[0] == myVar1);
}
3 changes: 3 additions & 0 deletions recipes/cnpy/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0":
folder: all