code: def test_feature_extract(rng):
      # Test that features are automatically cast into float32 when
      # coming from Python space
      class CenterOfMass64bit(dipysfeature.Feature):
          def infer_shape(self, streamline):
              return streamline.shape[1]
  
          def extract(self, streamline):
              return np.mean(streamline.astype(np.float64), axis=0)
  
      nb_streamlines = 100
      feature_shape = (1, 3)  # One N-dimensional point
      feature = CenterOfMass64bit()
  
      nb_points = rng.integers(20, 30, size=(nb_streamlines,)) * 3
      streamlines = [
          np.arange(nb).reshape((-1, 3)).astype(np.float32)
          for nb in nb_points
      ]
      features = extract(feature, streamlines)
  
      assert_equal(len(features), len(streamlines))
      assert_equal(features[0].shape, feature_shape)
  
      # Test that scalar features
      class ArcLengthFeature(dipysfeature.Feature):
          def infer_shape(self, streamline):
              return 1
  
          def extract(self, streamline):
              square_norms = np.sum(
                  (streamline[1:] - streamline[:-1]) ** 2
              )
              return np.sum(np.sqrt(square_norms))
  
      feature_shape = (1, 1)  # One scalar represented as a 2D array
      feature = ArcLengthFeature()
  
      features = extract(feature, streamlines)
      assert_equal(len(features), len(streamlines))
      assert_equal(features[0].shape, feature_shape)
  
      # Try if streamlines are readonly
      for s in streamlines:
          s.setflags(write=False)
  
file_path: dipy/dipy/segment/tests/test_feature.py
imports: import sys
  import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_raises, assert_equal
  import dipy.segment.featurespeed
  import dipy.segment.metric
  import dipy.segment.metricspeed
  from dipy.segment.featurespeed import extract
  from dipy.testing import assert_true, assert_false
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 7 for calling a global function with example usage: test_feature_extract(rng) and returns: streamline, np, int, np