11# frozen_string_literal: true
22
3+ require "numo/narray"
4+
35module GDAL
46 # @private
57 module InternalHelpers
@@ -62,14 +64,15 @@ def _buffer_from_data_type(data_type, size = nil)
6264 end
6365 end
6466
67+ # DEPRECATED: Use Numo::NArray directly instead.
6568 # @param data_type [FFI::GDAL::GDAL::DataType]
6669 # @param narray_args Args to pass to the NArray initializer.
67- # @return [NArray]
70+ # @return [Numo:: NArray]
6871 def _narray_from_data_type ( data_type , *narray_args )
69- init_meth = _gdal_data_type_to_narray ( data_type )
70- narray_args = 0 if narray_args . empty?
72+ numo_type = _gdal_data_type_to_numo_narray_type_constant ( data_type )
73+ narray_args = [ 1 ] if narray_args . empty?
7174
72- NArray . send ( init_meth , *narray_args )
75+ numo_type . zeros ( *narray_args )
7376 end
7477
7578 # Takes an array of strings (or things that should be converted to
@@ -155,42 +158,24 @@ def _gdal_data_type_to_ffi(data_type)
155158 end
156159 end
157160
158- # Maps GDAL DataTypes to NArray types.
161+ # DEPRECATED: These methods are deprecated. Use _gdal_data_type_to_numo_narray_type_constant instead.
162+ # Maps GDAL DataTypes to NArray types (deprecated).
159163 #
160164 # @param data_type [FFI::GDAL::GDAL::DataType]
161165 # @return [Symbol]
162166 def _gdal_data_type_to_narray ( data_type )
163- case data_type
164- when :GDT_Byte then :byte
165- when :GDT_Int16 then :sint
166- when :GDT_UInt16 , :GDT_Int32 , :GDT_UInt32 then :int
167- when :GDT_Float32 then :float
168- when :GDT_Float64 then :dfloat
169- when :GDT_CInt16 , :GDT_CInt32 then :scomplex
170- when :GDT_CFloat32 then :complex
171- when :GDT_CFloat64 then :dcomplex
172- else
173- raise GDAL ::InvalidDataType , "Unknown data type: #{ data_type } "
174- end
167+ # Delegate to Numo::NArray method
168+ _gdal_data_type_to_numo_narray_type_constant ( data_type )
175169 end
176170
177- # Maps GDAL DataTypes to NArray type constants.
171+ # DEPRECATED: Use _gdal_data_type_to_numo_narray_type_constant instead.
172+ # Maps GDAL DataTypes to NArray type constants (deprecated).
178173 #
179174 # @param data_type [FFI::GDAL::GDAL::DataType]
180- # @return [Symbol ]
175+ # @return [Class ]
181176 def _gdal_data_type_to_narray_type_constant ( data_type )
182- case data_type
183- when :GDT_Byte then NArray ::BYTE
184- when :GDT_Int16 then NArray ::SINT
185- when :GDT_UInt16 , :GDT_Int32 , :GDT_UInt32 then NArray ::INT
186- when :GDT_Float32 then NArray ::FLOAT
187- when :GDT_Float64 then NArray ::DFLOAT
188- when :GDT_CInt16 , :GDT_CInt32 then NArray ::SCOMPLEX
189- when :GDT_CFloat32 then NArray ::COMPLEX
190- when :GDT_CFloat64 then NArray ::DCOMPLEX
191- else
192- raise GDAL ::InvalidDataType , "Unknown data type: #{ data_type } "
193- end
177+ # Delegate to Numo::NArray method
178+ _gdal_data_type_to_numo_narray_type_constant ( data_type )
194179 end
195180
196181 # Maps GDAL DataTypes to [Numo::NArray] type constants.
@@ -199,12 +184,15 @@ def _gdal_data_type_to_narray_type_constant(data_type)
199184 # @return [Class]
200185 def _gdal_data_type_to_numo_narray_type_constant ( data_type )
201186 case data_type
202- when :GDT_Byte then Numo ::UInt8
203- when :GDT_Int16 then Numo ::Int16
204- when :GDT_UInt16 , :GDT_Int32 , :GDT_UInt32 then Numo ::Int32
205- when :GDT_Float32 then Numo ::SFloat
206- when :GDT_Float64 then Numo ::DFloat
207- when :GDT_CInt16 , :GDT_CInt32 , :GDT_CFloat32 , :GDT_CFloat64 then Numo ::SComplex
187+ when :GDT_Byte then Numo ::UInt8
188+ when :GDT_Int16 then Numo ::Int16
189+ when :GDT_UInt16 then Numo ::UInt16
190+ when :GDT_Int32 then Numo ::Int32
191+ when :GDT_UInt32 then Numo ::UInt32
192+ when :GDT_Float32 then Numo ::SFloat
193+ when :GDT_Float64 then Numo ::DFloat
194+ when :GDT_CInt16 , :GDT_CInt32 , :GDT_CFloat32 then Numo ::SComplex
195+ when :GDT_CFloat64 then Numo ::DComplex
208196 else
209197 raise GDAL ::InvalidDataType , "Unknown data type: #{ data_type } "
210198 end
0 commit comments