tame/core/vector/count.xml

48 lines
1.6 KiB
XML

<?xml-stylesheet type="text/xsl" href="summary.xsl"?>
<lv:package
xmlns:lv="http://www.lovullo.com/rater"
xmlns:c="http://www.lovullo.com/calc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.lovullo.com/rater ../../rater.xsd"
core="true"
name="core/vector/count"
desc="Vector element counting">
<lv:import package="../base" />
<!-- TODO: deprecate in favor of the new c:length-of -->
<lv:function name="length" desc="Counts the number of items in a vector (regardless of value)">
<lv:param name="count_set" type="integer" set="vector" desc="Vector to count" />
<c:sum of="count_set" index="k">
<c:const value="1" type="integer" desc="Add 1 for each value in the set" />
</c:sum>
</lv:function>
<!-- similar to a logical "exists" -->
<lv:function name="hasany" desc="Returns 1 or 0 based on whether any values in a boolean vector are set" sym="\exists">
<lv:param name="any_set" type="boolean" set="vector" desc="Boolean set to check" />
<c:ceil>
<c:quotient label="Create a fraction > 0 if any value in the given set is 1">
<c:sum of="any_set" label="Will be > 0 if any 1s exist in the set" />
<c:sum>
<c:apply name="length">
<c:arg name="count_set">
<c:value-of name="any_set" />
</c:arg>
</c:apply>
<!-- ensure the equation is not undefined if length = 0 -->
<c:const value="1" type="integer" desc="Add 1 to ensure equation is always defined" />
</c:sum>
</c:quotient>
</c:ceil>
</lv:function>
</lv:package>