_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q20600 | Promisepay.ItemResource.find | train | def find(id, type = :full)
case type
when :full
response = JSON.parse(@client.get("items/#{id}").body)
Promisepay::Item.new(@client, response['items'])
when :status
response = JSON.parse(@client.get("items/#{id}/status").body)
Promisepay::Item.new(@client, response['items'])
end
end | ruby | {
"resource": ""
} |
q20601 | Promisepay.User.bank_account | train | def bank_account
response = JSON.parse(@client.get("users/#{send(:id)}/bank_accounts").body)
Promisepay::BankAccount.new(@client, response['bank_accounts'])
rescue Promisepay::UnprocessableEntity
nil
end | ruby | {
"resource": ""
} |
q20602 | Promisepay.User.card_account | train | def card_account
response = JSON.parse(@client.get("users/#{send(:id)}/card_accounts").body)
Promisepay::CardAccount.new(@client, response['card_accounts'])
rescue Promisepay::UnprocessableEntity
nil
end | ruby | {
"resource": ""
} |
q20603 | Promisepay.User.paypal_account | train | def paypal_account
response = JSON.parse(@client.get("users/#{send(:id)}/paypal_accounts").body)
Promisepay::PaypalAccount.new(@client, response['paypal_accounts'])
rescue Promisepay::UnprocessableEntity
nil
end | ruby | {
"resource": ""
} |
q20604 | Promisepay.User.disbursement_account | train | def disbursement_account(account_id)
options = { account_id: account_id }
JSON.parse(@client.post("users/#{send(:id)}/disbursement_account", options).body)
true
end | ruby | {
"resource": ""
} |
q20605 | Promisepay.User.company | train | def company
response = JSON.parse(@client.get("users/#{send(:id)}/companies").body)
Promisepay::Company.new(@client, response['companies'])
rescue Promisepay::NotFound
nil
end | ruby | {
"resource": ""
} |
q20606 | Promisepay.FeeResource.find | train | def find(id)
response = JSON.parse(@client.get("fees/#{id}").body)
Promisepay::Fee.new(@client, response['fees'])
end | ruby | {
"resource": ""
} |
q20607 | Promisepay.FeeResource.create | train | def create(attributes)
response = JSON.parse(@client.post('fees', attributes).body)
Promisepay::Fee.new(@client, response['fees'])
end | ruby | {
"resource": ""
} |
q20608 | Promisepay.WalletAccount.withdraw | train | def withdraw(options = {})
response = JSON.parse(@client.post("wallet_accounts/#{send(:id)}/withdraw", options).body)
response.key?('disbursements') ? response['disbursements'] : {}
end | ruby | {
"resource": ""
} |
q20609 | Promisepay.WalletAccount.deposit | train | def deposit(options = {})
response = JSON.parse(@client.post("wallet_accounts/#{send(:id)}/deposit", options).body)
response.key?('disbursements') ? response['disbursements'] : {}
end | ruby | {
"resource": ""
} |
q20610 | Promisepay.WalletAccount.user | train | def user
response = JSON.parse(@client.get("wallet_accounts/#{send(:id)}/users").body)
response.key?('users') ? Promisepay::User.new(@client, response['users']) : nil
end | ruby | {
"resource": ""
} |
q20611 | Promisepay.Transaction.fee | train | def fee
response = JSON.parse(@client.get("transactions/#{send(:id)}/fees").body)
response.key?('fees') ? Promisepay::Fee.new(@client, response['fees']) : nil
end | ruby | {
"resource": ""
} |
q20612 | Promisepay.TokenResource.create | train | def create(type = :session, attributes)
case type
when :session
if attributes && attributes[:fee_ids] && attributes[:fee_ids].is_a?(Array)
attributes[:fee_ids] = attributes[:fee_ids].join(',')
end
response = @client.get('request_session_token', attributes)
JSON.parse(response.body)
when :eui
attributes[:token_type] = 'eui'
response = @client.post('token_auths/', attributes)
JSON.parse(response.body)
when :card
attributes[:token_type] = 'card'
response = @client.post('token_auths/', attributes)
JSON.parse(response.body)
when :approve
attributes[:token_type] = '4'
response = @client.post('token_auths/', attributes)
JSON.parse(response.body)
end
end | ruby | {
"resource": ""
} |
q20613 | Promisepay.ChargeResource.find_all | train | def find_all(options = {})
response = JSON.parse(@client.get('charges', options).body)
charges = response.key?('charges') ? response['charges'] : []
charges.map { |attributes| Promisepay::Charge.new(@client, attributes) }
end | ruby | {
"resource": ""
} |
q20614 | DocRaptor.DocApi.create_async_doc | train | def create_async_doc(doc, opts = {})
data, _status_code, _headers = create_async_doc_with_http_info(doc, opts)
return data
end | ruby | {
"resource": ""
} |
q20615 | DocRaptor.DocApi.create_doc | train | def create_doc(doc, opts = {})
data, _status_code, _headers = create_doc_with_http_info(doc, opts)
return data
end | ruby | {
"resource": ""
} |
q20616 | DocRaptor.DocApi.get_async_doc | train | def get_async_doc(id, opts = {})
data, _status_code, _headers = get_async_doc_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20617 | DocRaptor.DocApi.get_async_doc_status | train | def get_async_doc_status(id, opts = {})
data, _status_code, _headers = get_async_doc_status_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20618 | Socializer.Person.likes | train | def likes
verbs_of_interest = %w[like unlike]
query = Activity.joins(:verb)
.with_actor_id(id: guid)
.with_target_id(id: nil)
.merge(Verb.with_display_name(name: verbs_of_interest))
@likes ||= query.group(:activity_object_id).having("COUNT(1) % 2 == 1")
end | ruby | {
"resource": ""
} |
q20619 | Socializer.Person.likes? | train | def likes?(object)
verbs_of_interest = %w[like unlike]
query = Activity.joins(:verb)
.with_activity_object_id(id: object.id)
.with_actor_id(id: guid)
.merge(Verb.with_display_name(name: verbs_of_interest))
query.count.odd?
end | ruby | {
"resource": ""
} |
q20620 | Socializer.CreateActivity.add_audience_to_activity | train | def add_audience_to_activity(activity:)
object_ids_array.each do |audience_id|
privacy = audience_privacy(audience_id: audience_id)
audience = activity.audiences.build(privacy: privacy)
audience.activity_object_id = audience_id if privacy == limited_privacy
end
end | ruby | {
"resource": ""
} |
q20621 | Socializer.AudienceList.call | train | def call
audiences = [merge_icon(list: privacy_hash(privacy_symbol: :public),
icon: "fa-globe")]
audiences << merge_icon(list: privacy_hash(privacy_symbol: :circles),
icon: "fa-google-circles")
# TODO: may use the avatar for the user
audiences.concat(merge_icon(list: person_list, icon: "fa-user"))
audiences.concat(merge_icon(list: audience_list(type: :circles),
icon: "fa-google-circles"))
audiences.concat(merge_icon(list: audience_list(type: :groups),
icon: "fa-users"))
end | ruby | {
"resource": ""
} |
q20622 | Socializer.AudienceList.person_list | train | def person_list
return Person.none if @query.blank?
result = select_display_name_alias_and_guids(query: Person)
result.display_name_like(query: "%#{@query}%")
end | ruby | {
"resource": ""
} |
q20623 | Socializer.ActivityObject.liked_by | train | def liked_by
# subquery = Activity.where(activity_object_id: id)
# people = Person.joins(activity_object: { actor_activities: :verb })
# .merge(subquery)
# likers = people.merge(Verb.by_display_name("like"))
# unlikers = people.merge(Verb.by_display_name("unlike")).pluck(:id)
query = Activity.joins(:verb).with_activity_object_id(id: id)
likers = query.merge(Verb.with_display_name(name: "like"))
unlikers = query.merge(Verb.with_display_name(name: "unlike"))
people = likers.map(&:actor)
unlikers.each do |activity|
people.delete_at people.index(activity.actor)
end
people
end | ruby | {
"resource": ""
} |
q20624 | Socializer.ApplicationDecorator.time_ago | train | def time_ago(options: {})
data = { behavior: "tooltip-on-hover", time_ago: "moment.js" }
options.reverse_merge!(title: created_updated_tooltip_text, data: data)
time_tag(options: options)
end | ruby | {
"resource": ""
} |
q20625 | Socializer.AddDefaultCircles.call | train | def call
create_circle(display_name: "Friends",
content: friends_content)
create_circle(display_name: "Family",
content: family_content)
create_circle(display_name: "Acquaintances",
content: acquaintances_content)
create_circle(display_name: "Following",
content: following_content)
end | ruby | {
"resource": ""
} |
q20626 | Socializer.ActivityAudienceList.call | train | def call
list = []
@activity.audiences.each do |audience|
if audience.public?
message = I18n.t("tooltip.public",
scope: "socializer.activities.audiences.index")
return [message]
end
list.concat(audience_list(audience: audience))
end
list.unshift(@activity.activitable_actor.activitable.display_name)
end | ruby | {
"resource": ""
} |
q20627 | Socializer.ActivityAudienceList.limited_audience_list | train | def limited_audience_list(activitable:)
# The target audience is either a group or a person,
# which means we can add it as it is in the audience list.
return [activitable.display_name] unless activitable.is_a?(Circle)
activitable.contacts.pluck(:display_name)
end | ruby | {
"resource": ""
} |
q20628 | Socializer.Activity.comments | train | def comments
activitable_type =
ActivityObject.with_activitable_type(type: Comment.name)
@comments ||= children.joins(:activitable_object)
.merge(activitable_type)
end | ruby | {
"resource": ""
} |
q20629 | Socializer.ActivityObjectDecorator.link_to_like_or_unlike | train | def link_to_like_or_unlike
return unless helpers.current_user
options = current_user_likes? ? like_options : unlike_options
like_or_unlike_link(options: options)
end | ruby | {
"resource": ""
} |
q20630 | Socializer.PersonDecorator.image_tag_avatar | train | def image_tag_avatar(size: nil, css_class: nil, alt: "Avatar", title: nil)
width, height = parse_size(size: size) if size
helpers.tag.img(src: avatar_url, class: css_class, alt: alt,
title: title, width: width, height: height,
data: { behavior: "tooltip-on-hover" })
end | ruby | {
"resource": ""
} |
q20631 | Socializer.PersonDecorator.link_to_avatar | train | def link_to_avatar
helpers.link_to(image_tag_avatar(title: model.display_name),
helpers.person_activities_path(person_id: model.id))
end | ruby | {
"resource": ""
} |
q20632 | Socializer.PersonDecorator.toolbar_stream_links | train | def toolbar_stream_links
list = combine_circles_and_memberships
return if list.blank?
html = [toolbar_links(list[0..2])]
html << toolbar_dropdown(list[3..(list.size)])
helpers.safe_join(html)
end | ruby | {
"resource": ""
} |
q20633 | Clever.DataApi.get_contact | train | def get_contact(id, opts = {})
data, _status_code, _headers = get_contact_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20634 | Clever.DataApi.get_contacts_for_student | train | def get_contacts_for_student(id, opts = {})
data, _status_code, _headers = get_contacts_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20635 | Clever.DataApi.get_course | train | def get_course(id, opts = {})
data, _status_code, _headers = get_course_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20636 | Clever.DataApi.get_course_for_section | train | def get_course_for_section(id, opts = {})
data, _status_code, _headers = get_course_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20637 | Clever.DataApi.get_district | train | def get_district(id, opts = {})
data, _status_code, _headers = get_district_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20638 | Clever.DataApi.get_district_admin | train | def get_district_admin(id, opts = {})
data, _status_code, _headers = get_district_admin_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20639 | Clever.DataApi.get_district_for_contact | train | def get_district_for_contact(id, opts = {})
data, _status_code, _headers = get_district_for_contact_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20640 | Clever.DataApi.get_district_for_course | train | def get_district_for_course(id, opts = {})
data, _status_code, _headers = get_district_for_course_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20641 | Clever.DataApi.get_district_for_district_admin | train | def get_district_for_district_admin(id, opts = {})
data, _status_code, _headers = get_district_for_district_admin_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20642 | Clever.DataApi.get_district_for_school | train | def get_district_for_school(id, opts = {})
data, _status_code, _headers = get_district_for_school_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20643 | Clever.DataApi.get_district_for_school_admin | train | def get_district_for_school_admin(id, opts = {})
data, _status_code, _headers = get_district_for_school_admin_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20644 | Clever.DataApi.get_district_for_section | train | def get_district_for_section(id, opts = {})
data, _status_code, _headers = get_district_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20645 | Clever.DataApi.get_district_for_student | train | def get_district_for_student(id, opts = {})
data, _status_code, _headers = get_district_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20646 | Clever.DataApi.get_district_for_teacher | train | def get_district_for_teacher(id, opts = {})
data, _status_code, _headers = get_district_for_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20647 | Clever.DataApi.get_district_for_term | train | def get_district_for_term(id, opts = {})
data, _status_code, _headers = get_district_for_term_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20648 | Clever.DataApi.get_school | train | def get_school(id, opts = {})
data, _status_code, _headers = get_school_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20649 | Clever.DataApi.get_school_admin | train | def get_school_admin(id, opts = {})
data, _status_code, _headers = get_school_admin_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20650 | Clever.DataApi.get_school_for_section | train | def get_school_for_section(id, opts = {})
data, _status_code, _headers = get_school_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20651 | Clever.DataApi.get_school_for_student | train | def get_school_for_student(id, opts = {})
data, _status_code, _headers = get_school_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20652 | Clever.DataApi.get_school_for_teacher | train | def get_school_for_teacher(id, opts = {})
data, _status_code, _headers = get_school_for_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20653 | Clever.DataApi.get_schools_for_school_admin | train | def get_schools_for_school_admin(id, opts = {})
data, _status_code, _headers = get_schools_for_school_admin_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20654 | Clever.DataApi.get_schools_for_student | train | def get_schools_for_student(id, opts = {})
data, _status_code, _headers = get_schools_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20655 | Clever.DataApi.get_schools_for_teacher | train | def get_schools_for_teacher(id, opts = {})
data, _status_code, _headers = get_schools_for_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20656 | Clever.DataApi.get_section | train | def get_section(id, opts = {})
data, _status_code, _headers = get_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20657 | Clever.DataApi.get_sections_for_course | train | def get_sections_for_course(id, opts = {})
data, _status_code, _headers = get_sections_for_course_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20658 | Clever.DataApi.get_sections_for_school | train | def get_sections_for_school(id, opts = {})
data, _status_code, _headers = get_sections_for_school_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20659 | Clever.DataApi.get_sections_for_student | train | def get_sections_for_student(id, opts = {})
data, _status_code, _headers = get_sections_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20660 | Clever.DataApi.get_sections_for_teacher | train | def get_sections_for_teacher(id, opts = {})
data, _status_code, _headers = get_sections_for_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20661 | Clever.DataApi.get_sections_for_term | train | def get_sections_for_term(id, opts = {})
data, _status_code, _headers = get_sections_for_term_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20662 | Clever.DataApi.get_student | train | def get_student(id, opts = {})
data, _status_code, _headers = get_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20663 | Clever.DataApi.get_students_for_contact | train | def get_students_for_contact(id, opts = {})
data, _status_code, _headers = get_students_for_contact_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20664 | Clever.DataApi.get_students_for_school | train | def get_students_for_school(id, opts = {})
data, _status_code, _headers = get_students_for_school_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20665 | Clever.DataApi.get_students_for_section | train | def get_students_for_section(id, opts = {})
data, _status_code, _headers = get_students_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20666 | Clever.DataApi.get_students_for_teacher | train | def get_students_for_teacher(id, opts = {})
data, _status_code, _headers = get_students_for_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20667 | Clever.DataApi.get_teacher | train | def get_teacher(id, opts = {})
data, _status_code, _headers = get_teacher_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20668 | Clever.DataApi.get_teacher_for_section | train | def get_teacher_for_section(id, opts = {})
data, _status_code, _headers = get_teacher_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20669 | Clever.DataApi.get_teachers_with_http_info | train | def get_teachers_with_http_info(opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug "Calling API: DataApi.get_teachers ..."
end
# resource path
local_var_path = "/teachers"
# query parameters
query_params = {}
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
query_params[:'starting_after'] = opts[:'starting_after'] if !opts[:'starting_after'].nil?
query_params[:'ending_before'] = opts[:'ending_before'] if !opts[:'ending_before'].nil?
# header parameters
header_params = {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# form parameters
form_params = {}
# http body (model)
post_body = nil
auth_names = ['oauth']
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => 'TeachersResponse')
if @api_client.config.debugging
@api_client.config.logger.debug "API called: DataApi#get_teachers\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end | ruby | {
"resource": ""
} |
q20670 | Clever.DataApi.get_teachers_for_school | train | def get_teachers_for_school(id, opts = {})
data, _status_code, _headers = get_teachers_for_school_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20671 | Clever.DataApi.get_teachers_for_section | train | def get_teachers_for_section(id, opts = {})
data, _status_code, _headers = get_teachers_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20672 | Clever.DataApi.get_teachers_for_student | train | def get_teachers_for_student(id, opts = {})
data, _status_code, _headers = get_teachers_for_student_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20673 | Clever.DataApi.get_term | train | def get_term(id, opts = {})
data, _status_code, _headers = get_term_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20674 | Clever.DataApi.get_term_for_section | train | def get_term_for_section(id, opts = {})
data, _status_code, _headers = get_term_for_section_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20675 | Clever.EventsApi.get_event | train | def get_event(id, opts = {})
data, _status_code, _headers = get_event_with_http_info(id, opts)
return data
end | ruby | {
"resource": ""
} |
q20676 | APN.Client.setup_socket | train | def setup_socket
ctx = setup_certificate
APN.log(:debug, "Connecting to #{@host}:#{@port}...")
socket_tcp = TCPSocket.new(@host, @port)
OpenSSL::SSL::SSLSocket.new(socket_tcp, ctx).tap do |s|
s.sync = true
s.connect
end
end | ruby | {
"resource": ""
} |
q20677 | Numo.Linalg.dot | train | def dot(a, b)
a = NArray.asarray(a)
b = NArray.asarray(b)
case a.ndim
when 1
case b.ndim
when 1
func = blas_char(a, b) =~ /c|z/ ? :dotu : :dot
Blas.call(func, a, b)
else
if b.contiguous?
trans = 't'
else
if b.fortran_contiguous?
trans = 'n'
b = b.transpose
else
trans = 't'
b = b.dup
end
end
Blas.call(:gemv, b, a, trans:trans)
end
else
case b.ndim
when 1
if a.contiguous?
trans = 'n'
else
if a.fortran_contiguous?
trans = 't'
a = a.transpose
else
trans = 'n'
a = a.dup
end
end
Blas.call(:gemv, a, b, trans:trans)
else
if a.contiguous?
transa = 'n'
else
if a.fortran_contiguous?
transa = 't'
a = a.transpose
else
transa = 'n'
a = a.dup
end
end
if b.contiguous?
transb = 'n'
else
if b.fortran_contiguous?
transb='t'
b = b.transpose
else
transb='n'
b = b.dup
end
end
Blas.call(:gemm, a, b, transa:transa, transb:transb)
end
end
end | ruby | {
"resource": ""
} |
q20678 | Numo.Linalg.matrix_power | train | def matrix_power(a, n)
a = NArray.asarray(a)
m,k = a.shape[-2..-1]
unless m==k
raise NArray::ShapeError, "input must be a square array"
end
unless Integer===n
raise ArgumentError, "exponent must be an integer"
end
if n == 0
return a.class.eye(m)
elsif n < 0
a = inv(a)
n = n.abs
end
if n <= 3
r = a
(n-1).times do
r = matmul(r,a)
end
else
while (n & 1) == 0
a = matmul(a,a)
n >>= 1
end
r = a
while n != 0
a = matmul(a,a)
n >>= 1
if (n & 1) != 0
r = matmul(r,a)
end
end
end
r
end | ruby | {
"resource": ""
} |
q20679 | Numo.Linalg.svdvals | train | def svdvals(a, driver:'svd')
case driver.to_s
when /^(ge)?sdd$/i, "turbo"
Lapack.call(:gesdd, a, jobz:'N')[0]
when /^(ge)?svd$/i
Lapack.call(:gesvd, a, jobu:'N', jobvt:'N')[0]
else
raise ArgumentError, "invalid driver: #{driver}"
end
end | ruby | {
"resource": ""
} |
q20680 | Numo.Linalg.orth | train | def orth(a, rcond: -1)
raise NArray::ShapeError, '2-d array is required' if a.ndim < 2
s, u, = svd(a)
tol = s.max * (rcond.nil? || rcond < 0 ? a.class::EPSILON * a.shape.max : rcond)
k = (s > tol).count
u[true, 0...k]
end | ruby | {
"resource": ""
} |
q20681 | Numo.Linalg.null_space | train | def null_space(a, rcond: -1)
raise NArray::ShapeError, '2-d array is required' if a.ndim < 2
s, _u, vh = svd(a)
tol = s.max * (rcond.nil? || rcond < 0 ? a.class::EPSILON * a.shape.max : rcond)
k = (s > tol).count
return a.class.new if k == vh.shape[0]
r = vh[k..-1, true].transpose.dup
blas_char(vh) =~ /c|z/ ? r.conj : r
end | ruby | {
"resource": ""
} |
q20682 | Numo.Linalg.lu | train | def lu(a, permute_l: false)
raise NArray::ShapeError, '2-d array is required' if a.ndim < 2
m, n = a.shape
k = [m, n].min
lu, ip = lu_fact(a)
l = lu.tril.tap { |mat| mat[mat.diag_indices(0)] = 1.0 }[true, 0...k]
u = lu.triu[0...k, 0...n]
p = Numo::DFloat.eye(m).tap do |mat|
ip.to_a.each_with_index { |i, j| mat[true, [i - 1, j]] = mat[true, [j, i - 1]].dup }
end
permute_l ? [p.dot(l), u] : [p, l, u]
end | ruby | {
"resource": ""
} |
q20683 | Numo.Linalg.lu_solve | train | def lu_solve(lu, ipiv, b, trans:"N")
Lapack.call(:getrs, lu, ipiv, b, trans:trans)[0]
end | ruby | {
"resource": ""
} |
q20684 | Numo.Linalg.eigvals | train | def eigvals(a)
jobvl, jobvr = 'N','N'
case blas_char(a)
when /c|z/
w, = Lapack.call(:geev, a, jobvl:jobvl, jobvr:jobvr)
else
wr, wi, = Lapack.call(:geev, a, jobvl:jobvl, jobvr:jobvr)
w = wr + wi * Complex::I
end
w
end | ruby | {
"resource": ""
} |
q20685 | Numo.Linalg.cond | train | def cond(a,ord=nil)
if ord.nil?
s = svdvals(a)
s[false, 0]/s[false, -1]
else
norm(a, ord, axis:[-2,-1]) * norm(inv(a), ord, axis:[-2,-1])
end
end | ruby | {
"resource": ""
} |
q20686 | Numo.Linalg.det | train | def det(a)
lu, piv, = Lapack.call(:getrf, a)
idx = piv.new_narray.store(piv.class.new(piv.shape[-1]).seq(1))
m = piv.eq(idx).count_false(axis:-1) % 2
sign = m * -2 + 1
lu.diagonal.prod(axis:-1) * sign
end | ruby | {
"resource": ""
} |
q20687 | Numo.Linalg.slogdet | train | def slogdet(a)
lu, piv, = Lapack.call(:getrf, a)
idx = piv.new_narray.store(piv.class.new(piv.shape[-1]).seq(1))
m = piv.eq(idx).count_false(axis:-1) % 2
sign = m * -2 + 1
lud = lu.diagonal
if (lud.eq 0).any?
return 0, (-Float::INFINITY)
end
lud_abs = lud.abs
sign *= (lud/lud_abs).prod
[sign, NMath.log(lud_abs).sum(axis:-1)]
end | ruby | {
"resource": ""
} |
q20688 | Numo.Linalg.inv | train | def inv(a, driver:"getrf", uplo:'U')
case driver
when /(ge|sy|he|po)sv$/
d = $1
b = a.new_zeros.eye
solve(a, b, driver:d, uplo:uplo)
when /(ge|sy|he)tr[fi]$/
d = $1
lu, piv = lu_fact(a)
lu_inv(lu, piv)
when /potr[fi]$/
lu = cho_fact(a, uplo:uplo)
cho_inv(lu, uplo:uplo)
else
raise ArgumentError, "invalid driver: #{driver}"
end
end | ruby | {
"resource": ""
} |
q20689 | AutoParse.Instance.valid? | train | def valid?
unvalidated_fields = @data.keys.dup
for property_key, schema_class in self.class.properties
property_value = @data[property_key]
if !self.class.validate_property_value(
property_value, schema_class.data)
return false
end
if property_value == nil && schema_class.data['required'] != true
# Value was omitted, but not required. Still valid. Skip dependency
# checks.
next
end
# Verify property dependencies
property_dependencies = self.class.property_dependencies[property_key]
case property_dependencies
when String, Array
property_dependencies = [property_dependencies].flatten
for dependency_key in property_dependencies
dependency_value = @data[dependency_key]
return false if dependency_value == nil
end
when Class
if property_dependencies.ancestors.include?(Instance)
dependency_instance = property_dependencies.new(property_value)
return false unless dependency_instance.valid?
else
raise TypeError,
"Expected schema Class, got #{property_dependencies.class}."
end
end
end
if self.class.additional_properties_schema == nil
# No additional properties allowed
return false unless unvalidated_fields.empty?
elsif self.class.additional_properties_schema != EMPTY_SCHEMA
# Validate all remaining fields against this schema
for property_key in unvalidated_fields
property_value = @data[property_key]
if !self.class.additional_properties_schema.validate_property_value(
property_value, self.class.additional_properties_schema.data)
return false
end
end
end
if self.class.superclass && self.class.superclass != Instance &&
self.class.ancestors.first != Instance
# The spec actually only defined the 'extends' semantics as children
# must also validate aainst the parent.
return false unless self.class.superclass.new(@data).valid?
end
return true
end | ruby | {
"resource": ""
} |
q20690 | Crummy.ViewMethods.render_crumbs | train | def render_crumbs(options = {})
raise ArgumentError, "Renderer and block given" if options.has_key?(:renderer) && block_given?
return yield(crumbs, options) if block_given?
@_renderer ||= if options.has_key?(:renderer)
options.delete(:renderer)
else
require 'crummy/standard_renderer'
Crummy::StandardRenderer.new
end
@_renderer.render_crumbs(crumbs, options)
end | ruby | {
"resource": ""
} |
q20691 | Erector.Convenience.javascript | train | def javascript(value = nil, attributes = {})
if value.is_a?(Hash)
attributes = value
value = nil
elsif block_given? && value
raise ArgumentError, "You can't pass both a block and a value to javascript -- please choose one."
end
script(attributes.merge(:type => "text/javascript")) do
# Shouldn't this be a "cdata" HtmlPart?
# (maybe, but the syntax is specific to javascript; it isn't
# really a generic XML CDATA section. Specifically,
# ]]> within value is not treated as ending the
# CDATA section by Firefox2 when parsing text/html,
# although I guess we could refuse to generate ]]>
# there, for the benefit of XML/XHTML parsers).
output << raw("\n// <![CDATA[\n")
if block_given?
yield
else
output << raw(value)
end
output << raw("\n// ]]>")
output.append_newline # this forces a newline even if we're not in pretty mode
end
output << raw("\n")
end | ruby | {
"resource": ""
} |
q20692 | FinanceMath.Loan.pmt | train | def pmt(options = {})
future_value = options.fetch(:future_value, 0)
type = options.fetch(:type, 0)
((@amount * interest(@monthly_rate, @duration) - future_value ) / ((1.0 + @monthly_rate * type) * fvifa(@monthly_rate, duration)))
end | ruby | {
"resource": ""
} |
q20693 | Erector.JQuery.jquery | train | def jquery(*args)
event = if args.first.is_a? Symbol
args.shift
else
:ready
end
txt = args.shift
attributes = args.shift || {}
javascript attributes do
rawtext "\n"
rawtext "jQuery(document).#{event}(function($){\n"
rawtext txt
rawtext "\n});"
end
end | ruby | {
"resource": ""
} |
q20694 | Erector.AbstractWidget.capture_content | train | def capture_content
original, @_output = output, Output.new
yield
original.widgets.concat(output.widgets) # todo: test!!!
output.to_s
ensure
@_output = original
end | ruby | {
"resource": ""
} |
q20695 | Erector.AbstractWidget._emit_via | train | def _emit_via(parent, options = {}, &block)
_emit(options.merge(:parent => parent,
:output => parent.output,
:helpers => parent.helpers), &block)
end | ruby | {
"resource": ""
} |
q20696 | Erector.Rails.render | train | def render(*args, &block)
captured = helpers.capture do
helpers.concat(helpers.render(*args, &block))
helpers.output_buffer.to_s
end
rawtext(captured)
end | ruby | {
"resource": ""
} |
q20697 | Erector.Rails.content_for | train | def content_for(*args,&block)
if block
helpers.content_for(*args,&block)
else
rawtext(helpers.content_for(*args))
''
end
end | ruby | {
"resource": ""
} |
q20698 | Erector.Text.character | train | def character(code_point_or_name)
if code_point_or_name.is_a?(Symbol)
require "erector/unicode"
found = Erector::CHARACTERS[code_point_or_name]
if found.nil?
raise "Unrecognized character #{code_point_or_name}"
end
raw("&#x#{sprintf '%x', found};")
elsif code_point_or_name.is_a?(Integer)
raw("&#x#{sprintf '%x', code_point_or_name};")
else
raise "Unrecognized argument to character: #{code_point_or_name}"
end
end | ruby | {
"resource": ""
} |
q20699 | Resourceful.Response.method_missing | train | def method_missing(name, &block)
@formats.push([name, block || proc {}]) unless @formats.any? {|n,b| n == name}
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.