[docs]classDenseCellArray(CellArray):"""Implementation for dense TileDB arrays."""def_direct_slice(self,key:Tuple[slice,...])->np.ndarray:"""Implementation for direct slicing of dense arrays. Args: key: Tuple of slice objects. Returns: Sliced data. """withself.open_array(mode="r")asarray:res=array[key]returnres[self._attr]ifself._attrisnotNoneelseresdef_multi_index(self,key:Tuple[Union[slice,List[int]],...])->np.ndarray:"""Implementation for multi-index access of dense arrays. Args: key: Tuple of slice objects or index lists. Returns: Sliced data. """# Try to optimize contiguous indices to slicesoptimized_key=[]foridxinkey:ifisinstance(idx,list):slice_idx=SliceHelper.is_contiguous_indices(idx)optimized_key.append(slice_idxifslice_idxisnotNoneelseidx)else:optimized_key.append(idx)# If all indices are now slices, use direct slicingifall(isinstance(idx,slice)foridxinoptimized_key):returnself._direct_slice(tuple(optimized_key))# For mixed slice-list queries, adjust slice bounds to exclude upper boundtiledb_key=[]foridxinkey:ifisinstance(idx,slice):# Adjust stop to be exclusive by subtracting 1 if stop is not Nonestop=Noneifidx.stopisNoneelseidx.stop-1tiledb_key.append(slice(idx.start,stop,idx.step))else:tiledb_key.append(idx)withself.open_array(mode="r")asarray:res=array.multi_index[tuple(tiledb_key)]returnres[self._attr]ifself._attrisnotNoneelseres
[docs]defwrite_batch(self,data:np.ndarray,start_row:int,**kwargs)->None:"""Write a batch of data to the dense array. Args: data: Numpy array to write. start_row: Starting row index for writing. **kwargs: Additional arguments passed to TileDB write operation. Raises: TypeError: If input is not a numpy array. ValueError: If dimensions don't match or bounds are exceeded. """ifnotisinstance(data,np.ndarray):raiseTypeError("Input must be a numpy array.")iflen(data.shape)!=self.ndim:raiseValueError(f"Data dimensions {data.shape} don't match array dimensions {self.shape}.")# Check boundsend_row=start_row+data.shape[0]ifend_row>self.shape[0]:raiseValueError(f"Write operation would exceed array bounds. End row {end_row} > array rows {self.shape[0]}.")ifself.ndim==2anddata.shape[1]!=self.shape[1]:raiseValueError(f"Data columns {data.shape[1]} don't match array columns {self.shape[1]}.")# Construct write regionifself.ndim==1:write_region=slice(start_row,end_row)else:# 2Dwrite_region=(slice(start_row,end_row),slice(0,self.shape[1]))# write_data = {self._attr: data} if len(self.attr_names) > 1 else datawithself.open_array(mode="w")asarray:array[write_region]=data