Skip to content

Commit

Permalink
switch to ptr param
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Mar 29, 2024
1 parent eb92fb7 commit bc11103
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions clic/include/tier7.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace cle::tier7
* @param device Device to perform the operation on. [const Device::Pointer &]
* @param src Input Array to be transformed. [const Array::Pointer &]
* @param dst Output Array. [Array::Pointer ( = None )]
* @param transform_matrix Affine transformation matrix (3x3 or 4x4). [std::vector<float> & ( = [] )]
* @param transform_matrix Affine transformation matrix (3x3 or 4x4). [std::vector<float> * ( = None )]
* @param interpolate If true, bi/trilinear interpolation will be applied, if hardware allows. [bool ( = False )]
* @param resize Automatically determines the size of the output depending on the rotation angles. [bool ( = False )]
* @return Array::Pointer
Expand All @@ -31,7 +31,7 @@ auto
affine_transform_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
std::vector<float> & transform_matrix,
std::vector<float> * transform_matrix,
bool interpolate,
bool resize) -> Array::Pointer;

Expand Down
28 changes: 14 additions & 14 deletions clic/src/tier7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ auto
affine_transform_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
std::vector<float> & transform_matrix,
std::vector<float> * transform_matrix,
bool interpolate,
bool resize) -> Array::Pointer
{
if (transform_matrix.empty())
if (transform_matrix == nullptr)
{
transform_matrix = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
transform_matrix = new std::vector<float>({ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 });
}
if (transform_matrix.size() != 16 && transform_matrix.size() != 9)
if (transform_matrix->size() != 16 && transform_matrix->size() != 9)
{
throw std::runtime_error("Error: Transformation matrix size must be 9 or 16.");
}
std::array<float, 16> transform_matrix_arr;
if (transform_matrix.size() == 9)
if (transform_matrix->size() == 9)
{
// Fill the array with the 3x3 matrix and the extra row and column for the 4x4 matrix
transform_matrix_arr = { transform_matrix[0],
transform_matrix[1],
transform_matrix_arr = { (*transform_matrix)[0],
(*transform_matrix)[1],
0,
transform_matrix[2],
transform_matrix[3],
transform_matrix[4],
(*transform_matrix)[2],
(*transform_matrix)[3],
(*transform_matrix)[4],
0,
transform_matrix[5],
transform_matrix[6],
transform_matrix[7],
(*transform_matrix)[5],
(*transform_matrix)[6],
(*transform_matrix)[7],
1,
0, // transform_matrix[8],
0,
Expand All @@ -53,7 +53,7 @@ affine_transform_func(const Device::Pointer & device,
else
{
// If the matrix is already 4x4, just copy the values
std::copy(transform_matrix.begin(), transform_matrix.end(), transform_matrix_arr.begin());
std::copy(transform_matrix->begin(), transform_matrix->end(), transform_matrix_arr.begin());
}
auto transform = AffineTransform(transform_matrix_arr);
return apply_affine_transform(src, dst, transform, interpolate, resize);
Expand Down
2 changes: 1 addition & 1 deletion tests/tier7/test_affine_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST_P(TestAffineTransform, affineTransform)
gpu_input->write(input.data());

std::vector<float> matrix = { 1, 0, -1, 0, 1, -1, 0, 0, 1 };
auto gpu_output = cle::tier7::affine_transform_func(device, gpu_input, nullptr, matrix, false, false);
auto gpu_output = cle::tier7::affine_transform_func(device, gpu_input, nullptr, &matrix, false, false);

gpu_output->read(output.data());
for (int i = 0; i < output.size(); i++)
Expand Down

0 comments on commit bc11103

Please sign in to comment.