<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_allele_counts(self, max_allele=None, dtype='u1'):
 """Transform genotype calls into allele counts per call. Parameters max_allele : int, optional Highest allele index. Provide this value to speed up computation. dtype : dtype, optional Output dtype. Returns ------- out : ndarray, uint8, shape (n_variants, n_samples, len(alleles)) Array of allele counts per call. Examples -------- <GenotypeAlleleCountsArray shape=(3, 2, 3) dtype=uint8> 2:0:0 1:1:0 1:0:1 0:2:0 0:0:2 0:0:0 <GenotypeVector shape=(3, 2) dtype=int64> 0/0 0/2 2/2 <GenotypeAlleleCountsVector shape=(3, 3) dtype=uint8> 2:0:0 1:0:1 0:0:2 """


        # determine alleles to count
        if max_allele is None:
            max_allele = self.max()
        alleles = list(range(max_allele + 1))

        # set up output array
        outshape = self.shape[:-1] + (len(alleles),)
        out = np.zeros(outshape, dtype=dtype)

        for allele in alleles:
            # count alleles along ploidy dimension
            allele_match = self.values == allele
            if self.mask is not None:
                allele_match &= ~self.mask[..., np.newaxis]
            np.sum(allele_match, axis=-1, out=out[..., allele])

        if self.ndim == 2:
            out = GenotypeAlleleCountsVector(out)
        elif self.ndim == 3:
            out = GenotypeAlleleCountsArray(out)

        return out