-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import math | ||
from functools import reduce | ||
from itertools import starmap | ||
from operator import mul | ||
|
||
import numpy as np | ||
|
||
from cubed.types import T_DType, T_RegularChunks, T_Shape | ||
|
||
|
||
class ArrayMetadata: | ||
def __init__( | ||
self, | ||
shape: T_Shape, | ||
dtype: T_DType, | ||
chunks: T_RegularChunks, | ||
): | ||
self.shape = shape | ||
self.dtype = np.dtype(dtype) | ||
self.chunks = chunks | ||
|
||
@property | ||
def size(self) -> int: | ||
"""Number of elements in the array.""" | ||
return reduce(mul, self.shape, 1) | ||
|
||
@property | ||
def nbytes(self) -> int: | ||
"""Number of bytes in array""" | ||
return self.size * self.dtype.itemsize | ||
|
||
@property | ||
def _cdata_shape(self) -> T_Shape: | ||
"""The shape of the chunk grid for this array.""" | ||
return tuple( | ||
starmap( | ||
lambda s, c: math.ceil(s / c), | ||
zip(self.shape, self.chunks, strict=False), | ||
) | ||
) | ||
|
||
@property | ||
def nchunks(self) -> int: | ||
"""Number of chunks in array""" | ||
return reduce(mul, self._cdata_shape, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters