[ https://issues.apache.org/jira/browse/NUMBERS-156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17340144#comment-17340144 ]
Matt Juntunen commented on NUMBERS-156: --------------------------------------- I've run some benchmarks and accuracy tests on {{SafeNorm}} vs the code above. The approaches I tested are * exact - BigDecimal with MathContext.DECIMAL128 * unsafe - direct, unchecked computation with doubles * safe - current {{SafeNorm}} code * herbert - the code above The accuracy results are below for 100,000 vectors of length 3. The "non-finite count" column indicates how many computed results were not finite. || Name || ulp error mean || ulp error std dev || non-finite count || | exact | 0.0 | 0.0 | 0 | | unsafe | 5578.94225972039 | 18.57625771920449 | 9803 | | safe | 0.01339 | 4.2343109585731824E-5 | 0 | | herbert | 2.0E-4 | 6.324586943350534E-7 | 0 | Here are the performance results for the same number of inputs: ||Benchmark||Mode||Cnt||Score||Error||Units|| |NormsPerformance.exact|avgt|5|1220297639.200 |± 356780909.362 |ns/op| |NormsPerformance.herbert|avgt|5|2477818.076 |± 256183.380 |ns/op| |NormsPerformance.safe|avgt|5|3116261.568 |± 603776.022 |ns/op| |NormsPerformance.unsafe|avgt|5|983066.792 |± 103953.143 |ns/op| _Conclusion_ The code Alex has above is far more accurate and moderately more performant than {{SafeNorm}}. I suggest we replace the existing {{SafeNorm}} implementation with this new code. The only question is how do we structure the API. Perhaps we could create a {{Norms}} class with methods for L!, L2, and LInf norms and overloads for 1D, 2D, 3D, and ND vectors? > SafeNorm 3D overload > -------------------- > > Key: NUMBERS-156 > URL: https://issues.apache.org/jira/browse/NUMBERS-156 > Project: Commons Numbers > Issue Type: Improvement > Reporter: Matt Juntunen > Priority: Major > > We should create an overload of {{SafeNorm.value}} that accepts 3 arguments > to potentially improve performance for 3D vectors. -- This message was sent by Atlassian Jira (v8.3.4#803005)