MCPcopy Create free account
hub / github.com/apache/madlib / svec_svec_angle

Function svec_svec_angle

methods/svec_util/src/pg_gp/svec_util.c:506–531  ·  view source on GitHub ↗

* svec_svec_angle - Computes the angle between two SVECs. */

Source from the content-addressed store, hash-verified

504 * svec_svec_angle - Computes the angle between two SVECs.
505 */
506Datum svec_svec_angle(PG_FUNCTION_ARGS)
507{
508 SvecType *svec1 = PG_GETARG_SVECTYPE_P(0);
509 SvecType *svec2 = PG_GETARG_SVECTYPE_P(1);
510 SparseData left = sdata_from_svec(svec1);
511 SparseData right = sdata_from_svec(svec2);
512 double dot, m1, m2, result;
513
514 dot = svec_svec_dot_product( svec1, svec2);
515
516 m1 = l2norm_sdata_values_double(left);
517 m2 = l2norm_sdata_values_double(right);
518
519 if (IS_NVP(dot) || IS_NVP(m1) || IS_NVP(m2)) PG_RETURN_NULL();
520
521 result = dot/(m1*m2);
522
523 if (result > 1.0) {
524 result = 1.0;
525 }
526 else if (result < -1.0) {
527 result = -1.0;
528 }
529
530 PG_RETURN_FLOAT8(acos(result));
531}
532
533PG_FUNCTION_INFO_V1( svec_svec_tanimoto_distance );
534/**

Callers

nothing calls this directly

Calls 3

sdata_from_svecFunction · 0.85
svec_svec_dot_productFunction · 0.85

Tested by

no test coverage detected