-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"cci.20240718": | ||
url: "https://github.com/patr-schm/TinyAD/archive/29417031c185b6dc27b6d4b684550d844459b735.tar.gz" | ||
sha256: "0458b9aabd31bff079aa5e9e559bd4753744c29f9ffce9d06a6510409c92e221" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain, CMakeDeps | ||
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir | ||
Check warning on line 3 in recipes/tinyad/all/conanfile.py GitHub Actions / Lint changed conanfile.py (v2 migration)
Check warning on line 3 in recipes/tinyad/all/conanfile.py GitHub Actions / Lint changed conanfile.py (v2 migration)
|
||
import os | ||
|
||
required_conan_version = ">=1.52.0" | ||
|
||
|
||
class TinyADConan(ConanFile): | ||
name = "tinyad" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/patr-schm/TinyAD" | ||
description = "TinyAD is a C++ header-only library for second-order automatic differentiation" | ||
topics = ("algebra", "linear-algebra", "optimization", "autodiff", "numerical", "header-only") | ||
package_type = "header-library" | ||
license = ("MIT") | ||
|
||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
def requirements(self): | ||
self.requires("eigen/3.4.0", transitive_headers=True) | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], | ||
destination=self.source_folder, strip_root=True) | ||
|
||
def generate(self): | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
tc = CMakeToolchain(self) | ||
tc.generate() | ||
|
||
def package(self): | ||
copy(self, "include/**", src=self.source_folder, dst=self.package_folder) | ||
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) | ||
|
||
def package_info(self): | ||
self.cpp_info.set_property("cmake_file_name", "TinyAD") | ||
self.cpp_info.set_property("cmake_target_name", "TinyAD") | ||
self.cpp_info.components["tinyad"].set_property("cmake_target_name", "TinyAD::TinyAD") | ||
|
||
self.cpp_info.components["tinyad"].bindirs = [] | ||
self.cpp_info.components["tinyad"].libdirs = [] | ||
self.cpp_info.components["tinyad"].includedirs = [os.path.join(self.package_folder, "include")] | ||
self.cpp_info.components["tinyad"].requires = ["eigen::eigen"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(TinyAD REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE TinyAD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake, cmake_layout | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <TinyAD/Scalar.hh> | ||
#include <Eigen/Dense> | ||
|
||
int main(void) { | ||
// Choose autodiff scalar type for 3 variables | ||
using ADouble = TinyAD::Double<3>; | ||
|
||
// Init a 3D vector of active variables and a 3D vector of passive variables | ||
Eigen::Vector3<ADouble> x = ADouble::make_active({0.0, -1.0, 1.0}); | ||
Eigen::Vector3<double> y(2.0, 3.0, 5.0); | ||
|
||
// Compute angle using Eigen functions and retrieve gradient and Hessian w.r.t. x | ||
ADouble angle = acos(x.dot(y) / (x.norm() * y.norm())); | ||
Eigen::Vector3d g = angle.grad; | ||
Eigen::Matrix3d H = angle.Hess; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20240718": | ||
folder: all |