Skip to content

Commit 8165286

Browse files
authored
Remove unused math functions (#182)
Signed-off-by: Aleksandr Motsjonov <[email protected]>
1 parent 6cd7782 commit 8165286

File tree

2 files changed

+0
-306
lines changed

2 files changed

+0
-306
lines changed

src/rawtoaces_core/mathOps.h

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ namespace core
2020
{
2121

2222
// Non-class functions
23-
inline double invertD( double val )
24-
{
25-
assert( fabs( val - 0.0 ) >= DBL_EPSILON );
26-
27-
return 1.0 / val;
28-
};
29-
30-
template <typename T> T clip( T val, T target )
31-
{
32-
return std::min( val, target );
33-
};
3423

3524
template <typename T> int isSquare( const vector<vector<T>> &vm )
3625
{
@@ -126,16 +115,6 @@ template <typename T> vector<T> invertV( const vector<T> &vMtx )
126115
return result;
127116
};
128117

129-
template <typename T> vector<vector<T>> diagVM( const vector<T> &vct )
130-
{
131-
assert( vct.size() != 0 );
132-
vector<vector<T>> vctdiag( vct.size(), vector<T>( vct.size(), T( 0.0 ) ) );
133-
134-
FORI( vct.size() ) vctdiag[i][i] = vct[i];
135-
136-
return vctdiag;
137-
};
138-
139118
template <typename T> vector<T> diagV( const vector<T> &vct )
140119
{
141120
assert( vct.size() != 0 );
@@ -205,55 +184,6 @@ template <typename T> void scaleVector( vector<T> &vct, const T scale )
205184
return;
206185
};
207186

208-
template <typename T> void scale_vector_max( vector<T> &vector )
209-
{
210-
Eigen::Matrix<T, Eigen::Dynamic, 1> column_vector;
211-
column_vector.resize( vector.size(), 1 );
212-
213-
FORI( vector.size() )
214-
{
215-
column_vector( i, 0 ) = vector[i];
216-
}
217-
column_vector *= ( 1.0 / column_vector.maxCoeff() );
218-
219-
FORI( vector.size() )
220-
{
221-
vector[i] = column_vector( i, 0 );
222-
}
223-
224-
return;
225-
};
226-
227-
template <typename T> void scale_vector_min( vector<T> &vector )
228-
{
229-
Eigen::Matrix<T, Eigen::Dynamic, 1> column_vector;
230-
column_vector.resize( vector.size(), 1 );
231-
232-
FORI( vector.size() )
233-
{
234-
column_vector( i, 0 ) = vector[i];
235-
}
236-
column_vector *= ( 1.0 / column_vector.minCoeff() );
237-
238-
FORI( vector.size() )
239-
{
240-
vector[i] = column_vector( i, 0 );
241-
}
242-
243-
return;
244-
};
245-
246-
template <typename T> void scaleVectorD( vector<T> &vct )
247-
{
248-
Eigen::Matrix<T, Eigen::Dynamic, 1> v;
249-
v.resize( vct.size(), 1 );
250-
251-
FORI( v.rows() ) v( i, 0 ) = vct[i];
252-
FORI( v.rows() ) vct[i] = v.maxCoeff() / vct[i];
253-
254-
return;
255-
};
256-
257187
template <typename T>
258188
vector<T> mulVectorElement( const vector<T> &vct1, const vector<T> &vct2 )
259189
{
@@ -275,21 +205,6 @@ vector<T> mulVectorElement( const vector<T> &vct1, const vector<T> &vct2 )
275205
return vct3;
276206
};
277207

278-
template <typename T>
279-
vector<T> divVectorElement( const vector<T> &vct1, const vector<T> &vct2 )
280-
{
281-
assert( vct1.size() == vct2.size() );
282-
283-
vector<T> vct2D( vct2.size(), T( 1.0 ) );
284-
FORI( vct2.size() )
285-
{
286-
assert( vct2[i] != T( 0.0 ) );
287-
vct2D[i] = T( 1.0 ) / vct2[i];
288-
}
289-
290-
return mulVectorElement( vct1, vct2D );
291-
};
292-
293208
template <typename T>
294209
vector<T> mulVector( vector<T> vct1, vector<T> vct2, int k = 3 )
295210
{
@@ -368,73 +283,6 @@ vector<T> mulVector( const vector<T> &vct1, const vector<vector<T>> &vct2 )
368283
return mulVector( vct2, vct1 );
369284
};
370285

371-
template <typename T>
372-
T *mulVectorArray(
373-
T *data,
374-
const uint32_t total,
375-
const uint8_t dim,
376-
const vector<vector<double>> &vct )
377-
{
378-
assert( vct.size() == dim && isSquare( vct ) );
379-
380-
/**
381-
// new implementation based on Eigen::Eigen::Matrix (Slow...)
382-
383-
Eigen::Matrix <T, Eigen::Dynamic, Eigen::Dynamic> MI, mvct;
384-
MI.resize(total/dim, dim);
385-
mvct.resize(dim, dim);
386-
FORIJ(MI.rows(), MI.cols()) MI(i,j) = data[i*dim+j];
387-
FORIJ(dim, dim) mvct(i,j) = static_cast<T>(vct[i][j]);
388-
389-
Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic,RowMajor> MR(MI * (mvct.transpose()));
390-
FORI(total) data[i] = MR(i);
391-
*/
392-
393-
if ( dim == 3 || dim == 4 )
394-
{
395-
for ( uint32_t i = 0; i < total; i += dim )
396-
{
397-
T temp[4];
398-
399-
for ( uint8_t j = 0; j < dim; j++ )
400-
{
401-
temp[j] = 0;
402-
403-
for ( uint8_t k = 0; k < dim; k++ )
404-
temp[j] += vct[j][k] * data[i + k];
405-
}
406-
407-
for ( uint8_t j = 0; j < dim; j++ )
408-
data[i + j] = temp[j];
409-
}
410-
}
411-
412-
return data;
413-
};
414-
415-
template <typename T>
416-
vector<vector<T>>
417-
solveVM( const vector<vector<T>> &vct1, const vector<vector<T>> &vct2 )
418-
{
419-
420-
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> m1, m2, m3;
421-
m1.resize( vct1.size(), vct1[0].size() );
422-
m2.resize( vct2.size(), vct2[0].size() );
423-
424-
FORIJ( vct1.size(), vct1[0].size() )
425-
m1( i, j ) = vct1[i][j];
426-
FORIJ( vct2.size(), vct2[0].size() )
427-
m2( i, j ) = vct2[i][j];
428-
429-
// colPivHouseholderQr()
430-
m3 = m1.jacobiSvd( Eigen::ComputeThinU | Eigen::ComputeThinV ).solve( m2 );
431-
432-
vector<vector<T>> vct3( m3.rows(), vector<T>( m3.cols() ) );
433-
FORIJ( m3.rows(), m3.cols() ) vct3[i][j] = m3( i, j );
434-
435-
return vct3;
436-
};
437-
438286
/// Calculate the Sum of Squared Errors (SSE) between two vectors.
439287
/// The SSE measures how well the calculated values (tcp) match the reference values (src).
440288
/// Formula: Σ((tcp[i] / src[i] - 1)²)

tests/testMath.cpp

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@
1313

1414
using namespace rta::core;
1515

16-
void test_InvertD()
17-
{
18-
double a = 1.0;
19-
OIIO_CHECK_EQUAL_THRESH( invertD( a ), 1.0, 1e-9 );
20-
21-
double b = 1000.0;
22-
OIIO_CHECK_EQUAL_THRESH( invertD( b ), 0.001, 1e-9 );
23-
24-
double c = 1000000.0;
25-
OIIO_CHECK_EQUAL_THRESH( invertD( c ), 0.000001, 1e-9 );
26-
};
27-
28-
void test_Clip()
29-
{
30-
double a = 254.9;
31-
OIIO_CHECK_EQUAL_THRESH( clip( a, 255.0 ), a, 1e-5 );
32-
33-
double b = 255.1;
34-
OIIO_CHECK_EQUAL_THRESH( clip( b, 255.0 ), 255.0, 1e-5 );
35-
36-
double c = 63355.0;
37-
OIIO_CHECK_EQUAL_THRESH( clip( c, 63355.0 ), c, 1e-5 );
38-
};
39-
4016
void test_IsSquare()
4117
{
4218
vector<vector<double>> a;
@@ -126,24 +102,6 @@ void test_InvertV()
126102
FORI( 9 ) OIIO_CHECK_EQUAL_THRESH( V_Inverse[i], MV_Inverse[i], 1e-5 );
127103
};
128104

129-
void test_DiagVM()
130-
{
131-
double M[3][3] = { { 1.0, 0.0, 0.0 },
132-
{ 0.0, 2.0, 0.0 },
133-
{ 0.0, 0.0, 3.0 } };
134-
135-
double vd[3] = { 1.0, 2.0, 3.0 };
136-
vector<double> MV( vd, vd + 3 );
137-
vector<vector<double>> MVD = diagVM( MV );
138-
139-
FORI( 3 )
140-
{
141-
OIIO_CHECK_EQUAL_THRESH( MVD[i][0], M[i][0], 1e-5 );
142-
OIIO_CHECK_EQUAL_THRESH( MVD[i][1], M[i][1], 1e-5 );
143-
OIIO_CHECK_EQUAL_THRESH( MVD[i][2], M[i][2], 1e-5 );
144-
}
145-
};
146-
147105
void test_DiagV()
148106
{
149107
double v[3] = { 1.0, 2.0, 3.0 };
@@ -200,41 +158,6 @@ void test_SumVector()
200158
OIIO_CHECK_EQUAL_THRESH( sum, 55.0000, 1e-5 );
201159
};
202160

203-
void test_ScaleVectorMax()
204-
{
205-
double M[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
206-
double M_Scaled[10] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
207-
vector<double> MV( M, M + 10 );
208-
209-
scale_vector_max( MV );
210-
FORI( MV.size() )
211-
OIIO_CHECK_EQUAL_THRESH( M_Scaled[i], MV[i], 1e-5 );
212-
};
213-
214-
void test_ScaleVectorMin()
215-
{
216-
double M[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
217-
vector<double> MV( M, M + 10 );
218-
219-
scale_vector_min( MV );
220-
FORI( MV.size() )
221-
OIIO_CHECK_EQUAL_THRESH( M[i], MV[i], 1e-5 );
222-
};
223-
224-
void test_scaleVectorD()
225-
{
226-
double M[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
227-
double M_Scaled[10] = { 10.0000000000, 5.0000000000, 3.3333333333,
228-
2.5000000000, 2.0000000000, 1.6666666667,
229-
1.4285714286, 1.2500000000, 1.1111111111,
230-
1.0000000000 };
231-
vector<double> MV( M, M + 10 );
232-
233-
scaleVectorD( MV );
234-
FORI( MV.size() )
235-
OIIO_CHECK_EQUAL_THRESH( MV[i], M_Scaled[i], 1e-5 );
236-
};
237-
238161
void test_MulVectorElement()
239162
{
240163
double M1[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
@@ -249,19 +172,6 @@ void test_MulVectorElement()
249172
OIIO_CHECK_EQUAL_THRESH( MV3[i], 10.0000000000, 1e-5 );
250173
};
251174

252-
void test_DivVectorElement()
253-
{
254-
double M1[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
255-
double M2[10] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
256-
257-
vector<double> MV1( M1, M1 + 10 );
258-
vector<double> MV2( M2, M2 + 10 );
259-
260-
vector<double> MV3 = divVectorElement( MV1, MV2 );
261-
FORI( MV3.size() )
262-
OIIO_CHECK_EQUAL_THRESH( MV3[i], 1.0000000000, 1e-5 );
263-
};
264-
265175
void test_MulVector1()
266176
{
267177
double M1[3][3] = { { 1.0, 0.0, 0.0 },
@@ -312,61 +222,6 @@ void test_MulVector2()
312222
OIIO_CHECK_EQUAL_THRESH( MV3[i], M2[i], 1e-5 );
313223
};
314224

315-
void test_MulVectorArray()
316-
{
317-
double data[9] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
318-
double M[3][3] = { { 1.0000000000, 0.1000000000, 0.0100000000 },
319-
{ 0.1000000000, 2.0000000000, 0.0100000000 },
320-
{ 0.1000000000, 0.0100000000, 3.0000000000 }
321-
322-
};
323-
324-
double data_test[9] = { 1.2300000000, 4.13000000000, 9.12000000000,
325-
4.5600000000, 10.4600000000, 18.4500000000,
326-
7.8900000000, 16.7900000000, 27.7800000000 };
327-
328-
vector<vector<double>> MV( 3, vector<double>( 3 ) );
329-
FORIJ( 3, 3 )
330-
MV[i][j] = M[i][j];
331-
332-
mulVectorArray( data, 9, 3, MV );
333-
FORI( 9 )
334-
OIIO_CHECK_EQUAL_THRESH( data[i], data_test[i], 1e-5 );
335-
};
336-
337-
void test_SolveVM()
338-
{
339-
double M1[3][3] = { { 1.0000000000, 0.0000000000, 0.0000000000 },
340-
{ 0.0000000000, 2.0000000000, 0.0000000000 },
341-
{ 0.0000000000, 0.0000000000, 3.0000000000 }
342-
343-
};
344-
double M2[3][3] = { { 1.0000000000, 0.0000000000, 0.0000000000 },
345-
{ 0.0000000000, 1.0000000000, 0.0000000000 },
346-
{ 0.0000000000, 0.0000000000, 1.0000000000 }
347-
348-
};
349-
350-
double M3_test[3][3] = { { 1.0000000000, 0.0000000000, 0.0000000000 },
351-
{ 0.0000000000, 0.5000000000, 0.0000000000 },
352-
{ 0.0000000000, 0.0000000000, 0.3333333333 }
353-
354-
};
355-
356-
vector<vector<double>> MV1( 3, vector<double>( 3 ) );
357-
vector<vector<double>> MV2( 3, vector<double>( 3 ) );
358-
359-
FORIJ( 3, 3 )
360-
{
361-
MV1[i][j] = M1[i][j];
362-
MV2[i][j] = M2[i][j];
363-
}
364-
365-
vector<vector<double>> MV3 = solveVM( MV1, MV2 );
366-
FORIJ( 3, 3 )
367-
OIIO_CHECK_EQUAL_THRESH( MV3[i][j], M3_test[i][j], 1e-5 );
368-
};
369-
370225
void test_FindIndexInterp1()
371226
{
372227
int M[100];
@@ -909,27 +764,18 @@ void test_GetCalcXYZt()
909764

910765
int main( int, char ** )
911766
{
912-
test_InvertD();
913-
test_Clip();
914767
test_IsSquare();
915768
test_AddVectors();
916769
test_SubVectors();
917770
test_Cross2();
918771
test_InvertVM();
919772
test_InvertV();
920-
test_DiagVM();
921773
test_DiagV();
922774
test_TransposeVec();
923775
test_SumVector();
924-
test_ScaleVectorMax();
925-
test_ScaleVectorMin();
926-
test_scaleVectorD();
927776
test_MulVectorElement();
928-
test_DivVectorElement();
929777
test_MulVector1();
930778
test_MulVector2();
931-
test_MulVectorArray();
932-
test_SolveVM();
933779
test_FindIndexInterp1();
934780
test_Interp1DLinear();
935781
testIDT_XytoXYZ();

0 commit comments

Comments
 (0)