code: def __init__(
      self,
      in_dim: int,
      out_dim: Optional[int],
      *,
      num_tree: int = 10,
      tree_depth: int = 4,
      is_regression: Optional[bool] = None,
      tree_proj_config: Optional[Dict[str, Any]] = None,
      use_fast_dndf: bool = True,
  ):
      super().__init__()
      self._num_tree = num_tree
      self._tree_depth = tree_depth
      self._is_regression = is_regression
      if out_dim is not None and is_regression is None:
          self._is_regression = out_dim == 1
      self._num_leaf = 2 ** (self._tree_depth + 1)
      self._num_internals = self._num_leaf - 1
      self._output_dim = out_dim
      self._fast = use_fast_dndf
      if tree_proj_config is None:
          tree_proj_config = {}
      tree_proj_config.setdefault("pruner_config", {})
      self.tree_proj = Linear(
          in_dim,
          self._num_internals * self._num_tree,
          **tree_proj_config,
      )
      if out_dim is None:
          self.leaves = None
      else:
          leaves_shape = self._num_tree * self._num_leaf, out_dim
          self.leaves = nn.Parameter(torch.empty(*leaves_shape))
          with torch.no_grad():
              torch.nn.init.xavier_uniform_(self.leaves.data)
      # buffers
      num_repeat, num_local_internals = self._num_leaf // 2, 1
      ones_np = np.repeat([1, -1], num_repeat)
      ones_list = [torch.from_numpy(ones_np.astype(np.float32))]
      increment_indices_np = np.repeat(
          [0, self._num_internals], num_repeat
      )
      increment_indices = [
          torch.from_numpy(increment_indices_np.astype(np.int64))
      ]
      for i in range(1, self._tree_depth + 1):
          num_repeat //= 2
          num_local_internals *= 2
          arange = np.arange(
              num_local_internals - 1, 2 * num_local_internals - 1
          )
          ones_np = np.repeat([1, -1], num_repeat)
          ones_np = np.tile(ones_np, 2**i)
          ones_list.append(torch.from_numpy(ones_np.astype(np.float32)))
          increment_mask = np.repeat(arange, 2)
          increment_mask += np.tile(
              [0, self._num_internals], num_local_internals
          )
          increment_mask = np.repeat(increment_mask, num_repeat)
          increment_mask_ = torch.from_numpy(
              increment_mask.astype(np.int64)
          )
          increment_indices.append(increment_mask_)
      self.increment_masks: Tensor
      self.register_buffer(
          "tree_arange", torch.arange(num_tree)[..., None, None]
      )
      self.register_buffer("ones", torch.stack(ones_list))
      self.register_buffer(
          "increment_indices", torch.stack(increment_indices)
      )
  
imports: import math
  import torch
  import numpy
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from typing import Any
  from typing import Dict
  from typing import List
  from typing import Tuple
  from typing import Union
  from typing import Callable
  from typing import Optional
  from functools import partial
  from torch.nn import Module
  from cftool.misc import print_warning
  from .hooks import IBasicHook
label_desc: Use image node_id 1 to create a new DNDF object from inherited base classes: Module with example: obj = DNDF(in_dim, out_dim)