Is it impossible to select a nondeterministic value of an array element in Promela? - spin

Following is the Promela code that I am writing.
491 byte api1[5];
492 byte api2[5];
493 byte api3[5];
494 byte reftask1[5]
495 byte reftask2[5];
496 byte reftask3[5];
497 byte rid1[5];
498 byte rid2[5];
499 byte rid3[5];
500
501
502 proctype init_call(){
503 byte i1 = 0;
504 do
505 :: (i1 == 5) -> break
506 :: else ->
507 select ( api1[i1]: 2 .. 9);
508 select ( api2[i1] : 2 .. 9);
509 select ( api3[i1] : 2 .. 9);
510 select ( reftask1[i1] : 1 .. 3);
511 select( reftask2[i1] : 1 .. 3);
512 select ( reftask3[i1] : 1 .. 3);
513 select ( rid[i1] : 0 .. 1);
514 select ( rid[i1] : 0 .. 1);
515 select ( rid[i1] : 0 .. 1);
516 i1++;
517 od
518 }
But if I try to simulate the code, I get the error message as following,
saw: '[', expected ':' spin: osek_sp2.pml:507, Error: expecting select
( name : constant .. constant ) near 'select'
However, according to the syntax definition, I can't find any problem.
SYNTAX
select '(' varref ':' expr '..' expr ')'
varref : name [ '[' any_expr ']' ] [ '.' varref ]
What is the reason of this error message?

Patrick is right. I'd say that this is a bug. If you look into spinlex.c, you'll see that when it scans for name before : only alphanumeric characters are allowed:
scan_to(':', isalnum, name)
Anyway, select is just a shorthand for a sequence of assignments. So a work-around might be to write the assignments yourself, e.g.
api1[i1] = 2;
do
:: (api1[i1] < 9) -> api1[i1]++
:: break
od

Related

SpecificationError: Function names must be unique if there is no new column names assigned

I want to create a new column in the clin dataframe based on the following conditions:
1 if vals>=2*365 or is NAN
otherwise 0
I then assign the new column name as SURV.
import numpy as np
vals = clin['days_to_death'].astype(np.float32)
# non-LTS is 0, LTS is 1
surv = [1 if ( v>=2*365 or np.isnan(v) ) else 0 for v in vals ]
clin['SURV'] = clin.apply(surv, axis=1)
Traceback:
SpecificationError: Function names must be unique if there is no new column names assigned
---------------------------------------------------------------------------
SpecificationError Traceback (most recent call last)
<ipython-input-31-603dee8413ce> in <module>
5 # non-LTS is 0, LTS is 1
6 surv = [1 if ( v>=2*365 or np.isnan(v) ) else 0 for v in vals ]
----> 7 clin['SURV'] = clin.apply(surv, axis=1)
/shared-libs/python3.7/py/lib/python3.7/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
7766 kwds=kwds,
7767 )
-> 7768 return op.get_result()
7769
7770 def applymap(self, func, na_action: Optional[str] = None) -> DataFrame:
/shared-libs/python3.7/py/lib/python3.7/site-packages/pandas/core/apply.py in get_result(self)
146 # multiple values for keyword argument "axis"
147 return self.obj.aggregate( # type: ignore[misc]
--> 148 self.f, axis=self.axis, *self.args, **self.kwds
149 )
150
/shared-libs/python3.7/py/lib/python3.7/site-packages/pandas/core/frame.py in aggregate(self, func, axis, *args, **kwargs)
7572 axis = self._get_axis_number(axis)
7573
-> 7574 relabeling, func, columns, order = reconstruct_func(func, **kwargs)
7575
7576 result = None
/shared-libs/python3.7/py/lib/python3.7/site-packages/pandas/core/aggregation.py in reconstruct_func(func, **kwargs)
93 # there is no reassigned name
94 raise SpecificationError(
---> 95 "Function names must be unique if there is no new column names "
96 "assigned"
97 )
SpecificationError: Function names must be unique if there is no new column names assigned
clin
clin = pd.DataFrame([[1, '466', '47', 0, '90'],
[1, '357', '54', 1, '80'],
[1, '108', '72', 1, '60'],
[1, '254', '51', 0, '80'],
[1, '138', '78', 1, '80'],
[0, nan, '67', 0, '60']], columns=['vital_status', 'days_to_death', 'age_at_initial_pathologic_diagnosis',
'gender', 'karnofsky_performance_score'], index=['TCGA-06-1806', 'TCGA-06-5408', 'TCGA-06-5410', 'TCGA-06-5411',
'TCGA-06-5412', 'TCGA-06-5413'])
Expected output:
vital_status
days_to_death
age_at_initial_pathologic_diagnosis
gender
karnofsky_performance_score
SURV
TCGA-06-1806
1
466
47
0
90
0
TCGA-06-5408
1
357
54
1
80
0
TCGA-06-5410
1
108
72
1
60
0
TCGA-06-5411
1
254
51
0
80
0
TCGA-06-5412
1
138
78
1
80
0
TCGA-06-5413
0
nan
67
0
60
1
Make a new column of all 0's and then update the column with your desired parameters.
clin['SURV'] = 0
clin.loc[pd.to_numeric(clin.days_to_death).ge(2*365) | clin.days_to_death.isna(), 'SURV'] = 1
print(clin)
Output:
vital_status days_to_death age_at_initial_pathologic_diagnosis gender karnofsky_performance_score SURV
TCGA-06-1806 1 466 47 0 90 0
TCGA-06-5408 1 357 54 1 80 0
TCGA-06-5410 1 108 72 1 60 0
TCGA-06-5411 1 254 51 0 80 0
TCGA-06-5412 1 138 78 1 80 0
TCGA-06-5413 0 NaN 67 0 60 1

