martinzink commented on code in PR #2258:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2258#discussion_r3989488170


##########
minifi_rust/extensions/minifi_tensor/src/low_level_processors/invoke_tract_model.rs:
##########
@@ -0,0 +1,254 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::utils::tensor_helpers::MinifiDatumType;
+pub(crate) use invoke_tract_model_def::TRACT_MODEL_SERVICE;
+use invoke_tract_model_def::*;
+use minifi_native::macros::ComponentIdentifier;
+use minifi_native::{
+    FlowFileTransform, GetAttribute, GetControllerService, GetId, GetProperty, 
InputStream, Logger,
+    MinifiError, ProcessError, RouteErrorExt, Schedule, TransformedFlowFile,
+};
+use std::error::Error;
+use tract::__ndarray_interop::TensorInterface;
+use tract::Tensor;
+tract::impl_ndarray_interop!();
+
+mod invoke_tract_model_def;
+
+#[derive(ComponentIdentifier)]
+pub(crate) struct InvokeTractModel {}
+
+impl Schedule for InvokeTractModel {
+    fn schedule<Ctx: GetProperty, L: Logger>(
+        _context: &Ctx,
+        _logger: &L,
+    ) -> Result<Self, MinifiError>
+    where
+        Self: Sized,
+    {
+        Ok(Self {})
+    }
+}
+
+impl InvokeTractModel {
+    fn get_payload_as_f32_array(
+        input_stream: &mut dyn InputStream,
+    ) -> Result<Vec<f32>, Box<dyn Error>> {
+        let mut raw_bytes = Vec::new();
+        input_stream.read_to_end(&mut raw_bytes)?;
+        if raw_bytes.len() % 4 != 0 {
+            return Err(MinifiError::custom("Input bytes length is not a 
multiple of 4").into());
+        }
+        let mut f32_data = Vec::with_capacity(raw_bytes.len() / 4);
+        for chunk in raw_bytes.as_chunks::<4>().0.iter() {
+            let val = f32::from_le_bytes(*chunk);
+            f32_data.push(val);
+        }

Review Comment:
   👍 yeah thats valid, i've extracted it but seems i didnt find all the 
occurences, [remove code duplication from InvokeTract model and add 
result_via_out…](https://github.com/apache/nifi-minifi-cpp/pull/2258/commits/5c045ef6bec5000907d022b25afccbb2b77cfed1)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to