Numpy array converts into C_CONTIGUOUS after trimming rows - numpy

Output of this is:
print(arr.shape)
print(arr.flags)
Output:
(676, 3516)
C_CONTIGUOUS : False
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : False
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
But when I trim the rows using:
arr = arr[preds<0]
I get this output
(670, 3516)
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
Now, when I use catboost to predict on the trimmed version of array, it takes 2x the time to predict compared to the original array. Catboost needs F_CONTIGUOUS array only I guess, not sure what contiguous array means.
How can I make the trimmed version F_CONTIGUOUS?

Related

g1ant: jsonpath with method length() not implemented

I have problem to get size items of array. Function of jsonPath "length()" not implemented in g1ant, because throwing exception "Array index expected".
Below is sample in g1ant script for test.
addon core version 4.103.0.0
addon language version 4.104.0.0
♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴
♥aaa = ♥jsonImage⟦$.book.length()⟧
dialog ♥aaa
Are there other solutions related to the length of the array?
It's not possible to get the number of json array elements in the way that you are trying. G1ANT is using Newtonsoft.Json library for selecting json tokens where they don't allow expressions like .length() as you can read here.
Here's how you can workaround this issue.
♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴
♥jsonArrLength = 0
♥hasExceptionOccurred = false
while ⊂!♥hasExceptionOccurred⊃
try errorcall NoMoreElements
♥test = ♥jsonImage⟦book[♥jsonArrLength]⟧
♥jsonArrLength = ♥jsonArrLength + 1
end try
end while
dialog ♥jsonArrLength
procedure NoMoreElements
♥hasExceptionOccurred = true
end procedure

Why not infer T::Boolean for true and false?

Sorbet infers the type of true to be TrueClass, and the type of false to be FalseClass. Often it would be nice if it would instead infer T::Boolean. Why not special case true and false to have the type T::Boolean instead?
It's possible to work around this problem with a type annotation, initializing variables with T.let(true, T::Boolean) for example, but it would be nice to not have to provide this extra information.
# typed: true
T.reveal_type(true) # Revealed type: `TrueClass`
T.reveal_type(false) # Revealed type: `FalseClass`
extend T::Sig
sig {params(x: T::Boolean).void}
def test(x)
var = true
10.times do
var = false # Changing the type of a variable in a loop is not permitted
end
end
The assignment of false to var in the loop causes an error to be raised, as the type of var is being changed from TrueClass to FalseClass.
Sorbet's flow-sensitive typing is made more precise by true and false having different types. In the following example, a variable with the value true is used as the condition of an if-statement:
# typed: true
val = true
if val
puts "true!"
else
puts "false?"
end
The resulting error from sorbet is:
editor.rb:7: This code is unreachable https://srb.help/7006
7 | puts "false?"
^^^^^^^^
Errors: 1
Behind the scenes, sorbet knows that the value being examined has the type TrueClass, and that the value true is the only value of that type. As a result, it knows that val cannot be false, and that the else branch will never be executed.
Now consider the case where we instead infer the type T::Boolean for true and false. T::Boolean is a synonym for T.any(TrueClass, FalseClass), so in the example it now means that val could be either true or false. As a result, it becomes impossible to tell from the type alone that the else branch will not be executed.
The flow-sensitive typing documentation on sorbet.org has more information on this topic.
Asked the same question today as well.
Ended up fixing it as you suggested with type annotations and initializing with T.let(true, T::Boolean)
# typed: true
extend T::Sig
sig {params(x: T::Boolean).void}
def test(x)
var = T.let(true, T::Boolean)
10.times do
var = T.let(false, T::Boolean)
end
end

Objective-C Clang-Format Method Brace Break

I'm working with clang-format for my Objective-C project, but I'm having difficulty setting it up properly.
Here's my desired result:
- (NSString *)someMethod
{
return #"My String";
}
Here's the actual result after formatting:
- (NSString *)someMethod {
return #"My String";
}
Here's my .clang-format file:
BasedOnStyle: WebKit
AlignTrailingComments: true
ColumnLimit: 120
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
TabWidth: 2
UseTab: Never
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterExternBlock: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
What setting do I need to change to get the formatter to put a line break before the opening brace of an Objective-C method?
For any fine-tuning of your clang-format you are much better off never to use BasedOnStyle because that for me just creates random and hard to debug results.
Easiest way to do this would be probably to set: BreakBeforeBraces: Custom and then set everything up the way you want it in as it says in the documentation:
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false

how metamacro_if_eq works in extobjc

Read at the source code https://github.com/jspahrsummers/libextobjc/blob/master/extobjc/metamacros.h#L158
// expands to true
metamacro_if_eq(0, 0)(true)(false)
when is expand the macro metamacro_if_eq(0, 0) manually, i get the following
metamacro_if_eq0(0) (true) (false)
continue expanding.
metamacro_if_eq0_0() (true) (false)
go on.
metamacro_consume_ (true) (false)
metamacro_consume is defined as:
#define metamacro_consume_(...) // why nothing here ?
then how can I get the expected value of "true" ?
Your production is incorrect. The operations go like this:
metamacro_if_eq(0, 0)(true)(false)
metamacro_concat(metamacro_if_eq, 0)(0)(true)(false)
metamacro_concat_(metamacro_if_eq, 0)(0)(true)(false)
metamacro_if_eq0(0)(true)(false)
metamacro_concat(metamacro_if_eq0_, 0)(true)(false)
metamacro_concat_(metamacro_if_eq0_, 0)(true)(false)
// You made a mistake at this point.
metamacro_if_eq0_0(true)(false)
true metamacro_consume_(false)
true
After the second round of concatenation, true becomes the argument to metamacro_if_eq0_0(). The argument(s) to that macro is/are left in its place. metamacro_consume_() takes any numer of arguments and resolves to nothing.

flexpaper default two page view settings

I am using flexpage along with pdf2swf to generate swf for my pdf files and showing it in my page.
Here is the setting i have used
<script type="text/javascript">
highlightPageMenuLink();
var swfVersionStr = "10.0.0"; // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var xiSwfUrlStr = "playerProductInstall.swf"; // To use express install, set to playerProductInstall.swf, otherwise the empty string.
var flashvars = {
SwfFile : escape("<%= current_user.books.first.name%>.swf"),
Scale : 0.6,
ZoomTransition : "easeOut",
ZoomTime : 0.5,
ZoomInterval : 0.1,
FitPageOnLoad : false,
FitWidthOnLoad : true,
PrintEnabled : false,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
PrintToolsVisible : false,
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
FullScreenVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : false,
localeChain: "en_US"
};
var params = {}
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "FlexPaperViewer";
attributes.name = "FlexPaperViewer";
swfobject.embedSWF("FlexPaperViewer.swf", "flashContent", "650", "605", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
ViewModeToolsVisible is set to true , with this I can see options to view pages in single page mode , two page mode and thumb mode.
How to make two page view mode my default ?
Thanks.
Got the way to show two page view by default. we can just insert a call in flexpaper_flash.js
function onDocumentLoaded(totalPages){
getDocViewer().switchMode('TwoPage');}
But then I was having a problem ,it was loading in single page mode first and then was converting the view to two page mode . Then I had to change
ProgressiveLoading : true
to
ProgressiveLoading : false
You can just use the setting
InitViewMode (String) Sets the start-up view mode. For example
"Portrait" or "TwoPage".
e.g:
InitViewMode : 'TwoPage',
more info: http://flexpaper.devaldi.com/docs_parameters.jsp