Skip to content

Commit

Permalink
Verifying the data is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 15, 2023
1 parent 54dce49 commit 7d686ae
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
16 changes: 12 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
"configurations": [
{
"name": "Linux",
"compilerPathInCppPropertiesJson": "/usr/bin/clang",
"includePath": [
"${workspaceFolder}/**"
"include/**"
"/home/george/Documents/development/pydefm/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
"intelliSenseMode": "linux-clang-x64",
"mergeConfigurations": false,
"compilerPath": "/usr/bin/clang",
"configurationProvider": "ms-vscode.makefile-tools",
"browse": {
"path": [
"/home/george/Documents/development/pydefm"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"


[project]
name = "pydefm"
name = "scikit_build_example"
version = "0.0.1"
description="Python bindings for defm"
readme = "README.md"
Expand Down
29 changes: 26 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ std::shared_ptr< defm::DEFM > new_defm(
// std::vector<int> y = {1, 2, 3, 4, 5};
// std::vector<double> x = {1.0, 2.0, 3.0, 4.0, 5.0};

// Accessing the data buffer
auto id_buff = id.request();
auto y_buff = y.request();
auto x_buff = x.request();

int n_id = id.size();
int n_y = y.size();
int n_x = x.size();

std::shared_ptr< defm::DEFM > object(new defm::DEFM(
id.mutable_data(0u),
y.mutable_data(0u),
x.mutable_data(0u),
static_cast< int * >(id_buff.ptr),
static_cast< int * >(y_buff.ptr),
static_cast< double * >(x_buff.ptr),
static_cast< size_t >(n_id),
static_cast< size_t >(n_y),
static_cast< size_t >(n_x),
Expand All @@ -42,8 +47,20 @@ std::shared_ptr< defm::DEFM > new_defm(
return object;
}

/**
* @brief Print the y vector
* @param object The DEFM object
*/
void print_y(const std::shared_ptr< defm::DEFM > & object) {

auto Y = object->get_Y();
for (size_t i = 0u; i < object->get_n_y(); ++i)
std::cout << (*(Y + i)) << " ";

std::cout << std::endl;

return;
}

PYBIND11_MODULE(_core, m) {
m.doc() = R"pbdoc(
Expand Down Expand Up @@ -88,6 +105,12 @@ PYBIND11_MODULE(_core, m) {
Some other explanation about the new_defm function.
)pbdoc");

m.def("print_y", &print_y, R"pbdoc(
Print the y vector
Some other explanation about the print_y function.")
)pbdoc");

#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

from ._core import __doc__, __version__, add, subtract, new_defm
from ._core import __doc__, __version__, add, subtract, new_defm, print_y

__all__ = ["__doc__", "__version__", "add", "subtract", "new_defm"]
__all__ = ["__doc__", "__version__", "add", "subtract", "new_defm", "print_y"]
15 changes: 11 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import scikit_build_example as m
import numpy as np

y = np.array([1, 2, 3])
x = np.array([1, 2, 3])
id = np.array([1, 2, 3])
y = np.array([0, 10, 3])
x = np.array([1, 2.0, 3.4])
id = np.array([11, 2, 3])

m.new_defm(y, x, id)
obj = m.new_defm(id, y, x)

obj.print()

# Just testing whether the function works
m.print_y(obj)


def test_version():
Expand All @@ -20,3 +25,5 @@ def test_add():

def test_sub():
assert m.subtract(1, 2) == -1

print("Everything passed")

0 comments on commit 7d686ae

Please sign in to comment.