Closed AprilYUZhang closed 4 months ago
The same issue:
createChildSegs(
segregationTensor, currentSeg, childSegTensor[index, :, :, :, :]
)
def createChildSegs(segregationTensor, currentSeg, output):
# childSegs[index,:,:,:,:] = np.einsum("abcd, di -> abci", segregationTensor, currentSeg)
nLoci = currentSeg.shape[1]
output[:, :, :, :] = 0
for a in range(4):
for b in range(4):
for c in range(4):
for d in range(4):
for i in range(nLoci):
output[a, b, c, i] += (
segregationTensor[a, b, c, d] * currentSeg[d, i]
)
return output
projectChildGenotypes(
childSegTensor[index, :, :, :, :],
childValues,
childToParents[index, :, :, :],
)
def projectChildGenotypes(childSegs, childValues, output):
# childToParents[index,:,:,:] = np.einsum("abci, ci -> abi", childSegs[index,:,:,:,:], childValues)
nLoci = childSegs.shape[3]
output[:, :, :] = 0
for a in range(4):
for b in range(4):
for c in range(4):
for i in range(nLoci):
output[a, b, i] += childSegs[a, b, c, i] * childValues[c, i]
return output
projectParentGenotypes(
childSegTensor[i, :, :, :, :],
parentsMinusChild[i, :, :, :],
anterior[child, :, :],
)
@jit(nopython=True, nogil=True)
def projectParentGenotypes(childSegs, parentValues, output):
# anterior[child,:,:] = np.einsum("abci, abi -> ci", childSegs[i,:,:,:,:], parentsMinusChild[i,:,:,:])
nLoci = childSegs.shape[3]
output[:, :] = 0
for a in range(4):
for b in range(4):
for c in range(4):
for i in range(nLoci):
output[c, i] += childSegs[a, b, c, i] * parentValues[a, b, i]
return output
@AprilYUZhang Arrays are mutable objects which means that their values are changed even when they are not returned as the outputs of the functions.
It still makes me confused because these function just create a new array and there is no object to accept this array rather than changing the original arrays.
It still makes me confused because these function just create a new array and there is no object to accept this array rather than changing the original arrays.
Actually, no new array would be created when the function is called, and this is a result of how mutable objects are constructed and stored. Here is a good reference for the mutable objects: https://realpython.com/python-mutable-vs-immutable-types/
Thank you; I got it. "return output" is useless, right?
Thank you; I got it. "return output" is useless, right?
:) No return is needed.
This function as follows didn't value a object, has it been discard?