Skip to content

Commit

Permalink
style: apply Ruff linting rules and auto-fix code style issues
Browse files Browse the repository at this point in the history
Signed-off-by: NamCaoHai <namch.hust@gmail.com>
  • Loading branch information
CaoHaiNam committed Nov 7, 2024
1 parent d9f2c8e commit 5df4569
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions pymilvus/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from datetime import timedelta
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union

import numpy as np
import ujson

from pymilvus.exceptions import MilvusException, ParamError
from pymilvus.grpc_gen.common_pb2 import Status

from .constants import LOGICAL_BITS, LOGICAL_BITS_MASK
from .types import DataType
import numpy as np

MILVUS = "milvus"
ZILLIZ = "zilliz"
Expand Down Expand Up @@ -378,23 +378,20 @@ def is_scipy_sparse(cls, data: Any):
]


def convert_to_standard_form(vector_data):
def convert_to_standard_form(vector_data: Any) -> Any:
if len(vector_data.shape) == 1:
# Calculate the mean and standard deviation of the vector
mean = np.mean(vector_data)
std_dev = np.std(vector_data)

# Standardize the vector
standardized_vector = (vector_data - mean) / std_dev if std_dev != 0 else vector_data
return standardized_vector

else:
# Calculate mean and standard deviation for each row
row_means = np.mean(vector_data, axis=1, keepdims=True)
row_stds = np.std(vector_data, axis=1, keepdims=True)

# Standardize each row independently
standardized_matrix = np.where(
row_stds != 0, (vector_data - row_means) / row_stds, vector_data
)
return standardized_matrix
return (vector_data - mean) / std_dev if std_dev != 0 else vector_data

# Calculate mean and standard deviation for each row
row_means = np.mean(vector_data, axis=1, keepdims=True)
row_stds = np.std(vector_data, axis=1, keepdims=True)

# Standardize each row independently
return np.where(
row_stds != 0, (vector_data - row_means) / row_stds, vector_data
)
2 changes: 1 addition & 1 deletion pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
DataTypeNotSupportException,
ExceptionsMessage,
IndexNotExistException,
MilvusException,
PartitionAlreadyExistException,
SchemaNotReadyException,
MilvusException,
)
from pymilvus.grpc_gen import schema_pb2
from pymilvus.settings import Config
Expand Down

0 comments on commit 5df4569

Please sign in to comment.