Skip to content

Commit

Permalink
Add TinyAD
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcasmar committed Jul 17, 2024
1 parent b81e7e3 commit 0586e9b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions recipes/tinyad/all/conandata.yml
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"
53 changes: 53 additions & 0 deletions recipes/tinyad/all/conanfile.py
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

Check warning on line 2 in recipes/tinyad/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused CMake imported from conan.tools.cmake
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

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused apply_conandata_patches imported from conan.tools.files

Check warning on line 3 in recipes/tinyad/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused export_conandata_patches imported from conan.tools.files

Check warning on line 3 in recipes/tinyad/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused rmdir imported from conan.tools.files
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"]

7 changes: 7 additions & 0 deletions recipes/tinyad/all/test_package/CMakeLists.txt
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)
25 changes: 25 additions & 0 deletions recipes/tinyad/all/test_package/conanfile.py
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")
18 changes: 18 additions & 0 deletions recipes/tinyad/all/test_package/test_package.cpp
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;
}
3 changes: 3 additions & 0 deletions recipes/tinyad/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20240718":
folder: all

0 comments on commit 0586e9b

Please sign in to comment.