pyspark toPandas() IndexError: index is out of bounds

I'm experiencing a weird behaviour of pyspark's .toPandas() method running from Jupyt. For example, if I try this:
data = [{"Category": 'Category A', "ID": 1, "Value": 12.40},
{"Category": 'Category B', "ID": 2, "Value": 30.10},
{"Category": 'Category C', "ID": 3, "Value": 100.01}
]
# Create data frame (where spark is a SparkSession)
df = spark.createDataFrame(data)
df.show()
I'm able to successfully create the pyspark dataframe. However, when converting to pandas I get IndexError: index is out of bounds:
IndexError Traceback (most recent call last)
<path_to_python>/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
<path_to_python>/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
400 if cls is not object \
401 and callable(cls.__dict__.get('__repr__')):
--> 402 return _repr_pprint(obj, self, cycle)
403
404 return _default_pprint(obj, self, cycle)
<path_to_python>/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
695 """A pprint that just redirects to the normal repr function."""
696 # Find newlines and replace them with p.break_()
--> 697 output = repr(obj)
698 for idx,output_line in enumerate(output.splitlines()):
699 if idx:
<path_to_python>/lib/python3.7/site-packages/pandas/core/base.py in __repr__(self)
76 Yields Bytestring in Py2, Unicode String in py3.
77 """
---> 78 return str(self)
79
80
<path_to_python>/lib/python3.7/site-packages/pandas/core/base.py in __str__(self)
55
56 if compat.PY3:
---> 57 return self.__unicode__()
58 return self.__bytes__()
59
<path_to_python>/lib/python3.7/site-packages/pandas/core/frame.py in __unicode__(self)
632 width = None
633 self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols,
--> 634 line_width=width, show_dimensions=show_dimensions)
635
636 return buf.getvalue()
<path_to_python>/lib/python3.7/site-packages/pandas/core/frame.py in to_string(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, max_rows, max_cols, show_dimensions, decimal, line_width)
719 decimal=decimal,
720 line_width=line_width)
--> 721 formatter.to_string()
722
723 if buf is None:
<path_to_python>/lib/python3.7/site-packages/pandas/io/formats/format.py in to_string(self)
596 else:
597
--> 598 strcols = self._to_str_columns()
599 if self.line_width is None: # no need to wrap around just print
600 # the whole frame
<path_to_python>/lib/python3.7/site-packages/pandas/io/formats/format.py in _to_str_columns(self)
527 str_columns = [[label] for label in self.header]
528 else:
--> 529 str_columns = self._get_formatted_column_labels(frame)
530
531 stringified = []
<path_to_python>/lib/python3.7/site-packages/pandas/io/formats/format.py in _get_formatted_column_labels(self, frame)
770 need_leadsp[x] else x]
771 for i, (col, x) in enumerate(zip(columns,
--> 772 fmt_columns))]
773
774 if self.show_row_idx_names:
<path_to_python>/lib/python3.7/site-packages/pandas/io/formats/format.py in <listcomp>(.0)
769 str_columns = [[' ' + x if not self._get_formatter(i) and
770 need_leadsp[x] else x]
--> 771 for i, (col, x) in enumerate(zip(columns,
772 fmt_columns))]
773
<path_to_python>/lib/python3.7/site-packages/pandas/io/formats/format.py in _get_formatter(self, i)
362 else:
363 if is_integer(i) and i not in self.columns:
--> 364 i = self.columns[i]
365 return self.formatters.get(i, None)
366
<path_to_python>/lib/python3.7/site-packages/pandas/core/indexes/base.py in __getitem__(self, key)
3956 if is_scalar(key):
3957 key = com.cast_scalar_indexer(key)
-> 3958 return getitem(key)
3959
3960 if isinstance(key, slice):
IndexError: index 3 is out of bounds for axis 0 with size 3
I'm not sure where the problem can be, I've used this many times without problems but this time I tried a new environment and I got this issue. In case it can help my configuration is:
Python: 3.7.6;
Pandas: 0.24.2;
PySpark: 2.4.5
Any idea?
Thanks :)
I found the issue. Trying to minimize the code to reproduce the error I omitted that I was adding a pandas setting:
pd.set_option('display.max_columns', -1)
This caused the error independently of the dataframe being converted. To fix it I just specified a positive number of columns or None.

Why does one of these two indexing patterns give me an "index out of bounds" error?

With ncsim the following code throws the error:
Bit-select or part-select index out of declared bounds.
However, the commented out code which does exactly the same thing doesn't. Am I missing something or is the compiler mistaken?
module pd__test;
genvar i, j;
reg [10-1:0] assign_from_reg;
reg [256:0] assign_to_reg;
generate
for (i=0; i<2; i=i+1) begin
for (j=0; j<13; j=j+1) begin
always #* begin
if (i+2*j < 25) begin
// gives me an index out of bounds error
assign_to_reg[10*(i+2*j)+9 : 10*(i+2*j)] = assign_from_reg;
// gives me no such error, however the indices are the same
// assign_to_reg[10*(i+2*j)+9 -: 10] = assign_from_reg;
end else begin
// do something else
end
end
end
end
endgenerate
endmodule
I ran a python script to print the indeces to double check:
for i in range(2):
for j in range(13):
if (i+(2*j) < 25):
print("[", 10*(i+(2*j))+9, ":", 10*(i+(2*j)), "]")
Prints:
[ 9 : 0 ]
[ 29 : 20 ]
[ 49 : 40 ]
[ 69 : 60 ]
[ 89 : 80 ]
[ 109 : 100 ]
[ 129 : 120 ]
[ 149 : 140 ]
[ 169 : 160 ]
[ 189 : 180 ]
[ 209 : 200 ]
[ 229 : 220 ]
[ 249 : 240 ]
[ 19 : 10 ]
[ 39 : 30 ]
[ 59 : 50 ]
[ 79 : 70 ]
[ 99 : 90 ]
[ 119 : 110 ]
[ 139 : 130 ]
[ 159 : 150 ]
[ 179 : 170 ]
[ 199 : 190 ]
[ 219 : 210 ]
[ 239 : 230 ]
you asked verilog compiler to compile this code in the always block
assign_to_reg[10*(i+2*j)+9 -: 10]
which for i == 1 and j == 12 is generated by the generate block as:
assign_to_reg[259 : 250]
The above is clearly outside of the declared bounds [256:0].
Moving the 'if' into the generate block, as #toolic suggested would cause verilog not to generate the last always block at all, therefore, it will not be compiled and no warning/error would be produced.
So, the other solution with generate blocks would be to declare your assign_to_reg as [259:0].
And yet the best solution would be to get rid of the generate block all together and move all your loops inside the single always block:
always #* begin
for (int i=0; i<2; i=i+1) begin
for (int j=0; j<13; j=j+1) begin
if (i+2*j < 25) begin
assign_to_reg[10*(i+2*j)+9 -: 10] = assign_from_reg;
end
end
end
end
This should let compiler to calculate indexes at run-time and will not cause out-of-bound access as well.
Move the conditional if (i+2*j < 25) outside of the always block:
module pd__test;
genvar i, j;
reg [10-1:0] assign_from_reg;
reg [256:0] assign_to_reg;
generate
for (i=0; i<2; i=i+1) begin
for (j=0; j<13; j=j+1) begin
if (i+2*j < 25) begin
always #* begin
//assign_to_reg[10*(i+2*j)+9 : 10*(i+2*j)] = assign_from_reg;
assign_to_reg[10*(i+2*j)+9 -: 10] = assign_from_reg;
end
end
end
end
endgenerate
endmodule
Both assignments compile without warnings or errors for me.

H264 encoding and decoding using Videotoolbox

I was testing the encoding and decoding using videotoolbox, to convert the captured frames to H264 and using that data to display it in AVSampleBufferdisplayLayer.
error here while decompress CMVideoFormatDescriptionCreateFromH264ParameterSets with error code -12712
I follow this code from mobisoftinfotech.com
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(
kCFAlloc‌​‌ atorDefault, 2,
(const uint8_t const)parameterSetPointers,
parameterSetSizes, 4, &_formatDesc);
videoCompressionTest; can anyone figure out the problem?
I am not sure if you did figure out the problem yet. However, I found 2 places in your code that leading to the error. After fixed them and run locally your test app, it seems to be working fine. (Tested with Xcode 9.4.1, MacOS 10.13)
The first one is in -(void)CompressAndConvertToData:(CMSampleBufferRef)sampleBuffer method where the while loop should be like this
while (bufferOffset < blockBufferLength - AVCCHeaderLength) {
// Read the NAL unit length
uint32_t NALUnitLength = 0;
memcpy(&NALUnitLength, bufferDataPointer + bufferOffset, AVCCHeaderLength);
// Convert the length value from Big-endian to Little-endian
NALUnitLength = CFSwapInt32BigToHost(NALUnitLength);
// Write start code to the elementary stream
[elementaryStream appendBytes:startCode length:startCodeLength];
// Write the NAL unit without the AVCC length header to the elementary stream
[elementaryStream appendBytes:bufferDataPointer + bufferOffset + AVCCHeaderLength
length:NALUnitLength];
// Move to the next NAL unit in the block buffer
bufferOffset += AVCCHeaderLength + NALUnitLength;
}
uint8_t *bytes = (uint8_t*)[elementaryStream bytes];
int size = (int)[elementaryStream length];
[self receivedRawVideoFrame:bytes withSize:size];
The second place is the decompression code where you process for NALU type 8, the block of code in if(nalu_type == 8) statement. This is a tricky one.
To fix it, update
for (int i = _spsSize + 12; i < _spsSize + 50; i++)
to
for (int i = _spsSize + 12; i < _spsSize + 12 + 50; i++)
And you are freely to remove this hack
//was crashing here
if(_ppsSize == 0)
_ppsSize = 4;
Why? Lets print out the frame packet format.
po frame
▿ 4282 elements
- 0 : 0
- 1 : 0
- 2 : 0
- 3 : 1
- 4 : 39
- 5 : 100
- 6 : 0
- 7 : 30
- 8 : 172
- 9 : 86
- 10 : 193
- 11 : 112
- 12 : 247
- 13 : 151
- 14 : 64
- 15 : 0
- 16 : 0
- 17 : 0
- 18 : 1
- 19 : 40
- 20 : 238
- 21 : 60
- 22 : 176
- 23 : 0
- 24 : 0
- 25 : 0
- 26 : 1
- 27 : 6
- 28 : 5
- 29 : 35
- 30 : 71
- 31 : 86
- 32 : 74
- 33 : 220
- 34 : 92
- 35 : 76
- 36 : 67
- 37 : 63
- 38 : 148
- 39 : 239
- 40 : 197
- 41 : 17
- 42 : 60
- 43 : 209
- 44 : 67
- 45 : 168
- 46 : 0
- 47 : 0
- 48 : 3
- 49 : 0
- 50 : 0
- 51 : 3
- 52 : 0
- 53 : 2
- 54 : 143
- 55 : 92
- 56 : 40
- 57 : 1
- 58 : 221
- 59 : 204
- 60 : 204
- 61 : 221
- 62 : 2
- 63 : 0
- 64 : 76
- 65 : 75
- 66 : 64
- 67 : 128
- 68 : 0
- 69 : 0
- 70 : 0
- 71 : 1
- 72 : 37
- 73 : 184
- 74 : 32
- 75 : 1
- 76 : 223
- 77 : 205
- 78 : 248
- 79 : 30
- 80 : 231
… more
The first NALU start code if (nalu_type == 7) is 0, 0, 0, 1 from index of 15 to 18. The next 0, 0, 0, 1 (from 23 to 26) is type 6, type 8 NALU start code is from 68 to 71. That why I modify the for loop a bit to scan from start index (_spsSize + 12) with a range of 50.
I haven't fully tested your code to make sure encode and decode work properly as expected. However, I hope this finding would help you.
By the way, if there is any misunderstanding, I would love to learn from your comments.

SQL query - restriction doesn't work as I 'd expect

I have the following query:
SELECT
(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) ,
xex.xex_xexc_k,
FROM qot, sec, exc, ctr, xcx, xex, xexc, xcrr, crr
WHERE qot_source = 'X'
AND qot_id = 2029557521
AND nvl(qot_real_exc_id, qot_exc_id) = exc_id
AND exc_ctr_id = ctr_id
AND qot_sec_id = sec_id
AND nvl(qot_real_exc_id, qot_exc_id) = xex_exc_id(+)
AND qot_crr_id = xcx_crr_id(+)
AND xex_xexc_k = xexc_k(+)
AND xcx_xcrr_k = xcrr_k(+)
AND qot_crr_id = crr_id(+)
AND qot_status IN (1, 2)
AND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k);
When I comment out the last restrictionAND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k); I'm getting results:
1135 67
1135 111
1135 549
1135 246
1135 103
1135 564
1135 1135
1135 21
So as you can see I have a row:
1135 1135
But I'm getting no results when I add the last restriction:
AND (qot_sup_xpressfeed IS NULL OR to_number(substr(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,'), 2, length(REGEXP_SUBSTR(qot_sup_xpressfeed, ',[^,]+,')) - 2)) = xexc_k);
I'd expect I will get 1 result (the mentioned 1135 1135).
What am I doing wrong?
You are selecting xex.xex_xexc_k while your test is on xexc_k. As this is an OUTER JOIN they could be different. What happens when you compare with xex.xex_xexc_k instead?