Skip to content

Commit 69f4e19

Browse files
authored
remove obsolete np.int and np.float (fastmachinelearning#703)
1 parent 5f44cc6 commit 69f4e19

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

hls4ml/writer/quartus_writer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def write_project_cpp(self, model):
195195
newline += 'hls_max_concurrency(0)\n'
196196
newline += f'hls_component_ii({self.get_max_reuse_factor(model)})\n'
197197
clock_mhz = 1000 / (model.config.get_config_value('ClockPeriod'))
198-
newline += f'hls_scheduler_target_fmax_mhz({np.ceil(clock_mhz).astype(np.int)})\n'
198+
newline += f'hls_scheduler_target_fmax_mhz({np.ceil(clock_mhz).astype(int)})\n'
199199

200200
# In io_parallel, an output (struct) is returned from the top-level function
201201
# Therefore, it needs to be initialised before returning
@@ -342,7 +342,7 @@ def write_project_header(self, model):
342342
newline += 'hls_max_concurrency(0)\n'
343343
newline += f'hls_component_ii({self.get_max_reuse_factor(model)})\n'
344344
clock_mhz = 1000 / (model.config.get_config_value('ClockPeriod'))
345-
newline += f'hls_scheduler_target_fmax_mhz({np.ceil(clock_mhz).astype(np.int)})\n'
345+
newline += f'hls_scheduler_target_fmax_mhz({np.ceil(clock_mhz).astype(int)})\n'
346346

347347
# For io_stream, no inputs/outputs are instantiated, as they are passed by reference
348348
# For io_parallel, input/output structs are required

test/pytest/test_embed.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
1-
import pytest
2-
import hls4ml
3-
import numpy as np
41
from pathlib import Path
2+
3+
import numpy as np
4+
import pytest
5+
from tensorflow.keras.layers import Embedding, Input
56
from tensorflow.keras.models import Model
6-
from tensorflow.keras.layers import Input, Embedding
7+
8+
import hls4ml
79

810
test_root_path = Path(__file__).parent
911

12+
1013
@pytest.fixture(scope='module')
1114
def data():
1215
X = np.random.randint(10, size=(32, 100))
1316
return X
1417

18+
1519
@pytest.fixture(scope='module')
1620
def keras_model():
1721
inputs = Input(shape=(100,), name='embedding_input')
1822
embedding = Embedding(13, 8, input_length=100, name='embedding')(inputs)
1923
model = Model(inputs=inputs, outputs=embedding)
2024
return model
2125

26+
2227
@pytest.fixture
2328
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
2429
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
2530
def hls_model(keras_model, backend, io_type):
26-
hls_config = hls4ml.utils.config_from_keras_model(keras_model,
27-
default_precision='ap_fixed<16,6>',
28-
granularity='name')
31+
hls_config = hls4ml.utils.config_from_keras_model(keras_model, default_precision='ap_fixed<16,6>', granularity='name')
2932
hls_config['LayerName']['embedding_input']['Precision']['result'] = 'ap_uint<4>'
3033
out_dir = str(test_root_path / 'hls4mlprj_embed_{}_{}').format(backend, io_type)
31-
hls_model = hls4ml.converters.convert_from_keras_model(keras_model,
32-
backend=backend,
33-
hls_config=hls_config,
34-
io_type=io_type,
35-
output_dir=out_dir)
34+
hls_model = hls4ml.converters.convert_from_keras_model(
35+
keras_model, backend=backend, hls_config=hls_config, io_type=io_type, output_dir=out_dir
36+
)
3637

3738
hls_model.compile()
3839
return hls_model
3940

41+
4042
@pytest.mark.parametrize('backend', ['Vivado', 'Quartus'])
4143
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
4244
def test_embedding_accuracy(data, keras_model, hls_model):
4345
X = data
4446
model = keras_model
4547
# model under test predictions and accuracy
4648
y_keras = model.predict(X)
47-
y_hls4ml = hls_model.predict(X.astype(np.float)).reshape(y_keras.shape)
49+
y_hls4ml = hls_model.predict(X.astype(float)).reshape(y_keras.shape)
4850
# "accuracy" of hls4ml predictions vs keras
4951
np.testing.assert_allclose(y_keras, y_hls4ml, rtol=0, atol=1e-03, verbose=True)

0 commit comments

Comments
 (0)